From f8e6666a2c4fb66aad9da02b1ac850fdf405f506 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 17 Dec 2018 22:07:50 -0500 Subject: [PATCH] Add 'build' DSL method. Disallow processing Environments until configuration is performed. --- build_tests/cfile/Rsconscript | 8 ++-- build_tests/cfile/error_unknown_extension.rb | 6 ++- build_tests/clone_env/Rsconscript | 18 ++++---- build_tests/clone_env/clone_all.rb | 24 +++++----- .../check_c_header_no_fail_set_define.rb | 6 ++- .../check_c_header_success_set_define.rb | 6 ++- build_tests/configure/check_cfg.rb | 6 ++- build_tests/configure/check_cfg_package.rb | 6 ++- .../error_env_process_before_configure.rb | 4 ++ build_tests/configure/multiple_set_define.rb | 6 ++- build_tests/custom_builder/Rsconscript | 10 ++-- build_tests/custom_builder/build_after.rb | 20 ++++---- build_tests/custom_builder/cvar_expansion.rb | 14 +++--- build_tests/custom_builder/cvar_lambda.rb | 30 ++++++------ .../custom_builder/multiple_targets.rb | 10 ++-- build_tests/custom_builder/produces.rb | 24 +++++----- build_tests/d/Rsconscript | 6 ++- build_tests/header/Rsconscript | 6 ++- build_tests/json_to_yaml/Rsconscript | 24 +++++----- build_tests/library/Rsconscript | 8 ++-- build_tests/library/override_arcmd.rb | 8 ++-- build_tests/preprocess/Rsconscript | 6 ++- build_tests/shared_library/Rsconscript | 22 +++++---- .../shared_library/error_unknown_suffix.rb | 10 ++-- .../shared_library/shared_library_cxx.rb | 22 +++++---- .../shared_library/shared_library_d.rb | 18 ++++---- .../shared_library/shared_library_set_shld.rb | 24 +++++----- build_tests/simple/Rsconscript | 6 ++- build_tests/simple/absolute_source_path.rb | 24 +++++----- build_tests/simple/bc_produces.rb | 12 +++-- build_tests/simple/build_sources.rb | 22 +++++---- build_tests/simple/builder_no_sources.rb | 8 ++-- build_tests/simple/cache_command_change.rb | 8 ++-- build_tests/simple/cache_debugging.rb | 12 +++-- .../simple/cache_dep_checksum_change.rb | 6 ++- build_tests/simple/cache_new_dep1.rb | 12 +++-- build_tests/simple/cache_new_dep2.rb | 10 ++-- .../cache_successful_builds_when_one_fails.rb | 8 ++-- build_tests/simple/cache_user_dep.rb | 10 ++-- build_tests/simple/cache_varset.rb | 8 ++-- build_tests/simple/clear_targets.rb | 8 ++-- build_tests/simple/clone_n_threads.rb | 14 +++--- build_tests/simple/command.rb | 8 ++-- build_tests/simple/command_builder.rb | 14 +++--- build_tests/simple/command_redirect.rb | 16 ++++--- build_tests/simple/cvar_array.rb | 8 ++-- build_tests/simple/directory.rb | 6 ++- build_tests/simple/disassemble.rb | 8 ++-- build_tests/simple/dump.rb | 10 ++-- .../simple/error_circular_dependency.rb | 10 ++-- .../simple/error_circular_dependency2.rb | 6 ++- build_tests/simple/error_unknown_suffix.rb | 10 ++-- build_tests/simple/link_flag_change.rb | 10 ++-- build_tests/simple/override_cccmd.rb | 8 ++-- build_tests/simple/override_depfilesuffix.rb | 8 ++-- build_tests/simple/phony_target.rb | 18 ++++---- build_tests/simple/preprocess.rb | 8 ++-- build_tests/simple/progsuffix.rb | 8 ++-- build_tests/simple/progsuffix2.rb | 8 ++-- build_tests/simple/progsuffix3.rb | 6 ++- .../simple/register_target_in_build_hook.rb | 12 +++-- build_tests/simple/run_builder.rb | 10 ++-- build_tests/simple/standard_build.rb | 32 +++++++------ build_tests/simple/threading.rb | 16 ++++--- build_tests/simple/user_dep_build_order.rb | 12 +++-- build_tests/simple/user_dependencies.rb | 8 ++-- .../simple/wait_for_builds_on_failure.rb | 12 +++-- build_tests/simple_cc/Rsconscript | 6 ++- build_tests/simple_cc/cxxsuffix.rb | 10 ++-- build_tests/simple_cc/preprocess.rb | 8 ++-- build_tests/two_sources/Rsconscript | 8 ++-- build_tests/two_sources/assuffix.rb | 14 +++--- build_tests/two_sources/cache_strict_deps.rb | 14 +++--- build_tests/two_sources/libsuffix.rb | 12 +++-- build_tests/two_sources/objsuffix.rb | 12 +++-- .../backward_compatible_build_hooks.rb | 46 ++++++++++--------- build_tests/typical/build_hooks.rb | 18 ++++---- build_tests/typical/carat.rb | 14 +++--- build_tests/typical/copy.rb | 6 ++- build_tests/typical/csuffix.rb | 12 +++-- .../typical/echo_command_ruby_builder.rb | 10 ++-- build_tests/typical/echo_command_string.rb | 10 ++-- build_tests/typical/install.rb | 6 ++- build_tests/typical/install_directory.rb | 14 +++--- .../typical/multiple_targets_same_name.rb | 10 ++-- .../typical/post_build_hook_expansion.rb | 16 ++++--- lib/rscons/application.rb | 1 + lib/rscons/environment.rb | 13 +++++- lib/rscons/script.rb | 12 +++++ spec/build_tests_spec.rb | 7 +++ 90 files changed, 637 insertions(+), 434 deletions(-) create mode 100644 build_tests/configure/error_env_process_before_configure.rb diff --git a/build_tests/cfile/Rsconscript b/build_tests/cfile/Rsconscript index 41308ec..59be80f 100644 --- a/build_tests/cfile/Rsconscript +++ b/build_tests/cfile/Rsconscript @@ -1,4 +1,6 @@ -Rscons::Environment.new do |env| - env.CFile("lexer.c", "lexer.l") - env.CFile("parser.c", "parser.y") +build do + Rscons::Environment.new do |env| + env.CFile("lexer.c", "lexer.l") + env.CFile("parser.c", "parser.y") + end end diff --git a/build_tests/cfile/error_unknown_extension.rb b/build_tests/cfile/error_unknown_extension.rb index ad62f52..a4f93b3 100644 --- a/build_tests/cfile/error_unknown_extension.rb +++ b/build_tests/cfile/error_unknown_extension.rb @@ -1,3 +1,5 @@ -Rscons::Environment.new do |env| - env.CFile("file.c", "foo.bar") +build do + Rscons::Environment.new do |env| + env.CFile("file.c", "foo.bar") + end end diff --git a/build_tests/clone_env/Rsconscript b/build_tests/clone_env/Rsconscript index d8725cf..2dfcd39 100644 --- a/build_tests/clone_env/Rsconscript +++ b/build_tests/clone_env/Rsconscript @@ -1,10 +1,12 @@ -debug = Rscons::Environment.new(echo: :command) do |env| - env['CFLAGS'] = '-O2' - env['CPPFLAGS'] = '-DSTRING="Debug Version"' - env.Program('program-debug.exe', Dir['src/*.c']) -end +build do + debug = Rscons::Environment.new(echo: :command) do |env| + env['CFLAGS'] = '-O2' + env['CPPFLAGS'] = '-DSTRING="Debug Version"' + env.Program('program-debug.exe', Dir['src/*.c']) + end -release = debug.clone do |env| - env["CPPFLAGS"] = '-DSTRING="Release Version"' - env.Program('program-release.exe', Dir['src/*.c']) + release = debug.clone do |env| + env["CPPFLAGS"] = '-DSTRING="Release Version"' + env.Program('program-release.exe', Dir['src/*.c']) + end end diff --git a/build_tests/clone_env/clone_all.rb b/build_tests/clone_env/clone_all.rb index fbfdc01..596b759 100644 --- a/build_tests/clone_env/clone_all.rb +++ b/build_tests/clone_env/clone_all.rb @@ -1,14 +1,16 @@ -env1 = Rscons::Environment.new(echo: :command) do |env| - env['CFLAGS'] = '-O2' - env.add_build_hook do |build_op| - build_op[:vars]['CPPFLAGS'] = '-DSTRING="Hello"' +build do + env1 = Rscons::Environment.new(echo: :command) do |env| + env['CFLAGS'] = '-O2' + env.add_build_hook do |build_op| + build_op[:vars]['CPPFLAGS'] = '-DSTRING="Hello"' + end + env.add_post_build_hook do |build_op| + $stdout.puts "post #{build_op[:target]}" + end + env.Program('program.exe', Dir['src/*.c']) end - env.add_post_build_hook do |build_op| - $stdout.puts "post #{build_op[:target]}" - end - env.Program('program.exe', Dir['src/*.c']) -end -env2 = env1.clone do |env| - env.Program('program2.exe', Dir['src/*.c']) + env2 = env1.clone do |env| + env.Program('program2.exe', Dir['src/*.c']) + end end diff --git a/build_tests/configure/check_c_header_no_fail_set_define.rb b/build_tests/configure/check_c_header_no_fail_set_define.rb index f9031d0..f49d248 100644 --- a/build_tests/configure/check_c_header_no_fail_set_define.rb +++ b/build_tests/configure/check_c_header_no_fail_set_define.rb @@ -2,6 +2,8 @@ configure do check_c_header "not___found.h", fail: false, set_define: "HAVE_NOT___FOUND_H" end -Rscons::Environment.new(echo: :command) do |env| - env.Object("simple.o", "simple.c") +build do + Rscons::Environment.new(echo: :command) do |env| + env.Object("simple.o", "simple.c") + end end diff --git a/build_tests/configure/check_c_header_success_set_define.rb b/build_tests/configure/check_c_header_success_set_define.rb index a321fcb..f11cb38 100644 --- a/build_tests/configure/check_c_header_success_set_define.rb +++ b/build_tests/configure/check_c_header_success_set_define.rb @@ -2,6 +2,8 @@ configure do check_c_header "string.h", set_define: "HAVE_STRING_H" end -Rscons::Environment.new(echo: :command) do |env| - env.Object("simple.o", "simple.c") +build do + Rscons::Environment.new(echo: :command) do |env| + env.Object("simple.o", "simple.c") + end end diff --git a/build_tests/configure/check_cfg.rb b/build_tests/configure/check_cfg.rb index 29243d3..c122f42 100644 --- a/build_tests/configure/check_cfg.rb +++ b/build_tests/configure/check_cfg.rb @@ -2,6 +2,8 @@ configure do check_cfg program: "my-config" end -Rscons::Environment.new(echo: :command) do |env| - env.Program("myconfigtest", "simple.c") +build do + Rscons::Environment.new(echo: :command) do |env| + env.Program("myconfigtest", "simple.c") + end end diff --git a/build_tests/configure/check_cfg_package.rb b/build_tests/configure/check_cfg_package.rb index cab5ef5..59b69d6 100644 --- a/build_tests/configure/check_cfg_package.rb +++ b/build_tests/configure/check_cfg_package.rb @@ -2,6 +2,8 @@ configure do check_cfg package: "mypackage" end -Rscons::Environment.new(echo: :command) do |env| - env.Program("myconfigtest", "simple.c") +build do + Rscons::Environment.new(echo: :command) do |env| + env.Program("myconfigtest", "simple.c") + end end diff --git a/build_tests/configure/error_env_process_before_configure.rb b/build_tests/configure/error_env_process_before_configure.rb new file mode 100644 index 0000000..536aae1 --- /dev/null +++ b/build_tests/configure/error_env_process_before_configure.rb @@ -0,0 +1,4 @@ +Environment.new do |env| + env.Object("simple.o", "simple.cc") + env.process +end diff --git a/build_tests/configure/multiple_set_define.rb b/build_tests/configure/multiple_set_define.rb index 9a8008b..9decb3f 100644 --- a/build_tests/configure/multiple_set_define.rb +++ b/build_tests/configure/multiple_set_define.rb @@ -3,6 +3,8 @@ configure do check_c_header "stdio.h", set_define: "HAVE_STDIO_H" end -Rscons::Environment.new(echo: :command) do |env| - env.Object("simple.o", "simple.c") +build do + Rscons::Environment.new(echo: :command) do |env| + env.Object("simple.o", "simple.c") + end end diff --git a/build_tests/custom_builder/Rsconscript b/build_tests/custom_builder/Rsconscript index fb32ba1..87104f0 100644 --- a/build_tests/custom_builder/Rsconscript +++ b/build_tests/custom_builder/Rsconscript @@ -9,8 +9,10 @@ EOF end end -Rscons::Environment.new do |env| - env.add_builder(MySource.new) - env.MySource('inc.h', []) - env.Program('program.exe', Dir['*.c']) +build do + Rscons::Environment.new do |env| + env.add_builder(MySource.new) + env.MySource('inc.h', []) + env.Program('program.exe', Dir['*.c']) + end end diff --git a/build_tests/custom_builder/build_after.rb b/build_tests/custom_builder/build_after.rb index 7d4697b..715369a 100644 --- a/build_tests/custom_builder/build_after.rb +++ b/build_tests/custom_builder/build_after.rb @@ -1,10 +1,12 @@ -Rscons::Environment.new do |env| - env.Command("inc.c", - [], - "CMD" => %w[ruby gen.rb ${_TARGET}], - "CMD_DESC" => "Generating") - env["build_root"] = env.build_root - env["inc_c"] = "inc.c" - env.build_after("${build_root}/program.o", "${inc_c}") - env.Program("program.exe", ["program.c", "inc.c"]) +build do + Rscons::Environment.new do |env| + env.Command("inc.c", + [], + "CMD" => %w[ruby gen.rb ${_TARGET}], + "CMD_DESC" => "Generating") + env["build_root"] = env.build_root + env["inc_c"] = "inc.c" + env.build_after("${build_root}/program.o", "${inc_c}") + env.Program("program.exe", ["program.c", "inc.c"]) + end end diff --git a/build_tests/custom_builder/cvar_expansion.rb b/build_tests/custom_builder/cvar_expansion.rb index 37de6af..c16cda1 100644 --- a/build_tests/custom_builder/cvar_expansion.rb +++ b/build_tests/custom_builder/cvar_expansion.rb @@ -9,10 +9,12 @@ EOF end end -env = Rscons::Environment.new do |env| - env["hdr"] = "inc.h" - env["src"] = "program.c" - env.add_builder(MySource.new) - env.MySource('${hdr}') - env.Program('program.exe', "${src}") +build do + env = Rscons::Environment.new do |env| + env["hdr"] = "inc.h" + env["src"] = "program.c" + env.add_builder(MySource.new) + env.MySource('${hdr}') + env.Program('program.exe', "${src}") + end end diff --git a/build_tests/custom_builder/cvar_lambda.rb b/build_tests/custom_builder/cvar_lambda.rb index 4982b54..ea0a3b4 100644 --- a/build_tests/custom_builder/cvar_lambda.rb +++ b/build_tests/custom_builder/cvar_lambda.rb @@ -9,20 +9,22 @@ EOF end end -e1 = Rscons::Environment.new do |env| - env.add_builder(MySource.new) - env["one"] = "5" - env[:cfg] = {val: "9"} - env["two"] = lambda do |args| - args[:env][:cfg][:val] +build do + e1 = Rscons::Environment.new do |env| + env.add_builder(MySource.new) + env["one"] = "5" + env[:cfg] = {val: "9"} + env["two"] = lambda do |args| + args[:env][:cfg][:val] + end + env["the_value"] = lambda do |args| + "${one}${two}78" + end end - env["the_value"] = lambda do |args| - "${one}${two}78" - end -end -e1.clone do |env| - env[:cfg][:val] = "6" - env.MySource('inc.h', []) - env.Program('program.exe', Dir['*.c']) + e1.clone do |env| + env[:cfg][:val] = "6" + env.MySource('inc.h', []) + env.Program('program.exe', Dir['*.c']) + end end diff --git a/build_tests/custom_builder/multiple_targets.rb b/build_tests/custom_builder/multiple_targets.rb index 87708ff..d725154 100644 --- a/build_tests/custom_builder/multiple_targets.rb +++ b/build_tests/custom_builder/multiple_targets.rb @@ -12,8 +12,10 @@ class CHGen < Rscons::Builder end end -Rscons::Environment.new do |env| - env.add_builder(CHGen.new) - env.CHGen("inc.c", ["program.c"]) - env.Program("program.exe", %w[program.c inc.c]) +build do + Rscons::Environment.new do |env| + env.add_builder(CHGen.new) + env.CHGen("inc.c", ["program.c"]) + env.Program("program.exe", %w[program.c inc.c]) + end end diff --git a/build_tests/custom_builder/produces.rb b/build_tests/custom_builder/produces.rb index 079267b..d813e66 100644 --- a/build_tests/custom_builder/produces.rb +++ b/build_tests/custom_builder/produces.rb @@ -1,14 +1,16 @@ -Rscons::Environment.new do |env| - env["build_root"] = env.build_root - env["inc_h"] = "inc.h" +build do + Rscons::Environment.new do |env| + env["build_root"] = env.build_root + env["inc_h"] = "inc.h" - env.Copy("copy_inc.h", "${inc_h}") - env.depends("${build_root}/program.o", "${inc_h}") - env.Program("program.exe", ["program.c", "inc.c"]) + env.Copy("copy_inc.h", "${inc_h}") + env.depends("${build_root}/program.o", "${inc_h}") + env.Program("program.exe", ["program.c", "inc.c"]) - env.Command("inc.c", - [], - "CMD" => %w[ruby gen.rb ${_TARGET}], - "CMD_DESC" => "Generating") - env.produces("inc.c", "inc.h") + env.Command("inc.c", + [], + "CMD" => %w[ruby gen.rb ${_TARGET}], + "CMD_DESC" => "Generating") + env.produces("inc.c", "inc.h") + end end diff --git a/build_tests/d/Rsconscript b/build_tests/d/Rsconscript index 9e45872..a4a7cba 100644 --- a/build_tests/d/Rsconscript +++ b/build_tests/d/Rsconscript @@ -1,3 +1,5 @@ -Rscons::Environment.new(echo: :command) do |env| - env.Program("hello-d.exe", Rscons.glob("*.d")) +build do + Rscons::Environment.new(echo: :command) do |env| + env.Program("hello-d.exe", Rscons.glob("*.d")) + end end diff --git a/build_tests/header/Rsconscript b/build_tests/header/Rsconscript index 69b6d9c..46a95b6 100644 --- a/build_tests/header/Rsconscript +++ b/build_tests/header/Rsconscript @@ -1,3 +1,5 @@ -Rscons::Environment.new do |env| - env.Program('header.exe', Dir['*.c']) +build do + Rscons::Environment.new do |env| + env.Program('header.exe', Dir['*.c']) + end end diff --git a/build_tests/json_to_yaml/Rsconscript b/build_tests/json_to_yaml/Rsconscript index 1e70f16..33742df 100644 --- a/build_tests/json_to_yaml/Rsconscript +++ b/build_tests/json_to_yaml/Rsconscript @@ -1,15 +1,17 @@ -Rscons::Environment.new do |env| - require 'json' - require 'yaml' - env.add_builder(:JsonToYaml) do |target, sources, cache, env, vars| - unless cache.up_to_date?(target, :JsonToYaml, sources, env) - cache.mkdir_p(File.dirname(target)) - File.open(target, 'w') do |f| - f.write(YAML.dump(JSON.load(IO.read(sources.first)))) +build do + Rscons::Environment.new do |env| + require 'json' + require 'yaml' + env.add_builder(:JsonToYaml) do |target, sources, cache, env, vars| + unless cache.up_to_date?(target, :JsonToYaml, sources, env) + cache.mkdir_p(File.dirname(target)) + File.open(target, 'w') do |f| + f.write(YAML.dump(JSON.load(IO.read(sources.first)))) + end + cache.register_build(target, :JsonToYaml, sources, env) end - cache.register_build(target, :JsonToYaml, sources, env) + target end - target + env.JsonToYaml('foo.yml', 'foo.json') end - env.JsonToYaml('foo.yml', 'foo.json') end diff --git a/build_tests/library/Rsconscript b/build_tests/library/Rsconscript index ebc85ab..16ff03e 100644 --- a/build_tests/library/Rsconscript +++ b/build_tests/library/Rsconscript @@ -1,4 +1,6 @@ -Rscons::Environment.new(echo: :command) do |env| - env.Program('library.exe', ['lib.a', 'three.c']) - env.Library("lib.a", ['one.c', 'two.c'], 'CPPFLAGS' => ['-Dmake_lib']) +build do + Rscons::Environment.new(echo: :command) do |env| + env.Program('library.exe', ['lib.a', 'three.c']) + env.Library("lib.a", ['one.c', 'two.c'], 'CPPFLAGS' => ['-Dmake_lib']) + end end diff --git a/build_tests/library/override_arcmd.rb b/build_tests/library/override_arcmd.rb index 0fdd9f8..2a27206 100644 --- a/build_tests/library/override_arcmd.rb +++ b/build_tests/library/override_arcmd.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new(echo: :command) do |env| - env["ARCMD"] = %w[ar rcf ${_TARGET} ${_SOURCES}] - env.Library("lib.a", Rscons.glob("*.c")) +build do + Rscons::Environment.new(echo: :command) do |env| + env["ARCMD"] = %w[ar rcf ${_TARGET} ${_SOURCES}] + env.Library("lib.a", Rscons.glob("*.c")) + end end diff --git a/build_tests/preprocess/Rsconscript b/build_tests/preprocess/Rsconscript index 5a5e9e4..cd8a04a 100644 --- a/build_tests/preprocess/Rsconscript +++ b/build_tests/preprocess/Rsconscript @@ -1,3 +1,5 @@ -Rscons::Environment.new do |env| - env.Preprocess("pp", "foo.h") +build do + Rscons::Environment.new do |env| + env.Preprocess("pp", "foo.h") + end end diff --git a/build_tests/shared_library/Rsconscript b/build_tests/shared_library/Rsconscript index 19ca2bb..ef589f1 100644 --- a/build_tests/shared_library/Rsconscript +++ b/build_tests/shared_library/Rsconscript @@ -1,11 +1,13 @@ -Rscons::Environment.new do |env| - env["CPPPATH"] << "src/lib" - libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.c")) - env.Program("test-shared.exe", - Rscons.glob("src/*.c"), - "LIBPATH" => %w[.], - "LIBS" => %w[mine]) - env.build_after("test-shared.exe", libmine.to_s) - env.Program("test-static.exe", - Rscons.glob("src/**/*.c")) +build do + Rscons::Environment.new do |env| + env["CPPPATH"] << "src/lib" + libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.c")) + env.Program("test-shared.exe", + Rscons.glob("src/*.c"), + "LIBPATH" => %w[.], + "LIBS" => %w[mine]) + env.build_after("test-shared.exe", libmine.to_s) + env.Program("test-static.exe", + Rscons.glob("src/**/*.c")) + end end diff --git a/build_tests/shared_library/error_unknown_suffix.rb b/build_tests/shared_library/error_unknown_suffix.rb index e3e60bb..4573cf2 100644 --- a/build_tests/shared_library/error_unknown_suffix.rb +++ b/build_tests/shared_library/error_unknown_suffix.rb @@ -1,6 +1,8 @@ -Rscons::Environment.new do |env| - File.open("foo.xyz", "wb") do |fh| - fh.puts("hi") +build do + Rscons::Environment.new do |env| + File.open("foo.xyz", "wb") do |fh| + fh.puts("hi") + end + env.SharedObject("foo.o", "foo.xyz") end - env.SharedObject("foo.o", "foo.xyz") end diff --git a/build_tests/shared_library/shared_library_cxx.rb b/build_tests/shared_library/shared_library_cxx.rb index 12b4aa4..8bdc2bb 100644 --- a/build_tests/shared_library/shared_library_cxx.rb +++ b/build_tests/shared_library/shared_library_cxx.rb @@ -1,11 +1,13 @@ -Rscons::Environment.new do |env| - env["CPPPATH"] << "src/lib" - libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.cc")) - env.Program("test-shared.exe", - Rscons.glob("src/*.cc"), - "LIBPATH" => %w[.], - "LIBS" => %w[mine]) - env.build_after("test-shared.exe", libmine.to_s) - env.Program("test-static.exe", - Rscons.glob("src/**/*.cc")) +build do + Rscons::Environment.new do |env| + env["CPPPATH"] << "src/lib" + libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.cc")) + env.Program("test-shared.exe", + Rscons.glob("src/*.cc"), + "LIBPATH" => %w[.], + "LIBS" => %w[mine]) + env.build_after("test-shared.exe", libmine.to_s) + env.Program("test-static.exe", + Rscons.glob("src/**/*.cc")) + end end diff --git a/build_tests/shared_library/shared_library_d.rb b/build_tests/shared_library/shared_library_d.rb index e85fc7f..5cc839b 100644 --- a/build_tests/shared_library/shared_library_d.rb +++ b/build_tests/shared_library/shared_library_d.rb @@ -1,9 +1,11 @@ -Rscons::Environment.new do |env| - env["CPPPATH"] << "src/lib" - libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.d")) - env.Program("test-shared.exe", - Rscons.glob("src/*.c"), - "LIBPATH" => %w[.], - "LIBS" => %w[mine]) - env.build_after("test-shared.exe", libmine.to_s) +build do + Rscons::Environment.new do |env| + env["CPPPATH"] << "src/lib" + libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.d")) + env.Program("test-shared.exe", + Rscons.glob("src/*.c"), + "LIBPATH" => %w[.], + "LIBS" => %w[mine]) + env.build_after("test-shared.exe", libmine.to_s) + end end diff --git a/build_tests/shared_library/shared_library_set_shld.rb b/build_tests/shared_library/shared_library_set_shld.rb index 117ea7e..e87f7db 100644 --- a/build_tests/shared_library/shared_library_set_shld.rb +++ b/build_tests/shared_library/shared_library_set_shld.rb @@ -1,12 +1,14 @@ -Rscons::Environment.new do |env| - env["CPPPATH"] << "src/lib" - env["SHLD"] = "gcc" - libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.c")) - env.Program("test-shared.exe", - Rscons.glob("src/*.c"), - "LIBPATH" => %w[.], - "LIBS" => %w[mine]) - env.build_after("test-shared.exe", libmine.to_s) - env.Program("test-static.exe", - Rscons.glob("src/**/*.c")) +build do + Rscons::Environment.new do |env| + env["CPPPATH"] << "src/lib" + env["SHLD"] = "gcc" + libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.c")) + env.Program("test-shared.exe", + Rscons.glob("src/*.c"), + "LIBPATH" => %w[.], + "LIBS" => %w[mine]) + env.build_after("test-shared.exe", libmine.to_s) + env.Program("test-static.exe", + Rscons.glob("src/**/*.c")) + end end diff --git a/build_tests/simple/Rsconscript b/build_tests/simple/Rsconscript index 06b9b79..d4c09e4 100644 --- a/build_tests/simple/Rsconscript +++ b/build_tests/simple/Rsconscript @@ -1,3 +1,5 @@ -Rscons::Environment.new do |env| - env.Program('simple.exe', Dir['*.c']) +build do + Rscons::Environment.new do |env| + env.Program('simple.exe', Dir['*.c']) + end end diff --git a/build_tests/simple/absolute_source_path.rb b/build_tests/simple/absolute_source_path.rb index 7415b68..d1bd7c7 100644 --- a/build_tests/simple/absolute_source_path.rb +++ b/build_tests/simple/absolute_source_path.rb @@ -1,13 +1,15 @@ -Rscons::Environment.new do |env| - tempdir = ENV["TEMP"] || ENV["TMP"] || "/tmp" - source_file = File.join(tempdir, "abs.c") - File.open(source_file, "w") do |fh| - fh.puts(<<-EOF) - int main() - { - return 29; - } - EOF +build do + Rscons::Environment.new do |env| + tempdir = ENV["TEMP"] || ENV["TMP"] || "/tmp" + source_file = File.join(tempdir, "abs.c") + File.open(source_file, "w") do |fh| + fh.puts(<<-EOF) + int main() + { + return 29; + } + EOF + end + env.Program("abs.exe", source_file) end - env.Program("abs.exe", source_file) end diff --git a/build_tests/simple/bc_produces.rb b/build_tests/simple/bc_produces.rb index cd40d14..9c52fb6 100644 --- a/build_tests/simple/bc_produces.rb +++ b/build_tests/simple/bc_produces.rb @@ -12,10 +12,11 @@ class MyObject < Rscons::Builder end end -Rscons::Environment.new do |env| - env.add_builder(MyObject.new) - File.open("test.xyz", "w") do |fh| - fh.puts < int main(int argc, char * argv[]) { @@ -23,6 +24,7 @@ int main(int argc, char * argv[]) return 0; } EOF - env.Program("test", "test.xyz") + env.Program("test", "test.xyz") + end end end diff --git a/build_tests/simple/build_sources.rb b/build_tests/simple/build_sources.rb index ba19d82..32eac7c 100644 --- a/build_tests/simple/build_sources.rb +++ b/build_tests/simple/build_sources.rb @@ -8,15 +8,17 @@ class MyProgram < Rscons::Builder end end -Rscons::Environment.new do |env| - env.add_builder(MyProgram.new) - env.Object("simple.o", "simple.c") - File.open("two.c", "wb") do |fh| - fh.puts <<-EOF - void two(void) - { - } - EOF +build do + Rscons::Environment.new do |env| + env.add_builder(MyProgram.new) + env.Object("simple.o", "simple.c") + File.open("two.c", "wb") do |fh| + fh.puts <<-EOF + void two(void) + { + } + EOF + end + env.MyProgram("simple.exe", ["simple.o", "two.c"]) end - env.MyProgram("simple.exe", ["simple.o", "two.c"]) end diff --git a/build_tests/simple/builder_no_sources.rb b/build_tests/simple/builder_no_sources.rb index f95740d..4f3dd5f 100644 --- a/build_tests/simple/builder_no_sources.rb +++ b/build_tests/simple/builder_no_sources.rb @@ -3,7 +3,9 @@ class TestBuilder < Rscons::Builder target end end -Rscons::Environment.new do |env| - env.add_builder(TestBuilder.new) - env.TestBuilder("file") +build do + Rscons::Environment.new do |env| + env.add_builder(TestBuilder.new) + env.TestBuilder("file") + end end diff --git a/build_tests/simple/cache_command_change.rb b/build_tests/simple/cache_command_change.rb index ad6ec2d..b674e99 100644 --- a/build_tests/simple/cache_command_change.rb +++ b/build_tests/simple/cache_command_change.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new do |env| - env["LIBS"] += ["c"] - env.Program('simple.exe', Dir['*.c']) +build do + Rscons::Environment.new do |env| + env["LIBS"] += ["c"] + env.Program('simple.exe', Dir['*.c']) + end end diff --git a/build_tests/simple/cache_debugging.rb b/build_tests/simple/cache_debugging.rb index 67b7865..528e1d3 100644 --- a/build_tests/simple/cache_debugging.rb +++ b/build_tests/simple/cache_debugging.rb @@ -25,10 +25,12 @@ class DebugBuilder < Rscons::Builder end end -Rscons::Environment.new do |env| - env.add_builder(DebugBuilder.new) - if Rscons.vars["new_user_dep"] - env.depends("foo.o", "new_dep") +build do + Rscons::Environment.new do |env| + env.add_builder(DebugBuilder.new) + if Rscons.vars["new_user_dep"] + env.depends("foo.o", "new_dep") + end + env.DebugBuilder("foo.o", "simple.c") end - env.DebugBuilder("foo.o", "simple.c") end diff --git a/build_tests/simple/cache_dep_checksum_change.rb b/build_tests/simple/cache_dep_checksum_change.rb index dc12bd5..1f578f4 100644 --- a/build_tests/simple/cache_dep_checksum_change.rb +++ b/build_tests/simple/cache_dep_checksum_change.rb @@ -1,3 +1,5 @@ -Rscons::Environment.new do |env| - env.Copy("simple.copy", "simple.c") +build do + Rscons::Environment.new do |env| + env.Copy("simple.copy", "simple.c") + end end diff --git a/build_tests/simple/cache_new_dep1.rb b/build_tests/simple/cache_new_dep1.rb index 0a2307a..b2d83ac 100644 --- a/build_tests/simple/cache_new_dep1.rb +++ b/build_tests/simple/cache_new_dep1.rb @@ -1,6 +1,8 @@ -Rscons::Environment.new do |env| - env.Object("simple.o", "simple.c") - env.process - env["LDCMD"] = %w[gcc -o ${_TARGET} simple.o] - env.Program('simple.exe', []) +build do + Rscons::Environment.new do |env| + env.Object("simple.o", "simple.c") + env.process + env["LDCMD"] = %w[gcc -o ${_TARGET} simple.o] + env.Program('simple.exe', []) + end end diff --git a/build_tests/simple/cache_new_dep2.rb b/build_tests/simple/cache_new_dep2.rb index 2308920..bde61de 100644 --- a/build_tests/simple/cache_new_dep2.rb +++ b/build_tests/simple/cache_new_dep2.rb @@ -1,5 +1,7 @@ -Rscons::Environment.new do |env| - env.Object("simple.o", "simple.c") - env["LDCMD"] = %w[gcc -o ${_TARGET} simple.o] - env.Program('simple.exe', ["simple.o"]) +build do + Rscons::Environment.new do |env| + env.Object("simple.o", "simple.c") + env["LDCMD"] = %w[gcc -o ${_TARGET} simple.o] + env.Program('simple.exe', ["simple.o"]) + end end diff --git a/build_tests/simple/cache_successful_builds_when_one_fails.rb b/build_tests/simple/cache_successful_builds_when_one_fails.rb index d68520c..5fd28aa 100644 --- a/build_tests/simple/cache_successful_builds_when_one_fails.rb +++ b/build_tests/simple/cache_successful_builds_when_one_fails.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new do |env| - env.Object("simple.o", "simple.c") - env.Object("two.o", "two.c") +build do + Rscons::Environment.new do |env| + env.Object("simple.o", "simple.c") + env.Object("two.o", "two.c") + end end diff --git a/build_tests/simple/cache_user_dep.rb b/build_tests/simple/cache_user_dep.rb index 4a04718..10d4ddd 100644 --- a/build_tests/simple/cache_user_dep.rb +++ b/build_tests/simple/cache_user_dep.rb @@ -1,5 +1,7 @@ -Rscons::Environment.new do |env| - target = env.Program("simple.exe", "simple.c") - user_deps = File.read("user_deps", mode: "rb").split(" ") - target.depends(*user_deps) +build do + Rscons::Environment.new do |env| + target = env.Program("simple.exe", "simple.c") + user_deps = File.read("user_deps", mode: "rb").split(" ") + target.depends(*user_deps) + end end diff --git a/build_tests/simple/cache_varset.rb b/build_tests/simple/cache_varset.rb index 84589db..51af949 100644 --- a/build_tests/simple/cache_varset.rb +++ b/build_tests/simple/cache_varset.rb @@ -14,7 +14,9 @@ class TestBuilder < Rscons::Builder end end -Rscons::Environment.new do |env| - env.add_builder(TestBuilder.new) - env.TestBuilder("foo") +build do + Rscons::Environment.new do |env| + env.add_builder(TestBuilder.new) + env.TestBuilder("foo") + end end diff --git a/build_tests/simple/clear_targets.rb b/build_tests/simple/clear_targets.rb index c42ad92..39b2218 100644 --- a/build_tests/simple/clear_targets.rb +++ b/build_tests/simple/clear_targets.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new do |env| - env.Program("simple.exe", "simple.c") - env.clear_targets +build do + Rscons::Environment.new do |env| + env.Program("simple.exe", "simple.c") + env.clear_targets + end end diff --git a/build_tests/simple/clone_n_threads.rb b/build_tests/simple/clone_n_threads.rb index ec422cb..836dc55 100644 --- a/build_tests/simple/clone_n_threads.rb +++ b/build_tests/simple/clone_n_threads.rb @@ -1,7 +1,9 @@ -base_env = Rscons::Environment.new do |env| - env.n_threads = 165 +build do + base_env = Rscons::Environment.new do |env| + env.n_threads = 165 + end + + my_env = base_env.clone + + puts my_env.n_threads end - -my_env = base_env.clone - -puts my_env.n_threads diff --git a/build_tests/simple/command.rb b/build_tests/simple/command.rb index 7e80141..bab9526 100644 --- a/build_tests/simple/command.rb +++ b/build_tests/simple/command.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new(echo: :command) do |env| - env["LD"] = "gcc" - env.Program('simple.exe', Dir['*.c']) +build do + Rscons::Environment.new(echo: :command) do |env| + env["LD"] = "gcc" + env.Program('simple.exe', Dir['*.c']) + end end diff --git a/build_tests/simple/command_builder.rb b/build_tests/simple/command_builder.rb index 5b1c02d..9dfcb36 100644 --- a/build_tests/simple/command_builder.rb +++ b/build_tests/simple/command_builder.rb @@ -1,7 +1,9 @@ -Rscons::Environment.new do |env| - command = %W[gcc -o ${_TARGET} ${_SOURCES}] - env.Command("simple.exe", - "simple.c", - "CMD" => command, - "CMD_DESC" => "BuildIt") +build do + Rscons::Environment.new do |env| + command = %W[gcc -o ${_TARGET} ${_SOURCES}] + env.Command("simple.exe", + "simple.c", + "CMD" => command, + "CMD_DESC" => "BuildIt") + end end diff --git a/build_tests/simple/command_redirect.rb b/build_tests/simple/command_redirect.rb index 4a50093..6741a7b 100644 --- a/build_tests/simple/command_redirect.rb +++ b/build_tests/simple/command_redirect.rb @@ -1,8 +1,10 @@ -Rscons::Environment.new do |env| - env.Object("simple.o", "simple.c") - env.Command("simple.txt", - "simple.o", - "CMD" => %w[objdump --disassemble --source ${_SOURCES}], - "CMD_STDOUT" => "${_TARGET}", - "CMD_DESC" => "My Disassemble") +build do + Rscons::Environment.new do |env| + env.Object("simple.o", "simple.c") + env.Command("simple.txt", + "simple.o", + "CMD" => %w[objdump --disassemble --source ${_SOURCES}], + "CMD_STDOUT" => "${_TARGET}", + "CMD_DESC" => "My Disassemble") + end end diff --git a/build_tests/simple/cvar_array.rb b/build_tests/simple/cvar_array.rb index e7a4062..84a3df9 100644 --- a/build_tests/simple/cvar_array.rb +++ b/build_tests/simple/cvar_array.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new do |env| - env["sources"] = Rscons.glob("*.c") - env.Program("simple.exe", "${sources}") +build do + Rscons::Environment.new do |env| + env["sources"] = Rscons.glob("*.c") + env.Program("simple.exe", "${sources}") + end end diff --git a/build_tests/simple/directory.rb b/build_tests/simple/directory.rb index 9031c36..8208a5e 100644 --- a/build_tests/simple/directory.rb +++ b/build_tests/simple/directory.rb @@ -1,3 +1,5 @@ -Rscons::Environment.new do |env| - env.Directory("teh_dir") +build do + Rscons::Environment.new do |env| + env.Directory("teh_dir") + end end diff --git a/build_tests/simple/disassemble.rb b/build_tests/simple/disassemble.rb index 113e163..076cdb0 100644 --- a/build_tests/simple/disassemble.rb +++ b/build_tests/simple/disassemble.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new do |env| - env.Object("simple.o", "simple.c") - env.Disassemble("simple.txt", "simple.o") +build do + Rscons::Environment.new do |env| + env.Object("simple.o", "simple.c") + env.Disassemble("simple.txt", "simple.o") + end end diff --git a/build_tests/simple/dump.rb b/build_tests/simple/dump.rb index df80212..f17dab0 100644 --- a/build_tests/simple/dump.rb +++ b/build_tests/simple/dump.rb @@ -1,5 +1,7 @@ -env = Rscons::Environment.new do |env| - env["CFLAGS"] += %w[-O2 -fomit-frame-pointer] - env[:foo] = :bar +build do + env = Rscons::Environment.new do |env| + env["CFLAGS"] += %w[-O2 -fomit-frame-pointer] + env[:foo] = :bar + end + env.dump end -env.dump diff --git a/build_tests/simple/error_circular_dependency.rb b/build_tests/simple/error_circular_dependency.rb index 7cb9bc6..4f9bf74 100644 --- a/build_tests/simple/error_circular_dependency.rb +++ b/build_tests/simple/error_circular_dependency.rb @@ -1,5 +1,7 @@ -Rscons::Environment.new do |env| - env.Command("foo", "bar") - env.Command("bar", "baz") - env.Command("baz", "foo") +build do + Rscons::Environment.new do |env| + env.Command("foo", "bar") + env.Command("bar", "baz") + env.Command("baz", "foo") + end end diff --git a/build_tests/simple/error_circular_dependency2.rb b/build_tests/simple/error_circular_dependency2.rb index 6ac13c8..fd23016 100644 --- a/build_tests/simple/error_circular_dependency2.rb +++ b/build_tests/simple/error_circular_dependency2.rb @@ -1,3 +1,5 @@ -Rscons::Environment.new do |env| - env.Command("foo", "foo") +build do + Rscons::Environment.new do |env| + env.Command("foo", "foo") + end end diff --git a/build_tests/simple/error_unknown_suffix.rb b/build_tests/simple/error_unknown_suffix.rb index d8bfe75..774dfc8 100644 --- a/build_tests/simple/error_unknown_suffix.rb +++ b/build_tests/simple/error_unknown_suffix.rb @@ -1,6 +1,8 @@ -Rscons::Environment.new do |env| - File.open("foo.xyz", "wb") do |fh| - fh.puts("hi") +build do + Rscons::Environment.new do |env| + File.open("foo.xyz", "wb") do |fh| + fh.puts("hi") + end + env.Object("foo.o", "foo.xyz") end - env.Object("foo.o", "foo.xyz") end diff --git a/build_tests/simple/link_flag_change.rb b/build_tests/simple/link_flag_change.rb index 585f941..85d29bb 100644 --- a/build_tests/simple/link_flag_change.rb +++ b/build_tests/simple/link_flag_change.rb @@ -1,5 +1,7 @@ -Rscons::Environment.new(echo: :command) do |env| - env["LD"] = "gcc" - env["LIBPATH"] += ["libdir"] - env.Program('simple.exe', Dir['*.c']) +build do + Rscons::Environment.new(echo: :command) do |env| + env["LD"] = "gcc" + env["LIBPATH"] += ["libdir"] + env.Program('simple.exe', Dir['*.c']) + end end diff --git a/build_tests/simple/override_cccmd.rb b/build_tests/simple/override_cccmd.rb index 3b5a02e..d40db93 100644 --- a/build_tests/simple/override_cccmd.rb +++ b/build_tests/simple/override_cccmd.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new(echo: :command) do |env| - env.Object("simple.o", "simple.c", - "CCCMD" => %w[${CC} -c -o ${_TARGET} -Dfoobar ${_SOURCES}]) +build do + Rscons::Environment.new(echo: :command) do |env| + env.Object("simple.o", "simple.c", + "CCCMD" => %w[${CC} -c -o ${_TARGET} -Dfoobar ${_SOURCES}]) + end end diff --git a/build_tests/simple/override_depfilesuffix.rb b/build_tests/simple/override_depfilesuffix.rb index 1547a46..7fde120 100644 --- a/build_tests/simple/override_depfilesuffix.rb +++ b/build_tests/simple/override_depfilesuffix.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new(echo: :command) do |env| - env["DEPFILESUFFIX"] = ".deppy" - env.Object("simple.o", "simple.c") +build do + Rscons::Environment.new(echo: :command) do |env| + env["DEPFILESUFFIX"] = ".deppy" + env.Object("simple.o", "simple.c") + end end diff --git a/build_tests/simple/phony_target.rb b/build_tests/simple/phony_target.rb index 745fe89..2590d14 100644 --- a/build_tests/simple/phony_target.rb +++ b/build_tests/simple/phony_target.rb @@ -1,11 +1,13 @@ -Rscons::Environment.new do |env| - env.add_builder(:Checker) do |target, sources, cache, env, vars| - unless cache.up_to_date?(target, :Checker, sources, env) - puts "Checker #{sources.first}" if env.echo != :off - cache.register_build(target, :Checker, sources, env) +build do + Rscons::Environment.new do |env| + env.add_builder(:Checker) do |target, sources, cache, env, vars| + unless cache.up_to_date?(target, :Checker, sources, env) + puts "Checker #{sources.first}" if env.echo != :off + cache.register_build(target, :Checker, sources, env) + end + target end - target + env.Program("simple.exe", "simple.c") + env.Checker(:checker, "simple.exe") end - env.Program("simple.exe", "simple.c") - env.Checker(:checker, "simple.exe") end diff --git a/build_tests/simple/preprocess.rb b/build_tests/simple/preprocess.rb index 793206d..b249e09 100644 --- a/build_tests/simple/preprocess.rb +++ b/build_tests/simple/preprocess.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new do |env| - env.Preprocess("simplepp.c", "simple.c") - env.Program("simple.exe", "simplepp.c") +build do + Rscons::Environment.new do |env| + env.Preprocess("simplepp.c", "simple.c") + env.Program("simple.exe", "simplepp.c") + end end diff --git a/build_tests/simple/progsuffix.rb b/build_tests/simple/progsuffix.rb index 363efdf..7c4d802 100644 --- a/build_tests/simple/progsuffix.rb +++ b/build_tests/simple/progsuffix.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new do |env| - env["PROGSUFFIX"] = ".out" - env.Program("simple", Dir["*.c"]) +build do + Rscons::Environment.new do |env| + env["PROGSUFFIX"] = ".out" + env.Program("simple", Dir["*.c"]) + end end diff --git a/build_tests/simple/progsuffix2.rb b/build_tests/simple/progsuffix2.rb index 8f7ce00..6e33c16 100644 --- a/build_tests/simple/progsuffix2.rb +++ b/build_tests/simple/progsuffix2.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new do |env| - env["MYSUFFIX"] = ".out" - env.Program("simple${MYSUFFIX}", Dir["*.c"]) +build do + Rscons::Environment.new do |env| + env["MYSUFFIX"] = ".out" + env.Program("simple${MYSUFFIX}", Dir["*.c"]) + end end diff --git a/build_tests/simple/progsuffix3.rb b/build_tests/simple/progsuffix3.rb index 9552a3f..be99d8e 100644 --- a/build_tests/simple/progsuffix3.rb +++ b/build_tests/simple/progsuffix3.rb @@ -1,3 +1,5 @@ -Rscons::Environment.new do |env| - env.Program("simple", Dir["*.c"], "PROGSUFFIX" => ".xyz") +build do + Rscons::Environment.new do |env| + env.Program("simple", Dir["*.c"], "PROGSUFFIX" => ".xyz") + end end diff --git a/build_tests/simple/register_target_in_build_hook.rb b/build_tests/simple/register_target_in_build_hook.rb index 73d44db..d4bbc5c 100644 --- a/build_tests/simple/register_target_in_build_hook.rb +++ b/build_tests/simple/register_target_in_build_hook.rb @@ -1,8 +1,10 @@ -Rscons::Environment.new do |env| - env.Program("simple.exe", Dir["*.c"]) - env.add_build_hook do |build_op| - if build_op[:target].end_with?(".o") - env.Disassemble("#{build_op[:target]}.txt", build_op[:target]) +build do + Rscons::Environment.new do |env| + env.Program("simple.exe", Dir["*.c"]) + env.add_build_hook do |build_op| + if build_op[:target].end_with?(".o") + env.Disassemble("#{build_op[:target]}.txt", build_op[:target]) + end end end end diff --git a/build_tests/simple/run_builder.rb b/build_tests/simple/run_builder.rb index 83fc5f9..c31718e 100644 --- a/build_tests/simple/run_builder.rb +++ b/build_tests/simple/run_builder.rb @@ -5,8 +5,10 @@ class MyObject < Rscons::Builder end end -Rscons::Environment.new do |env| - env.add_builder(MyObject.new) - env.MyObject("simple.o", "simple.c") - env.Program("simple.exe", "simple.o") +build do + Rscons::Environment.new do |env| + env.add_builder(MyObject.new) + env.MyObject("simple.o", "simple.c") + env.Program("simple.exe", "simple.o") + end end diff --git a/build_tests/simple/standard_build.rb b/build_tests/simple/standard_build.rb index 9d8fa06..332a79b 100644 --- a/build_tests/simple/standard_build.rb +++ b/build_tests/simple/standard_build.rb @@ -1,17 +1,19 @@ -class MyCommand < Rscons::Builder - def run(target, sources, cache, env, vars) - vars = vars.merge({ - "_TARGET" => target, - "_SOURCES" => sources, - }) - command = env.build_command("${CMD}", vars) - cmd_desc = vars["CMD_DESC"] || "MyCommand" - standard_build("#{cmd_desc} #{target}", target, command, sources, env, cache) +build do + class MyCommand < Rscons::Builder + def run(target, sources, cache, env, vars) + vars = vars.merge({ + "_TARGET" => target, + "_SOURCES" => sources, + }) + command = env.build_command("${CMD}", vars) + cmd_desc = vars["CMD_DESC"] || "MyCommand" + standard_build("#{cmd_desc} #{target}", target, command, sources, env, cache) + end + end + + Rscons::Environment.new do |env| + env.add_builder(MyCommand.new) + command = %w[gcc -c -o ${_TARGET} ${_SOURCES}] + env.MyCommand("simple.o", "simple.c", "CMD" => command) end end - -Rscons::Environment.new do |env| - env.add_builder(MyCommand.new) - command = %w[gcc -c -o ${_TARGET} ${_SOURCES}] - env.MyCommand("simple.o", "simple.c", "CMD" => command) -end diff --git a/build_tests/simple/threading.rb b/build_tests/simple/threading.rb index fba5998..acc8606 100644 --- a/build_tests/simple/threading.rb +++ b/build_tests/simple/threading.rb @@ -18,11 +18,13 @@ class NonThreadedTestBuilder < Rscons::Builder end end -Rscons::Environment.new do |env| - env.add_builder(ThreadedTestBuilder.new) - env.add_builder(NonThreadedTestBuilder.new) - env.ThreadedTestBuilder("a") - env.ThreadedTestBuilder("b") - env.ThreadedTestBuilder("c") - env.NonThreadedTestBuilder("d") +build do + Rscons::Environment.new do |env| + env.add_builder(ThreadedTestBuilder.new) + env.add_builder(NonThreadedTestBuilder.new) + env.ThreadedTestBuilder("a") + env.ThreadedTestBuilder("b") + env.ThreadedTestBuilder("c") + env.NonThreadedTestBuilder("d") + end end diff --git a/build_tests/simple/user_dep_build_order.rb b/build_tests/simple/user_dep_build_order.rb index c6afd2b..2bc1941 100644 --- a/build_tests/simple/user_dep_build_order.rb +++ b/build_tests/simple/user_dep_build_order.rb @@ -14,9 +14,11 @@ class TestBuilder < Rscons::Builder end end -Rscons::Environment.new do |env| - env.add_builder(TestBuilder.new) - env.TestBuilder("one", [], "wait_time" => "3") - env.TestBuilder("two", [], "wait_time" => "0") - env.depends("two", "one") +build do + Rscons::Environment.new do |env| + env.add_builder(TestBuilder.new) + env.TestBuilder("one", [], "wait_time" => "3") + env.TestBuilder("two", [], "wait_time" => "0") + env.depends("two", "one") + end end diff --git a/build_tests/simple/user_dependencies.rb b/build_tests/simple/user_dependencies.rb index 910a694..ccec745 100644 --- a/build_tests/simple/user_dependencies.rb +++ b/build_tests/simple/user_dependencies.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new do |env| - program = env.Program("simple.exe", Dir["*.c"]) - env.depends(program, "program.ld") +build do + Rscons::Environment.new do |env| + program = env.Program("simple.exe", Dir["*.c"]) + env.depends(program, "program.ld") + end end diff --git a/build_tests/simple/wait_for_builds_on_failure.rb b/build_tests/simple/wait_for_builds_on_failure.rb index 550cf73..6acb773 100644 --- a/build_tests/simple/wait_for_builds_on_failure.rb +++ b/build_tests/simple/wait_for_builds_on_failure.rb @@ -11,10 +11,12 @@ class Fail < Rscons::Builder end end -Rscons::Environment.new do |env| - env.add_builder(Fail.new) - 4.times do |i| - wait_time = i + 1 - env.Fail("foo_#{wait_time}", [], "wait_time" => wait_time.to_s) +build do + Rscons::Environment.new do |env| + env.add_builder(Fail.new) + 4.times do |i| + wait_time = i + 1 + env.Fail("foo_#{wait_time}", [], "wait_time" => wait_time.to_s) + end end end diff --git a/build_tests/simple_cc/Rsconscript b/build_tests/simple_cc/Rsconscript index b3239ab..1400dfc 100644 --- a/build_tests/simple_cc/Rsconscript +++ b/build_tests/simple_cc/Rsconscript @@ -1,3 +1,5 @@ -Rscons::Environment.new do |env| - env.Program('simple.exe', Dir['*.cc']) +build do + Rscons::Environment.new do |env| + env.Program('simple.exe', Dir['*.cc']) + end end diff --git a/build_tests/simple_cc/cxxsuffix.rb b/build_tests/simple_cc/cxxsuffix.rb index eff56f6..a5f2dfc 100644 --- a/build_tests/simple_cc/cxxsuffix.rb +++ b/build_tests/simple_cc/cxxsuffix.rb @@ -1,5 +1,7 @@ -Rscons::Environment.new do |env| - env["CXXSUFFIX"] = %w[.cccc .cc] - env["CXXFLAGS"] += %w[-x c++] - env.Program("simple.exe", Dir["*.cc"] + Dir["*.cccc"]) +build do + Rscons::Environment.new do |env| + env["CXXSUFFIX"] = %w[.cccc .cc] + env["CXXFLAGS"] += %w[-x c++] + env.Program("simple.exe", Dir["*.cc"] + Dir["*.cccc"]) + end end diff --git a/build_tests/simple_cc/preprocess.rb b/build_tests/simple_cc/preprocess.rb index bef6a82..2963a06 100644 --- a/build_tests/simple_cc/preprocess.rb +++ b/build_tests/simple_cc/preprocess.rb @@ -1,4 +1,6 @@ -Rscons::Environment.new do |env| - env.Preprocess("simplepp.cc", "simple.cc") - env.Program("simple.exe", "simplepp.cc") +build do + Rscons::Environment.new do |env| + env.Preprocess("simplepp.cc", "simple.cc") + env.Program("simple.exe", "simplepp.cc") + end end diff --git a/build_tests/two_sources/Rsconscript b/build_tests/two_sources/Rsconscript index b30faa1..f1e2dd0 100644 --- a/build_tests/two_sources/Rsconscript +++ b/build_tests/two_sources/Rsconscript @@ -1,4 +1,6 @@ -Rscons::Environment.new(echo: :command) do |env| - env.Object("one.o", "one.c", 'CPPFLAGS' => ['-DONE']) - env.Program('two_sources.exe', ['one.o', 'two.c']) +build do + Rscons::Environment.new(echo: :command) do |env| + env.Object("one.o", "one.c", 'CPPFLAGS' => ['-DONE']) + env.Program('two_sources.exe', ['one.o', 'two.c']) + end end diff --git a/build_tests/two_sources/assuffix.rb b/build_tests/two_sources/assuffix.rb index a1f5597..7217ed8 100644 --- a/build_tests/two_sources/assuffix.rb +++ b/build_tests/two_sources/assuffix.rb @@ -1,7 +1,9 @@ -Rscons::Environment.new do |env| - env["ASSUFFIX"] = %w[.ssss .sss] - env["CFLAGS"] += %w[-S] - env.Object("one.ssss", "one.c", "CPPFLAGS" => ["-DONE"]) - env.Object("two.sss", "two.c") - env.Program("two_sources.exe", %w[one.ssss two.sss], "ASFLAGS" => env["ASFLAGS"] + %w[-x assembler]) +build do + Rscons::Environment.new do |env| + env["ASSUFFIX"] = %w[.ssss .sss] + env["CFLAGS"] += %w[-S] + env.Object("one.ssss", "one.c", "CPPFLAGS" => ["-DONE"]) + env.Object("two.sss", "two.c") + env.Program("two_sources.exe", %w[one.ssss two.sss], "ASFLAGS" => env["ASFLAGS"] + %w[-x assembler]) + end end diff --git a/build_tests/two_sources/cache_strict_deps.rb b/build_tests/two_sources/cache_strict_deps.rb index a20ad83..1553553 100644 --- a/build_tests/two_sources/cache_strict_deps.rb +++ b/build_tests/two_sources/cache_strict_deps.rb @@ -10,10 +10,12 @@ class StrictBuilder < Rscons::Builder end end -Rscons::Environment.new(echo: :command) do |env| - env.add_builder(StrictBuilder.new) - env.Object("one.o", "one.c", "CCFLAGS" => %w[-DONE]) - env.Object("two.o", "two.c") - sources = File.read("sources", mode: "rb").split(" ") - env.StrictBuilder("program.exe", sources) +build do + Rscons::Environment.new(echo: :command) do |env| + env.add_builder(StrictBuilder.new) + env.Object("one.o", "one.c", "CCFLAGS" => %w[-DONE]) + env.Object("two.o", "two.c") + sources = File.read("sources", mode: "rb").split(" ") + env.StrictBuilder("program.exe", sources) + end end diff --git a/build_tests/two_sources/libsuffix.rb b/build_tests/two_sources/libsuffix.rb index 58e0a9f..ced9d19 100644 --- a/build_tests/two_sources/libsuffix.rb +++ b/build_tests/two_sources/libsuffix.rb @@ -1,6 +1,8 @@ -Rscons::Environment.new() do |env| - env["LIBSUFFIX"] = %w[.aaaa .aaa] - env.Library("one.aaaa", "one.c", "CPPFLAGS" => ["-DONE"]) - env.Library("two.aaa", "two.c") - env.Program("two_sources.exe", %w[one.aaaa two.aaa]) +build do + Rscons::Environment.new() do |env| + env["LIBSUFFIX"] = %w[.aaaa .aaa] + env.Library("one.aaaa", "one.c", "CPPFLAGS" => ["-DONE"]) + env.Library("two.aaa", "two.c") + env.Program("two_sources.exe", %w[one.aaaa two.aaa]) + end end diff --git a/build_tests/two_sources/objsuffix.rb b/build_tests/two_sources/objsuffix.rb index 6be2f16..3cdfdef 100644 --- a/build_tests/two_sources/objsuffix.rb +++ b/build_tests/two_sources/objsuffix.rb @@ -1,6 +1,8 @@ -Rscons::Environment.new do |env| - env["OBJSUFFIX"] = %w[.oooo .ooo] - env.Object("one.oooo", "one.c", "CPPFLAGS" => ["-DONE"]) - env.Object("two.ooo", "two.c") - env.Program("two_sources.exe", %w[one.oooo two.ooo]) +build do + Rscons::Environment.new do |env| + env["OBJSUFFIX"] = %w[.oooo .ooo] + env.Object("one.oooo", "one.c", "CPPFLAGS" => ["-DONE"]) + env.Object("two.ooo", "two.c") + env.Program("two_sources.exe", %w[one.oooo two.ooo]) + end end diff --git a/build_tests/typical/backward_compatible_build_hooks.rb b/build_tests/typical/backward_compatible_build_hooks.rb index a5e2150..268fe57 100644 --- a/build_tests/typical/backward_compatible_build_hooks.rb +++ b/build_tests/typical/backward_compatible_build_hooks.rb @@ -1,22 +1,24 @@ -class MyObject < Rscons::Builder - def run(target, sources, cache, env, vars) - env.run_builder(env.builders["Object"], target, sources, cache, vars) - end -end - -Rscons::Environment.new(echo: :command) do |env| - env.add_builder(MyObject.new) - env.append('CPPPATH' => Rscons.glob('src/**')) - env.add_build_hook do |build_op| - if build_op[:builder].name == "MyObject" && build_op[:sources].first =~ %r{one\.c} - build_op[:vars]["CFLAGS"] << "-O1" - build_op[:sources] = ['src/two/two.c'] - elsif build_op[:builder].name == "MyObject" && build_op[:target] =~ %r{two\.o} - new_vars = build_op[:vars].clone - new_vars["CFLAGS"] << "-O2" - build_op[:vars] = new_vars - end - end - env.MyObject('one.o', 'src/one/one.c') - env.MyObject('two.o', 'src/two/two.c') -end +class MyObject < Rscons::Builder + def run(target, sources, cache, env, vars) + env.run_builder(env.builders["Object"], target, sources, cache, vars) + end +end + +build do + Rscons::Environment.new(echo: :command) do |env| + env.add_builder(MyObject.new) + env.append('CPPPATH' => Rscons.glob('src/**')) + env.add_build_hook do |build_op| + if build_op[:builder].name == "MyObject" && build_op[:sources].first =~ %r{one\.c} + build_op[:vars]["CFLAGS"] << "-O1" + build_op[:sources] = ['src/two/two.c'] + elsif build_op[:builder].name == "MyObject" && build_op[:target] =~ %r{two\.o} + new_vars = build_op[:vars].clone + new_vars["CFLAGS"] << "-O2" + build_op[:vars] = new_vars + end + end + env.MyObject('one.o', 'src/one/one.c') + env.MyObject('two.o', 'src/two/two.c') + end +end diff --git a/build_tests/typical/build_hooks.rb b/build_tests/typical/build_hooks.rb index 32c6b95..1bc1e3b 100644 --- a/build_tests/typical/build_hooks.rb +++ b/build_tests/typical/build_hooks.rb @@ -1,11 +1,13 @@ -Rscons::Environment.new(echo: :command) do |env| - env.append('CPPPATH' => Rscons.glob('src/**/*/')) - env.add_build_hook do |build_op| - if File.basename(build_op[:target]) == "one.o" - build_op[:vars]["CFLAGS"] << "-O1" - elsif File.basename(build_op[:target]) == "two.o" - build_op[:vars]["CFLAGS"] << "-O2" +build do + Rscons::Environment.new(echo: :command) do |env| + env.append('CPPPATH' => Rscons.glob('src/**/*/')) + env.add_build_hook do |build_op| + if File.basename(build_op[:target]) == "one.o" + build_op[:vars]["CFLAGS"] << "-O1" + elsif File.basename(build_op[:target]) == "two.o" + build_op[:vars]["CFLAGS"] << "-O2" + end end + env.Program('build_hook.exe', Rscons.glob('src/**/*.c')) end - env.Program('build_hook.exe', Rscons.glob('src/**/*.c')) end diff --git a/build_tests/typical/carat.rb b/build_tests/typical/carat.rb index c8d5179..f36d8d0 100644 --- a/build_tests/typical/carat.rb +++ b/build_tests/typical/carat.rb @@ -1,7 +1,9 @@ -Rscons::Environment.new(echo: :command) do |env| - env.append('CPPPATH' => Rscons.glob('src/**').sort) - FileUtils.mkdir_p(env.build_root) - FileUtils.mv("src/one/one.c", env.build_root) - env.Object("^/one.o", "^/one.c") - env.Program("program.exe", Rscons.glob('src/**/*.c') + ["^/one.o"]) +build do + Rscons::Environment.new(echo: :command) do |env| + env.append('CPPPATH' => Rscons.glob('src/**').sort) + FileUtils.mkdir_p(env.build_root) + FileUtils.mv("src/one/one.c", env.build_root) + env.Object("^/one.o", "^/one.c") + env.Program("program.exe", Rscons.glob('src/**/*.c') + ["^/one.o"]) + end end diff --git a/build_tests/typical/copy.rb b/build_tests/typical/copy.rb index fce7294..675d689 100644 --- a/build_tests/typical/copy.rb +++ b/build_tests/typical/copy.rb @@ -1,3 +1,5 @@ -Rscons::Environment.new do |env| - env.Copy("inst.exe", "copy.rb") +build do + Rscons::Environment.new do |env| + env.Copy("inst.exe", "copy.rb") + end end diff --git a/build_tests/typical/csuffix.rb b/build_tests/typical/csuffix.rb index 4d8e89f..d55a468 100644 --- a/build_tests/typical/csuffix.rb +++ b/build_tests/typical/csuffix.rb @@ -1,6 +1,8 @@ -Rscons::Environment.new do |env| - env["CSUFFIX"] = %w[.yargh .c] - env["CFLAGS"] += %w[-x c] - env["CPPPATH"] += Rscons.glob("src/**") - env.Program("program.exe", Rscons.glob("src/**/*.{c,yargh}")) +build do + Rscons::Environment.new do |env| + env["CSUFFIX"] = %w[.yargh .c] + env["CFLAGS"] += %w[-x c] + env["CPPPATH"] += Rscons.glob("src/**") + env.Program("program.exe", Rscons.glob("src/**/*.{c,yargh}")) + end end diff --git a/build_tests/typical/echo_command_ruby_builder.rb b/build_tests/typical/echo_command_ruby_builder.rb index 60309e3..5e7097a 100644 --- a/build_tests/typical/echo_command_ruby_builder.rb +++ b/build_tests/typical/echo_command_ruby_builder.rb @@ -1,5 +1,7 @@ -Rscons::Environment.new do |env| - env.echo = :command - env.Install("inst.exe", "install.rb") -end +build do + Rscons::Environment.new do |env| + env.echo = :command + env.Install("inst.exe", "install.rb") + end +end diff --git a/build_tests/typical/echo_command_string.rb b/build_tests/typical/echo_command_string.rb index 95c8523..08d2bcb 100644 --- a/build_tests/typical/echo_command_string.rb +++ b/build_tests/typical/echo_command_string.rb @@ -6,8 +6,10 @@ class MyBuilder < Rscons::Builder end end -Rscons::Environment.new do |env| - env.echo = :command - env.add_builder(MyBuilder.new) - env.MyBuilder("foo") +build do + Rscons::Environment.new do |env| + env.echo = :command + env.add_builder(MyBuilder.new) + env.MyBuilder("foo") + end end diff --git a/build_tests/typical/install.rb b/build_tests/typical/install.rb index 1e39ca8..d92061b 100644 --- a/build_tests/typical/install.rb +++ b/build_tests/typical/install.rb @@ -1,3 +1,5 @@ -Rscons::Environment.new do |env| - env.Install("inst.exe", "install.rb") +build do + Rscons::Environment.new do |env| + env.Install("inst.exe", "install.rb") + end end diff --git a/build_tests/typical/install_directory.rb b/build_tests/typical/install_directory.rb index 2381af7..7879cac 100644 --- a/build_tests/typical/install_directory.rb +++ b/build_tests/typical/install_directory.rb @@ -1,9 +1,11 @@ -Rscons::Environment.new do |env| - env.Directory("inst") - env.Install("inst", "install_directory.rb") +build do + Rscons::Environment.new do |env| + env.Directory("inst") + env.Install("inst", "install_directory.rb") - env.Install("noexist/src", "src") + env.Install("noexist/src", "src") - env.Directory("exist/src") - env.Install("exist/src", "src") + env.Directory("exist/src") + env.Install("exist/src", "src") + end end diff --git a/build_tests/typical/multiple_targets_same_name.rb b/build_tests/typical/multiple_targets_same_name.rb index e74bbc9..4ebc864 100644 --- a/build_tests/typical/multiple_targets_same_name.rb +++ b/build_tests/typical/multiple_targets_same_name.rb @@ -1,5 +1,7 @@ -Rscons::Environment.new do |env| - env["CPPPATH"] << "src/two" - env.Object("one.o", "src/one/one.c") - env.Object("one.o", "src/two/two.c") +build do + Rscons::Environment.new do |env| + env["CPPPATH"] << "src/two" + env.Object("one.o", "src/one/one.c") + env.Object("one.o", "src/two/two.c") + end end diff --git a/build_tests/typical/post_build_hook_expansion.rb b/build_tests/typical/post_build_hook_expansion.rb index 26b7a33..9dc88cc 100644 --- a/build_tests/typical/post_build_hook_expansion.rb +++ b/build_tests/typical/post_build_hook_expansion.rb @@ -1,10 +1,12 @@ -Rscons::Environment.new do |env| - env["CPPPATH"] << "src/two" - env.Object("one.o", "src/one/one.c") - env.add_post_build_hook do |build_op| - if build_op[:target] == "one.o" - env["MODULE"] = "two" - env.Object("${MODULE}.o", "src/${MODULE}/${MODULE}.c") +build do + Rscons::Environment.new do |env| + env["CPPPATH"] << "src/two" + env.Object("one.o", "src/one/one.c") + env.add_post_build_hook do |build_op| + if build_op[:target] == "one.o" + env["MODULE"] = "two" + env.Object("${MODULE}.o", "src/${MODULE}/${MODULE}.c") + end end end end diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index d032769..41f574a 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -68,6 +68,7 @@ module Rscons # Exit code. def build(options) begin + @script.build Environment.environments.each do |env| env.process end diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 604d4c4..7a56689 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -15,6 +15,11 @@ module Rscons # All Environments. attr_reader :environments + # Initialize class instance variables. + def class_init + @environments = [] + end + # Get an ID for a new Environment. This is a monotonically increasing # integer. # @@ -77,8 +82,7 @@ module Rscons end end @echo = options[:echo] || :short - # TODO: remove the || "build" below when autoconf is turned on for build test specs - @build_root = "#{Cache.instance.configuration_data["build_dir"] || "build"}/e.#{@id}" + @build_root = "#{Cache.instance.configuration_data["build_dir"]}/e.#{@id}" load_configuration_data! if block_given? @@ -273,6 +277,9 @@ module Rscons # @return [void] def process cache = Cache.instance + unless cache.configuration_data["configured"] + raise "Project must be configured before processing an Environment" + end failure = nil begin while @job_set.size > 0 or @threaded_commands.size > 0 @@ -1083,4 +1090,6 @@ module Rscons end end + + Environment.class_init end diff --git a/lib/rscons/script.rb b/lib/rscons/script.rb index 1c0cc03..09358d2 100644 --- a/lib/rscons/script.rb +++ b/lib/rscons/script.rb @@ -19,6 +19,11 @@ module Rscons @script.autoconf = autoconf end + # Enter build block. + def build(&block) + @script.operations["build"] = block + end + # Enter configuration block. def configure(&block) @script.operations["configure"] = block @@ -81,6 +86,13 @@ module Rscons Dsl.new(self).instance_eval(script_contents, path, 1) end + # Perform build operation. + def build + if build_proc = @operations["build"] + build_proc.call + end + end + # Perform configure operation. def configure(configure_op) if operation_lambda = @operations["configure"] diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 4b24f48..2775473 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1886,6 +1886,13 @@ EOF expect(result.stdout).to match /Checking for C compiler\.\.\. not found/ expect(result.status).to_not eq 0 end + + it "exits with an error if configuration has not been performed before attempting to process an environment" do + test_dir "configure" + result = run_rscons(rsconscript: "error_env_process_before_configure.rb") + expect(result.stderr).to match /Project must be configured before processing an Environment/ + expect(result.status).to_not eq 0 + end end end