From ef7e9259cb23c88dff4c4f5b7beacf1de0050a91 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 12 Feb 2022 21:59:52 -0500 Subject: [PATCH] Add shortcut method for creating environments - close #149 Add env() method to create environments. Process all environments created at build script top level before executing any autoconf-enabled tasks, or if no tasks are specified by the user. --- build_tests/cfile/Rsconscript | 8 +- build_tests/cfile/error_unknown_extension.rb | 6 +- build_tests/clone_env/Rsconscript | 20 ++-- build_tests/clone_env/clone_all.rb | 24 ++-- build_tests/configure/autoconf_false.rb | 2 +- build_tests/configure/autoconf_rebuild.rb | 6 +- .../configure/check_c_header_cpppath.rb | 6 +- .../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 +- build_tests/configure/check_cfg_use.rb | 18 ++- .../configure/check_cxx_header_cpppath.rb | 6 +- .../configure/check_d_import_d_import_path.rb | 6 +- build_tests/configure/check_lib_libpath1.rb | 6 +- build_tests/configure/check_lib_libpath2.rb | 6 +- build_tests/configure/check_lib_success.rb | 6 +- build_tests/configure/check_lib_use.rb | 18 ++- build_tests/configure/check_lib_use_false.rb | 8 +- build_tests/configure/custom_config_check.rb | 6 +- build_tests/configure/multiple_set_define.rb | 6 +- build_tests/custom_builder/Rsconscript | 10 +- build_tests/custom_builder/build_after.rb | 22 ++-- build_tests/custom_builder/cvar_expansion.rb | 14 +-- build_tests/custom_builder/cvar_lambda.rb | 30 +++-- .../custom_builder/error_run_return_value.rb | 10 +- build_tests/custom_builder/error_wait_for.rb | 10 +- .../custom_builder/multiple_targets.rb | 10 +- build_tests/custom_builder/produces.rb | 26 ++--- build_tests/custom_builder/produces_env.rb | 26 ++--- build_tests/custom_builder/wait_for_thread.rb | 8 +- build_tests/d/Rsconscript | 6 +- build_tests/d/build-ldc2.rb | 6 +- build_tests/d/link_objects.rb | 10 +- build_tests/direct/c_program.rb | 6 +- build_tests/direct/c_shared_library.rb | 10 +- build_tests/header/Rsconscript | 6 +- build_tests/json_to_yaml/Rsconscript | 26 ++--- build_tests/library/Rsconscript | 8 +- build_tests/library/library_from_object.rb | 10 +- build_tests/library/override_arcmd.rb | 8 +- build_tests/multiple_basename/Rsconscript | 6 +- build_tests/preprocess/Rsconscript | 6 +- build_tests/shared_library/Rsconscript | 22 ++-- .../shared_library/error_unknown_suffix.rb | 10 +- .../shared_library/shared_library_as.rb | 10 +- .../shared_library/shared_library_cxx.rb | 22 ++-- .../shared_library/shared_library_d.rb | 18 ++- .../shared_library_from_object.rb | 10 +- .../shared_library/shared_library_set_shld.rb | 24 ++-- build_tests/simple/Rsconscript | 6 +- build_tests/simple/absolute_source_path.rb | 24 ++-- build_tests/simple/barrier.rb | 20 ++-- build_tests/simple/builder_as_source.rb | 8 +- build_tests/simple/builder_no_sources.rb | 9 +- .../simple/builder_wait_for_builder.rb | 10 +- 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/distclean.rb | 6 +- build_tests/simple/dump.rb | 2 +- .../simple/error_circular_dependency.rb | 10 +- .../simple/error_circular_dependency2.rb | 6 +- .../error_produces_nonexistent_target.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/pathing.rb | 10 +- 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/size.rb | 8 +- build_tests/simple/threading.rb | 16 ++- build_tests/simple/user_dep_build_order.rb | 12 +- build_tests/simple/user_dependencies.rb | 8 +- build_tests/simple/user_dependencies_carat.rb | 13 +-- .../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/link_objects.rb | 8 +- build_tests/simple_cc/preprocess.rb | 8 +- build_tests/tasks/tasks.rb | 2 +- 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 +- build_tests/typical/Rsconscript | 8 +- build_tests/typical/build_hooks.rb | 18 ++- .../typical/build_hooks_override_vars.rb | 26 ++--- build_tests/typical/carat.rb | 16 ++- build_tests/typical/clone_and_name.rb | 14 +-- build_tests/typical/clone_with_lookup.rb | 7 ++ build_tests/typical/copy.rb | 6 +- build_tests/typical/copy_directory.rb | 14 +-- build_tests/typical/copy_multiple.rb | 6 +- build_tests/typical/csuffix.rb | 12 +- .../typical/echo_command_ruby_builder.rb | 9 +- build_tests/typical/echo_command_string.rb | 10 +- build_tests/typical/error_env_nontask.rb | 1 + build_tests/typical/error_env_option.rb | 1 + build_tests/typical/install.rb | 6 +- build_tests/typical/multiple_environments.rb | 20 ++-- .../typical/multiple_targets_same_name.rb | 10 +- .../typical/post_build_hook_expansion.rb | 16 ++- lib/rscons/application.rb | 69 +++++++++++- lib/rscons/cli.rb | 103 ++++++------------ lib/rscons/environment.rb | 76 ++++++++----- lib/rscons/script.rb | 14 +-- lib/rscons/task.rb | 23 ++-- lib/rscons/util.rb | 10 ++ spec/build_tests_spec.rb | 44 +++++--- 129 files changed, 742 insertions(+), 901 deletions(-) create mode 100644 build_tests/typical/clone_with_lookup.rb create mode 100644 build_tests/typical/error_env_nontask.rb create mode 100644 build_tests/typical/error_env_option.rb diff --git a/build_tests/cfile/Rsconscript b/build_tests/cfile/Rsconscript index 96818d0..8ade2c1 100644 --- a/build_tests/cfile/Rsconscript +++ b/build_tests/cfile/Rsconscript @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - env.CFile("lexer.c", "lexer.l") - env.CFile("parser.c", "parser.y") - end +env do |env| + env.CFile("lexer.c", "lexer.l") + env.CFile("parser.c", "parser.y") end diff --git a/build_tests/cfile/error_unknown_extension.rb b/build_tests/cfile/error_unknown_extension.rb index af5b2b1..cea81f6 100644 --- a/build_tests/cfile/error_unknown_extension.rb +++ b/build_tests/cfile/error_unknown_extension.rb @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.CFile("file.c", "foo.bar") - end +env do |env| + env.CFile("file.c", "foo.bar") end diff --git a/build_tests/clone_env/Rsconscript b/build_tests/clone_env/Rsconscript index fe88c89..f9dd58a 100644 --- a/build_tests/clone_env/Rsconscript +++ b/build_tests/clone_env/Rsconscript @@ -1,12 +1,10 @@ -default do - debug = 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']) - end +debug = env(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']) end diff --git a/build_tests/clone_env/clone_all.rb b/build_tests/clone_env/clone_all.rb index 08eebd1..09e8951 100644 --- a/build_tests/clone_env/clone_all.rb +++ b/build_tests/clone_env/clone_all.rb @@ -1,16 +1,14 @@ -default do - env1 = Environment.new(echo: :command) do |env| - env['CFLAGS'] = '-O2' - env.add_build_hook do |builder| - builder.vars['CPPFLAGS'] = '-DSTRING="Hello"' - end - env.add_post_build_hook do |builder| - $stdout.puts "post #{builder.target}" - end - env.Program('program.exe', Dir['src/*.c']) +env1 = env(echo: :command) do |env| + env['CFLAGS'] = '-O2' + env.add_build_hook do |builder| + builder.vars['CPPFLAGS'] = '-DSTRING="Hello"' end - - env2 = env1.clone do |env| - env.Program('program2.exe', Dir['src/*.c']) + env.add_post_build_hook do |builder| + $stdout.puts "post #{builder.target}" end + env.Program('program.exe', Dir['src/*.c']) +end + +env2 = env1.clone do |env| + env.Program('program2.exe', Dir['src/*.c']) end diff --git a/build_tests/configure/autoconf_false.rb b/build_tests/configure/autoconf_false.rb index 6c81396..a12fd40 100644 --- a/build_tests/configure/autoconf_false.rb +++ b/build_tests/configure/autoconf_false.rb @@ -1,3 +1,3 @@ autoconf false -Environment.new do |env| +env do |env| end diff --git a/build_tests/configure/autoconf_rebuild.rb b/build_tests/configure/autoconf_rebuild.rb index 38731d9..a0fffa8 100644 --- a/build_tests/configure/autoconf_rebuild.rb +++ b/build_tests/configure/autoconf_rebuild.rb @@ -3,8 +3,6 @@ configure do check_c_header "stdio.h" end -default do - Environment.new do |env| - env.Program("simple.exe", "simple.c") - end +env do |env| + env.Program("simple.exe", "simple.c") end diff --git a/build_tests/configure/check_c_header_cpppath.rb b/build_tests/configure/check_c_header_cpppath.rb index 6e6cf72..96c52c3 100644 --- a/build_tests/configure/check_c_header_cpppath.rb +++ b/build_tests/configure/check_c_header_cpppath.rb @@ -3,8 +3,6 @@ configure do check_c_header "frobulous.h", check_cpppath: ["./usr2"] end -default do - Environment.new do |env| - env.Object("test.o", "test.c") - end +env do |env| + env.Object("test.o", "test.c") 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 16a5f61..3d44c24 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,8 +2,6 @@ configure do check_c_header "not___found.h", set_define: "HAVE_NOT___FOUND_H" end -default do - Environment.new(echo: :command) do |env| - env.Object("simple.o", "simple.c") - end +env(echo: :command) do |env| + env.Object("simple.o", "simple.c") 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 59a4b8c..d10ca78 100644 --- a/build_tests/configure/check_c_header_success_set_define.rb +++ b/build_tests/configure/check_c_header_success_set_define.rb @@ -2,8 +2,6 @@ configure do check_c_header "string.h", set_define: "HAVE_STRING_H" end -default do - Environment.new(echo: :command) do |env| - env.Object("simple.o", "simple.c") - end +env(echo: :command) do |env| + env.Object("simple.o", "simple.c") end diff --git a/build_tests/configure/check_cfg.rb b/build_tests/configure/check_cfg.rb index fcf40e4..147e411 100644 --- a/build_tests/configure/check_cfg.rb +++ b/build_tests/configure/check_cfg.rb @@ -2,8 +2,6 @@ configure do check_cfg program: "my-config" end -default do - Environment.new(echo: :command) do |env| - env.Program("myconfigtest", "simple.c") - end +env(echo: :command) do |env| + env.Program("myconfigtest", "simple.c") end diff --git a/build_tests/configure/check_cfg_package.rb b/build_tests/configure/check_cfg_package.rb index 26ccfde..9995e95 100644 --- a/build_tests/configure/check_cfg_package.rb +++ b/build_tests/configure/check_cfg_package.rb @@ -2,8 +2,6 @@ configure do check_cfg package: "mypackage" end -default do - Environment.new(echo: :command) do |env| - env.Program("myconfigtest", "simple.c") - end +env(echo: :command) do |env| + env.Program("myconfigtest", "simple.c") end diff --git a/build_tests/configure/check_cfg_use.rb b/build_tests/configure/check_cfg_use.rb index 1a7bb9f..8796cea 100644 --- a/build_tests/configure/check_cfg_use.rb +++ b/build_tests/configure/check_cfg_use.rb @@ -2,14 +2,12 @@ configure do check_cfg package: "mypackage", use: "myp" end -default do - Environment.new(echo: :command) do |env| - env.Copy("myconfigtest1.c", "simple.c") - env.Program("myconfigtest1.exe", "myconfigtest1.c") - end - - Environment.new(echo: :command, use: "myp") do |env| - env.Copy("myconfigtest2.c", "simple.c") - env.Program("myconfigtest2.exe", "myconfigtest2.c") - end +env(echo: :command) do |env| + env.Copy("myconfigtest1.c", "simple.c") + env.Program("myconfigtest1.exe", "myconfigtest1.c") +end + +env(echo: :command, use: "myp") do |env| + env.Copy("myconfigtest2.c", "simple.c") + env.Program("myconfigtest2.exe", "myconfigtest2.c") end diff --git a/build_tests/configure/check_cxx_header_cpppath.rb b/build_tests/configure/check_cxx_header_cpppath.rb index 5650389..2757222 100644 --- a/build_tests/configure/check_cxx_header_cpppath.rb +++ b/build_tests/configure/check_cxx_header_cpppath.rb @@ -3,8 +3,6 @@ configure do check_cxx_header "frobulous.h", check_cpppath: ["./usr2"] end -default do - Environment.new do |env| - env.Object("test.o", "test.cc") - end +env do |env| + env.Object("test.o", "test.cc") end diff --git a/build_tests/configure/check_d_import_d_import_path.rb b/build_tests/configure/check_d_import_d_import_path.rb index 012a428..0bd09c0 100644 --- a/build_tests/configure/check_d_import_d_import_path.rb +++ b/build_tests/configure/check_d_import_d_import_path.rb @@ -4,8 +4,6 @@ configure do check_d_import "frobulous", check_d_import_path: ["./usr2"] end -default do - Environment.new do |env| - env.Object("test.o", "test.d") - end +env do |env| + env.Object("test.o", "test.d") end diff --git a/build_tests/configure/check_lib_libpath1.rb b/build_tests/configure/check_lib_libpath1.rb index 2e6aa30..082672c 100644 --- a/build_tests/configure/check_lib_libpath1.rb +++ b/build_tests/configure/check_lib_libpath1.rb @@ -1,5 +1,3 @@ -default do - Environment.new(echo: :command) do |env| - env.Library("usr2/libfrobulous.a", "two.c") - end +env(echo: :command) do |env| + env.Library("usr2/libfrobulous.a", "two.c") end diff --git a/build_tests/configure/check_lib_libpath2.rb b/build_tests/configure/check_lib_libpath2.rb index 96534ce..9570444 100644 --- a/build_tests/configure/check_lib_libpath2.rb +++ b/build_tests/configure/check_lib_libpath2.rb @@ -3,8 +3,6 @@ configure do check_lib "frobulous", check_libpath: ["./usr2"] end -default do - Environment.new(echo: :command) do |env| - env.Program("simple.exe", "simple.c") - end +env(echo: :command) do |env| + env.Program("simple.exe", "simple.c") end diff --git a/build_tests/configure/check_lib_success.rb b/build_tests/configure/check_lib_success.rb index ad5b7ae..7dd5a35 100644 --- a/build_tests/configure/check_lib_success.rb +++ b/build_tests/configure/check_lib_success.rb @@ -2,8 +2,6 @@ configure do check_lib "m" end -default do - Environment.new(echo: :command) do |env| - env.Program("simple.exe", "simple.c") - end +env(echo: :command) do |env| + env.Program("simple.exe", "simple.c") end diff --git a/build_tests/configure/check_lib_use.rb b/build_tests/configure/check_lib_use.rb index d198332..e18b8be 100644 --- a/build_tests/configure/check_lib_use.rb +++ b/build_tests/configure/check_lib_use.rb @@ -2,14 +2,12 @@ configure do check_lib "m", use: :m end -default do - Environment.new(echo: :command) do |env| - env.Copy("test1.c", "simple.c") - env.Program("test2.exe", "test1.c") - end - - Environment.new(echo: :command, use: %w[m]) do |env| - env.Copy("test2.c", "simple.c") - env.Program("test2.exe", "test2.c") - end +env(echo: :command) do |env| + env.Copy("test1.c", "simple.c") + env.Program("test2.exe", "test1.c") +end + +env(echo: :command, use: %w[m]) do |env| + env.Copy("test2.c", "simple.c") + env.Program("test2.exe", "test2.c") end diff --git a/build_tests/configure/check_lib_use_false.rb b/build_tests/configure/check_lib_use_false.rb index b9cf3bc..e1d794d 100644 --- a/build_tests/configure/check_lib_use_false.rb +++ b/build_tests/configure/check_lib_use_false.rb @@ -2,9 +2,7 @@ configure do check_lib "m", use: false end -default do - Environment.new(echo: :command) do |env| - env.Copy("test1.c", "simple.c") - env.Program("test2.exe", "test1.c") - end +env(echo: :command) do |env| + env.Copy("test1.c", "simple.c") + env.Program("test2.exe", "test1.c") end diff --git a/build_tests/configure/custom_config_check.rb b/build_tests/configure/custom_config_check.rb index 487859a..62554b7 100644 --- a/build_tests/configure/custom_config_check.rb +++ b/build_tests/configure/custom_config_check.rb @@ -23,8 +23,6 @@ configure do end end -default do - Environment.new do |env| - puts env["CPPDEFINES"] - end +env do |env| + puts env["CPPDEFINES"] end diff --git a/build_tests/configure/multiple_set_define.rb b/build_tests/configure/multiple_set_define.rb index eefedc8..e672818 100644 --- a/build_tests/configure/multiple_set_define.rb +++ b/build_tests/configure/multiple_set_define.rb @@ -3,8 +3,6 @@ configure do check_c_header "stdio.h", set_define: "HAVE_STDIO_H" end -default do - Environment.new(echo: :command) do |env| - env.Object("simple.o", "simple.c") - end +env(echo: :command) do |env| + env.Object("simple.o", "simple.c") end diff --git a/build_tests/custom_builder/Rsconscript b/build_tests/custom_builder/Rsconscript index 99a461c..76cd1f5 100644 --- a/build_tests/custom_builder/Rsconscript +++ b/build_tests/custom_builder/Rsconscript @@ -9,10 +9,8 @@ EOF end end -default do - Environment.new do |env| - env.add_builder(MySource) - env.MySource('inc.h', []) - env.Program('program.exe', Dir['*.c']) - end +env do |env| + env.add_builder(MySource) + env.MySource('inc.h', []) + env.Program('program.exe', Dir['*.c']) end diff --git a/build_tests/custom_builder/build_after.rb b/build_tests/custom_builder/build_after.rb index 3c40645..45660cd 100644 --- a/build_tests/custom_builder/build_after.rb +++ b/build_tests/custom_builder/build_after.rb @@ -1,13 +1,11 @@ -default do - 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.Object("program.o", "program.c") - env.build_after("program.o", "${inc_c}") - env.Program("program.exe", ["program.o", "inc.c"]) - end +env 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.Object("program.o", "program.c") + env.build_after("program.o", "${inc_c}") + env.Program("program.exe", ["program.o", "inc.c"]) end diff --git a/build_tests/custom_builder/cvar_expansion.rb b/build_tests/custom_builder/cvar_expansion.rb index 07f55aa..68f4f53 100644 --- a/build_tests/custom_builder/cvar_expansion.rb +++ b/build_tests/custom_builder/cvar_expansion.rb @@ -9,12 +9,10 @@ EOF end end -default do - env = Environment.new do |env| - env["hdr"] = "inc.h" - env["src"] = "program.c" - env.add_builder(MySource) - env.MySource('${hdr}') - env.Program('program.exe', "${src}") - end +env = env do |env| + env["hdr"] = "inc.h" + env["src"] = "program.c" + env.add_builder(MySource) + env.MySource('${hdr}') + env.Program('program.exe', "${src}") end diff --git a/build_tests/custom_builder/cvar_lambda.rb b/build_tests/custom_builder/cvar_lambda.rb index 96affd7..1800444 100644 --- a/build_tests/custom_builder/cvar_lambda.rb +++ b/build_tests/custom_builder/cvar_lambda.rb @@ -9,22 +9,20 @@ EOF end end -default do - e1 = Environment.new do |env| - env.add_builder(MySource) - 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 +e1 = env do |env| + env.add_builder(MySource) + env["one"] = "5" + env[:cfg] = {val: "9"} + env["two"] = lambda do |args| + args[:env][:cfg][:val] end - - e1.clone do |env| - env[:cfg][:val] = "6" - env.MySource('inc.h', []) - env.Program('program.exe', Dir['*.c']) + 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']) +end diff --git a/build_tests/custom_builder/error_run_return_value.rb b/build_tests/custom_builder/error_run_return_value.rb index 6abd8ce..9730ef5 100644 --- a/build_tests/custom_builder/error_run_return_value.rb +++ b/build_tests/custom_builder/error_run_return_value.rb @@ -1,8 +1,6 @@ -default do - Environment.new do |env| - env.add_builder(:MyBuilder) do |options| - "hi" - end - env.MyBuilder("foo") +env do |env| + env.add_builder(:MyBuilder) do |options| + "hi" end + env.MyBuilder("foo") end diff --git a/build_tests/custom_builder/error_wait_for.rb b/build_tests/custom_builder/error_wait_for.rb index 1fb605f..efd4479 100644 --- a/build_tests/custom_builder/error_wait_for.rb +++ b/build_tests/custom_builder/error_wait_for.rb @@ -1,8 +1,6 @@ -default do - Environment.new do |env| - env.add_builder(:MyBuilder) do |options| - wait_for(1) - end - env.MyBuilder("foo") +env do |env| + env.add_builder(:MyBuilder) do |options| + wait_for(1) end + env.MyBuilder("foo") end diff --git a/build_tests/custom_builder/multiple_targets.rb b/build_tests/custom_builder/multiple_targets.rb index 292bb2e..6dbcee3 100644 --- a/build_tests/custom_builder/multiple_targets.rb +++ b/build_tests/custom_builder/multiple_targets.rb @@ -12,10 +12,8 @@ class CHGen < Rscons::Builder end end -default do - Environment.new do |env| - env.add_builder(CHGen) - env.CHGen("inc.c", ["program.c"]) - env.Program("program.exe", %w[program.c inc.c]) - end +env do |env| + env.add_builder(CHGen) + env.CHGen("inc.c", ["program.c"]) + env.Program("program.exe", %w[program.c inc.c]) end diff --git a/build_tests/custom_builder/produces.rb b/build_tests/custom_builder/produces.rb index 552b94c..c9d677c 100644 --- a/build_tests/custom_builder/produces.rb +++ b/build_tests/custom_builder/produces.rb @@ -1,17 +1,15 @@ -default do - Environment.new do |env| - env["build_root"] = env.build_root - env["inc_h"] = "inc.h" +env do |env| + env["build_root"] = env.build_root + env["inc_h"] = "inc.h" - env.Copy("copy_inc.h", "${inc_h}") - env.depends("program.o", "${inc_h}") - env.Object("program.o", "program.c") - env.Program("program.exe", ["program.o", "inc.c"]) + env.Copy("copy_inc.h", "${inc_h}") + env.depends("program.o", "${inc_h}") + env.Object("program.o", "program.c") + env.Program("program.exe", ["program.o", "inc.c"]) - inc_c = env.Command("inc.c", - [], - "CMD" => %w[ruby gen.rb ${_TARGET}], - "CMD_DESC" => "Generating") - inc_c.produces("inc.h") - end + inc_c = env.Command("inc.c", + [], + "CMD" => %w[ruby gen.rb ${_TARGET}], + "CMD_DESC" => "Generating") + inc_c.produces("inc.h") end diff --git a/build_tests/custom_builder/produces_env.rb b/build_tests/custom_builder/produces_env.rb index 727f66e..aa97f33 100644 --- a/build_tests/custom_builder/produces_env.rb +++ b/build_tests/custom_builder/produces_env.rb @@ -1,17 +1,15 @@ -default do - Environment.new do |env| - env["build_root"] = env.build_root - env["inc_h"] = "inc.h" +env do |env| + env["build_root"] = env.build_root + env["inc_h"] = "inc.h" - env.Copy("copy_inc.h", "${inc_h}") - env.depends("program.o", "${inc_h}") - env.Object("program.o", "program.c") - env.Program("program.exe", ["program.o", "inc.c"]) + env.Copy("copy_inc.h", "${inc_h}") + env.depends("program.o", "${inc_h}") + env.Object("program.o", "program.c") + env.Program("program.exe", ["program.o", "inc.c"]) - env.Command("inc.c", - [], - "CMD" => %w[ruby gen.rb ${_TARGET}], - "CMD_DESC" => "Generating") - env.produces("inc.c", "inc.h") - end + env.Command("inc.c", + [], + "CMD" => %w[ruby gen.rb ${_TARGET}], + "CMD_DESC" => "Generating") + env.produces("inc.c", "inc.h") end diff --git a/build_tests/custom_builder/wait_for_thread.rb b/build_tests/custom_builder/wait_for_thread.rb index dbfb2c1..696dc27 100644 --- a/build_tests/custom_builder/wait_for_thread.rb +++ b/build_tests/custom_builder/wait_for_thread.rb @@ -13,9 +13,7 @@ class MyBuilder < Rscons::Builder end end -default do - Environment.new do |env| - env.add_builder(MyBuilder) - env.MyBuilder("foo") - end +env do |env| + env.add_builder(MyBuilder) + env.MyBuilder("foo") end diff --git a/build_tests/d/Rsconscript b/build_tests/d/Rsconscript index 046b8b5..b764fb1 100644 --- a/build_tests/d/Rsconscript +++ b/build_tests/d/Rsconscript @@ -2,8 +2,6 @@ configure do check_d_compiler "gdc" end -default do - Environment.new(echo: :command) do |env| - env.Program("hello-d.exe", glob("*.d")) - end +env(echo: :command) do |env| + env.Program("hello-d.exe", glob("*.d")) end diff --git a/build_tests/d/build-ldc2.rb b/build_tests/d/build-ldc2.rb index a435d40..40d7012 100644 --- a/build_tests/d/build-ldc2.rb +++ b/build_tests/d/build-ldc2.rb @@ -2,8 +2,6 @@ configure do check_d_compiler "ldc2" end -default do - Environment.new(echo: :command) do |env| - env.Program("hello-d.exe", glob("*.d")) - end +env(echo: :command) do |env| + env.Program("hello-d.exe", glob("*.d")) end diff --git a/build_tests/d/link_objects.rb b/build_tests/d/link_objects.rb index 69fba89..8f0dc3d 100644 --- a/build_tests/d/link_objects.rb +++ b/build_tests/d/link_objects.rb @@ -1,7 +1,5 @@ -default do - Environment.new(echo: :command) do |env| - env.Object("main.o", "main.d") - env.Object("mod.o", "mod.d") - env.Program("hello-d.exe", ["main.o", "mod.o"]) - end +env(echo: :command) do |env| + env.Object("main.o", "main.d") + env.Object("mod.o", "mod.d") + env.Program("hello-d.exe", ["main.o", "mod.o"]) end diff --git a/build_tests/direct/c_program.rb b/build_tests/direct/c_program.rb index ffcfe82..ad9e23c 100644 --- a/build_tests/direct/c_program.rb +++ b/build_tests/direct/c_program.rb @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Program("test.exe", glob("*.c"), direct: true) - end +env do |env| + env.Program("test.exe", glob("*.c"), direct: true) end diff --git a/build_tests/direct/c_shared_library.rb b/build_tests/direct/c_shared_library.rb index fa257b2..e24287e 100644 --- a/build_tests/direct/c_shared_library.rb +++ b/build_tests/direct/c_shared_library.rb @@ -1,7 +1,5 @@ -default do - Environment.new do |env| - lib = env.SharedLibrary("mylib", ["two.c", "three.c"], direct: true) - program = env.Program("test.exe", "main.c", "LIBS" => ["mylib"], "LIBPATH" => ["."]) - env.depends(program, lib) - end +env do |env| + lib = env.SharedLibrary("mylib", ["two.c", "three.c"], direct: true) + program = env.Program("test.exe", "main.c", "LIBS" => ["mylib"], "LIBPATH" => ["."]) + env.depends(program, lib) end diff --git a/build_tests/header/Rsconscript b/build_tests/header/Rsconscript index d3dbd70..3a8c55b 100644 --- a/build_tests/header/Rsconscript +++ b/build_tests/header/Rsconscript @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Program('header.exe', Dir['*.c']) - end +env do |env| + env.Program('header.exe', Dir['*.c']) end diff --git a/build_tests/json_to_yaml/Rsconscript b/build_tests/json_to_yaml/Rsconscript index f3e3a31..5a6ab19 100644 --- a/build_tests/json_to_yaml/Rsconscript +++ b/build_tests/json_to_yaml/Rsconscript @@ -1,18 +1,16 @@ -default do - Environment.new do |env| - require 'json' - require 'yaml' - env.add_builder(:JsonToYaml) do |params| - unless @cache.up_to_date?(@target, :JsonToYaml, @sources, @env) - print_run_message("JsonToYaml #{@target}", nil) - @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) +env do |env| + require 'json' + require 'yaml' + env.add_builder(:JsonToYaml) do |params| + unless @cache.up_to_date?(@target, :JsonToYaml, @sources, @env) + print_run_message("JsonToYaml #{@target}", nil) + @cache.mkdir_p(File.dirname(@target)) + File.open(@target, 'w') do |f| + f.write(YAML.dump(JSON.load(IO.read(@sources.first)))) end - true + @cache.register_build(@target, :JsonToYaml, @sources, @env) end - env.JsonToYaml('foo.yml', 'foo.json') + true end + env.JsonToYaml('foo.yml', 'foo.json') end diff --git a/build_tests/library/Rsconscript b/build_tests/library/Rsconscript index b0bc5fd..910f0d7 100644 --- a/build_tests/library/Rsconscript +++ b/build_tests/library/Rsconscript @@ -1,6 +1,4 @@ -default do - 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 +env(echo: :command) do |env| + env.Program('library.exe', ['lib.a', 'three.c']) + env.Library("lib.a", ['one.c', 'two.c'], 'CPPFLAGS' => ['-Dmake_lib']) end diff --git a/build_tests/library/library_from_object.rb b/build_tests/library/library_from_object.rb index fe39fa4..3fa920b 100644 --- a/build_tests/library/library_from_object.rb +++ b/build_tests/library/library_from_object.rb @@ -1,7 +1,5 @@ -default do - Environment.new do |env| - env.Program("library.exe", ["lib.a", "three.c"]) - env.Object("two.o", "two.c") - env.Library("lib.a", ["one.c", "two.o"], 'CPPFLAGS' => ['-Dmake_lib']) - end +env do |env| + env.Program("library.exe", ["lib.a", "three.c"]) + env.Object("two.o", "two.c") + env.Library("lib.a", ["one.c", "two.o"], 'CPPFLAGS' => ['-Dmake_lib']) end diff --git a/build_tests/library/override_arcmd.rb b/build_tests/library/override_arcmd.rb index efa72cf..22f092e 100644 --- a/build_tests/library/override_arcmd.rb +++ b/build_tests/library/override_arcmd.rb @@ -1,6 +1,4 @@ -default do - Environment.new(echo: :command) do |env| - env["ARCMD"] = %w[ar rcf ${_TARGET} ${_SOURCES}] - env.Library("lib.a", glob("*.c")) - end +env(echo: :command) do |env| + env["ARCMD"] = %w[ar rcf ${_TARGET} ${_SOURCES}] + env.Library("lib.a", glob("*.c")) end diff --git a/build_tests/multiple_basename/Rsconscript b/build_tests/multiple_basename/Rsconscript index c35302f..9b4cdb7 100644 --- a/build_tests/multiple_basename/Rsconscript +++ b/build_tests/multiple_basename/Rsconscript @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Program("foo.exe", glob("*.cc", "*.c")) - end +env do |env| + env.Program("foo.exe", glob("*.cc", "*.c")) end diff --git a/build_tests/preprocess/Rsconscript b/build_tests/preprocess/Rsconscript index 793d6d3..f1832cd 100644 --- a/build_tests/preprocess/Rsconscript +++ b/build_tests/preprocess/Rsconscript @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Preprocess("pp", "foo.h") - end +env do |env| + env.Preprocess("pp", "foo.h") end diff --git a/build_tests/shared_library/Rsconscript b/build_tests/shared_library/Rsconscript index 1e46959..646ae93 100644 --- a/build_tests/shared_library/Rsconscript +++ b/build_tests/shared_library/Rsconscript @@ -1,13 +1,11 @@ -default do - Environment.new do |env| - env["CPPPATH"] << "src/lib" - libmine = env.SharedLibrary("mine", glob("src/lib/*.c")) - env.Program("test-shared.exe", - glob("src/*.c"), - "LIBPATH" => %w[.], - "LIBS" => %w[mine]) - env.build_after("test-shared.exe", libmine) - env.Program("test-static.exe", - glob("src/**/*.c")) - end +env do |env| + env["CPPPATH"] << "src/lib" + libmine = env.SharedLibrary("mine", glob("src/lib/*.c")) + env.Program("test-shared.exe", + glob("src/*.c"), + "LIBPATH" => %w[.], + "LIBS" => %w[mine]) + env.build_after("test-shared.exe", libmine) + env.Program("test-static.exe", + glob("src/**/*.c")) end diff --git a/build_tests/shared_library/error_unknown_suffix.rb b/build_tests/shared_library/error_unknown_suffix.rb index 49dfb09..d38496a 100644 --- a/build_tests/shared_library/error_unknown_suffix.rb +++ b/build_tests/shared_library/error_unknown_suffix.rb @@ -1,8 +1,6 @@ -default do - Environment.new do |env| - File.open("foo.xyz", "wb") do |fh| - fh.puts("hi") - end - env.SharedObject("foo.o", "foo.xyz") +env do |env| + File.open("foo.xyz", "wb") do |fh| + fh.puts("hi") end + env.SharedObject("foo.o", "foo.xyz") end diff --git a/build_tests/shared_library/shared_library_as.rb b/build_tests/shared_library/shared_library_as.rb index 7b54422..a43d3fb 100644 --- a/build_tests/shared_library/shared_library_as.rb +++ b/build_tests/shared_library/shared_library_as.rb @@ -1,7 +1,5 @@ -default do - Environment.new do |env| - env["CPPPATH"] << "src/lib" - env.Object("file.S", "src/lib/one.c", "CFLAGS" => env["CFLAGS"] + ["-S"]) - libmine = env.SharedLibrary("mine", "file.S") - end +env do |env| + env["CPPPATH"] << "src/lib" + env.Object("file.S", "src/lib/one.c", "CFLAGS" => env["CFLAGS"] + ["-S"]) + libmine = env.SharedLibrary("mine", "file.S") end diff --git a/build_tests/shared_library/shared_library_cxx.rb b/build_tests/shared_library/shared_library_cxx.rb index 97f5c5d..5faeba4 100644 --- a/build_tests/shared_library/shared_library_cxx.rb +++ b/build_tests/shared_library/shared_library_cxx.rb @@ -1,13 +1,11 @@ -default do - Environment.new do |env| - env["CPPPATH"] << "src/lib" - libmine = env.SharedLibrary("mine", glob("src/lib/*.cc")) - env.Program("test-shared.exe", - glob("src/*.cc"), - "LIBPATH" => %w[.], - "LIBS" => %w[mine]) - env.build_after("test-shared.exe", libmine) - env.Program("test-static.exe", - glob("src/**/*.cc")) - end +env do |env| + env["CPPPATH"] << "src/lib" + libmine = env.SharedLibrary("mine", glob("src/lib/*.cc")) + env.Program("test-shared.exe", + glob("src/*.cc"), + "LIBPATH" => %w[.], + "LIBS" => %w[mine]) + env.build_after("test-shared.exe", libmine) + env.Program("test-static.exe", + glob("src/**/*.cc")) end diff --git a/build_tests/shared_library/shared_library_d.rb b/build_tests/shared_library/shared_library_d.rb index 36c6352..8661146 100644 --- a/build_tests/shared_library/shared_library_d.rb +++ b/build_tests/shared_library/shared_library_d.rb @@ -1,11 +1,9 @@ -default do - Environment.new do |env| - env["CPPPATH"] << "src/lib" - libmine = env.SharedLibrary("mine", glob("src/lib/*.d")) - env.Program("test-shared.exe", - glob("src/*.c"), - "LIBPATH" => %w[.], - "LIBS" => %w[mine]) - env.build_after("test-shared.exe", libmine) - end +env do |env| + env["CPPPATH"] << "src/lib" + libmine = env.SharedLibrary("mine", glob("src/lib/*.d")) + env.Program("test-shared.exe", + glob("src/*.c"), + "LIBPATH" => %w[.], + "LIBS" => %w[mine]) + env.build_after("test-shared.exe", libmine) end diff --git a/build_tests/shared_library/shared_library_from_object.rb b/build_tests/shared_library/shared_library_from_object.rb index 9df7d4d..b96468a 100644 --- a/build_tests/shared_library/shared_library_from_object.rb +++ b/build_tests/shared_library/shared_library_from_object.rb @@ -1,7 +1,5 @@ -default do - Environment.new do |env| - env["CPPPATH"] << "src/lib" - env.SharedObject("one.o", "src/lib/one.c") - libmine = env.SharedLibrary("mine", ["one.o", "src/lib/two.c"]) - end +env do |env| + env["CPPPATH"] << "src/lib" + env.SharedObject("one.o", "src/lib/one.c") + libmine = env.SharedLibrary("mine", ["one.o", "src/lib/two.c"]) end diff --git a/build_tests/shared_library/shared_library_set_shld.rb b/build_tests/shared_library/shared_library_set_shld.rb index 54d7a3e..d8d53aa 100644 --- a/build_tests/shared_library/shared_library_set_shld.rb +++ b/build_tests/shared_library/shared_library_set_shld.rb @@ -1,14 +1,12 @@ -default do - Environment.new do |env| - env["CPPPATH"] << "src/lib" - env["SHLD"] = "gcc" - libmine = env.SharedLibrary("mine", glob("src/lib/*.c")) - env.Program("test-shared.exe", - glob("src/*.c"), - "LIBPATH" => %w[.], - "LIBS" => %w[mine]) - env.build_after("test-shared.exe", libmine) - env.Program("test-static.exe", - glob("src/**/*.c")) - end +env do |env| + env["CPPPATH"] << "src/lib" + env["SHLD"] = "gcc" + libmine = env.SharedLibrary("mine", glob("src/lib/*.c")) + env.Program("test-shared.exe", + glob("src/*.c"), + "LIBPATH" => %w[.], + "LIBS" => %w[mine]) + env.build_after("test-shared.exe", libmine) + env.Program("test-static.exe", + glob("src/**/*.c")) end diff --git a/build_tests/simple/Rsconscript b/build_tests/simple/Rsconscript index d80cb69..1c9c1df 100644 --- a/build_tests/simple/Rsconscript +++ b/build_tests/simple/Rsconscript @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Program('simple.exe', Dir['*.c']) - end +env do |env| + env.Program('simple.exe', Dir['*.c']) end diff --git a/build_tests/simple/absolute_source_path.rb b/build_tests/simple/absolute_source_path.rb index 08d8b5c..48b283b 100644 --- a/build_tests/simple/absolute_source_path.rb +++ b/build_tests/simple/absolute_source_path.rb @@ -1,15 +1,13 @@ -default do - Environment.new(echo: :command) 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) +env(echo: :command) 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 diff --git a/build_tests/simple/barrier.rb b/build_tests/simple/barrier.rb index aed2974..1603671 100644 --- a/build_tests/simple/barrier.rb +++ b/build_tests/simple/barrier.rb @@ -10,15 +10,13 @@ class ThreadedTestBuilder < Rscons::Builder end end -default do - Environment.new do |env| - env.add_builder(ThreadedTestBuilder) - env.ThreadedTestBuilder("T3", [], "delay" => 3) - env.ThreadedTestBuilder("T2", [], "delay" => 1.0) - env.ThreadedTestBuilder("T1", [], "delay" => 0.5) - env.barrier - env.ThreadedTestBuilder("T6", [], "delay" => 1.5) - env.ThreadedTestBuilder("T5", [], "delay" => 1.0) - env.ThreadedTestBuilder("T4", [], "delay" => 0.5) - end +env do |env| + env.add_builder(ThreadedTestBuilder) + env.ThreadedTestBuilder("T3", [], "delay" => 3) + env.ThreadedTestBuilder("T2", [], "delay" => 1.0) + env.ThreadedTestBuilder("T1", [], "delay" => 0.5) + env.barrier + env.ThreadedTestBuilder("T6", [], "delay" => 1.5) + env.ThreadedTestBuilder("T5", [], "delay" => 1.0) + env.ThreadedTestBuilder("T4", [], "delay" => 0.5) end diff --git a/build_tests/simple/builder_as_source.rb b/build_tests/simple/builder_as_source.rb index 46a7a41..818bee1 100644 --- a/build_tests/simple/builder_as_source.rb +++ b/build_tests/simple/builder_as_source.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - object = env.Object("simple.o", "simple.c") - env.Program("simple.exe", object) - end +env do |env| + object = env.Object("simple.o", "simple.c") + env.Program("simple.exe", object) end diff --git a/build_tests/simple/builder_no_sources.rb b/build_tests/simple/builder_no_sources.rb index 16c4fe8..6f207d2 100644 --- a/build_tests/simple/builder_no_sources.rb +++ b/build_tests/simple/builder_no_sources.rb @@ -3,9 +3,8 @@ class TestBuilder < Rscons::Builder true end end -default do - Environment.new do |env| - env.add_builder(TestBuilder) - env.TestBuilder("file") - end + +env do |env| + env.add_builder(TestBuilder) + env.TestBuilder("file") end diff --git a/build_tests/simple/builder_wait_for_builder.rb b/build_tests/simple/builder_wait_for_builder.rb index c0cc255..4f991f1 100644 --- a/build_tests/simple/builder_wait_for_builder.rb +++ b/build_tests/simple/builder_wait_for_builder.rb @@ -14,10 +14,8 @@ class MyObject < Rscons::Builder end end -default do - Environment.new do |env| - env.add_builder(MyObject) - env.MyObject("simple.o", "simple.c") - env.Program("simple.exe", "simple.o") - end +env do |env| + env.add_builder(MyObject) + env.MyObject("simple.o", "simple.c") + env.Program("simple.exe", "simple.o") end diff --git a/build_tests/simple/cache_command_change.rb b/build_tests/simple/cache_command_change.rb index d39ea04..1749877 100644 --- a/build_tests/simple/cache_command_change.rb +++ b/build_tests/simple/cache_command_change.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - env["LIBS"] += ["m"] - env.Program('simple.exe', Dir['*.c']) - end +env do |env| + env["LIBS"] += ["m"] + env.Program('simple.exe', Dir['*.c']) end diff --git a/build_tests/simple/cache_debugging.rb b/build_tests/simple/cache_debugging.rb index 77a381d..02438ba 100644 --- a/build_tests/simple/cache_debugging.rb +++ b/build_tests/simple/cache_debugging.rb @@ -27,12 +27,10 @@ class DebugBuilder < Rscons::Builder end end -default do - Environment.new do |env| - env.add_builder(DebugBuilder) - if ENV["test"] == "new_user_dep" - env.depends("foo.o", "new_dep") - end - env.DebugBuilder("foo.o", "simple.c") +env do |env| + env.add_builder(DebugBuilder) + if ENV["test"] == "new_user_dep" + env.depends("foo.o", "new_dep") 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 6ac75b7..f039c50 100644 --- a/build_tests/simple/cache_dep_checksum_change.rb +++ b/build_tests/simple/cache_dep_checksum_change.rb @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Copy("simple.copy", "simple.c") - end +env do |env| + env.Copy("simple.copy", "simple.c") end diff --git a/build_tests/simple/cache_new_dep1.rb b/build_tests/simple/cache_new_dep1.rb index 381d5ec..c3dab2e 100644 --- a/build_tests/simple/cache_new_dep1.rb +++ b/build_tests/simple/cache_new_dep1.rb @@ -1,8 +1,6 @@ -default do - 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 +env do |env| + env.Object("simple.o", "simple.c") + env.process + env["LDCMD"] = %w[gcc -o ${_TARGET} simple.o] + env.Program('simple.exe', []) end diff --git a/build_tests/simple/cache_new_dep2.rb b/build_tests/simple/cache_new_dep2.rb index d21029f..bf8512e 100644 --- a/build_tests/simple/cache_new_dep2.rb +++ b/build_tests/simple/cache_new_dep2.rb @@ -1,7 +1,5 @@ -default do - 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 +env do |env| + env.Object("simple.o", "simple.c") + env["LDCMD"] = %w[gcc -o ${_TARGET} simple.o] + env.Program('simple.exe', ["simple.o"]) 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 f7a700a..591cf8c 100644 --- a/build_tests/simple/cache_successful_builds_when_one_fails.rb +++ b/build_tests/simple/cache_successful_builds_when_one_fails.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - env.Object("simple.o", "simple.c") - env.Object("two.o", "two.c") - end +env do |env| + env.Object("simple.o", "simple.c") + env.Object("two.o", "two.c") end diff --git a/build_tests/simple/cache_user_dep.rb b/build_tests/simple/cache_user_dep.rb index 4ba98f1..0239791 100644 --- a/build_tests/simple/cache_user_dep.rb +++ b/build_tests/simple/cache_user_dep.rb @@ -1,7 +1,5 @@ -default do - 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 +env do |env| + target = env.Program("simple.exe", "simple.c") + user_deps = File.read("user_deps", mode: "rb").split(" ") + target.depends(*user_deps) end diff --git a/build_tests/simple/cache_varset.rb b/build_tests/simple/cache_varset.rb index 85b8c77..f67dba1 100644 --- a/build_tests/simple/cache_varset.rb +++ b/build_tests/simple/cache_varset.rb @@ -13,9 +13,7 @@ class TestBuilder < Rscons::Builder end end -default do - Environment.new do |env| - env.add_builder(TestBuilder) - env.TestBuilder("foo") - end +env do |env| + env.add_builder(TestBuilder) + env.TestBuilder("foo") end diff --git a/build_tests/simple/clear_targets.rb b/build_tests/simple/clear_targets.rb index 101fb47..4bd86aa 100644 --- a/build_tests/simple/clear_targets.rb +++ b/build_tests/simple/clear_targets.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - env.Program("simple.exe", "simple.c") - env.clear_targets - end +env do |env| + env.Program("simple.exe", "simple.c") + env.clear_targets end diff --git a/build_tests/simple/clone_n_threads.rb b/build_tests/simple/clone_n_threads.rb index 17e7f09..fcb5677 100644 --- a/build_tests/simple/clone_n_threads.rb +++ b/build_tests/simple/clone_n_threads.rb @@ -1,9 +1,7 @@ -default do - base_env = Environment.new do |env| - env.n_threads = 165 - end - - my_env = base_env.clone - - puts my_env.n_threads +base_env = env do |env| + env.n_threads = 165 +end + +my_env = base_env.clone do |env| + puts env.n_threads end diff --git a/build_tests/simple/command.rb b/build_tests/simple/command.rb index cfa2c81..3103b9b 100644 --- a/build_tests/simple/command.rb +++ b/build_tests/simple/command.rb @@ -1,6 +1,4 @@ -default do - Environment.new(echo: :command) do |env| - env["LD"] = "gcc" - env.Program('simple.exe', Dir['*.c']) - end +env(echo: :command) do |env| + env["LD"] = "gcc" + env.Program('simple.exe', Dir['*.c']) end diff --git a/build_tests/simple/command_builder.rb b/build_tests/simple/command_builder.rb index c9bbe50..f3d7844 100644 --- a/build_tests/simple/command_builder.rb +++ b/build_tests/simple/command_builder.rb @@ -1,9 +1,7 @@ -default do - Environment.new do |env| - command = %W[gcc -o ${_TARGET} ${_SOURCES}] - env.Command("simple.exe", - "simple.c", - "CMD" => command, - "CMD_DESC" => "BuildIt") - end +env do |env| + command = %W[gcc -o ${_TARGET} ${_SOURCES}] + env.Command("simple.exe", + "simple.c", + "CMD" => command, + "CMD_DESC" => "BuildIt") end diff --git a/build_tests/simple/command_redirect.rb b/build_tests/simple/command_redirect.rb index fe201cb..ea065f7 100644 --- a/build_tests/simple/command_redirect.rb +++ b/build_tests/simple/command_redirect.rb @@ -1,10 +1,8 @@ -default do - 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 +env 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 diff --git a/build_tests/simple/cvar_array.rb b/build_tests/simple/cvar_array.rb index 3335f5a..dc53ed9 100644 --- a/build_tests/simple/cvar_array.rb +++ b/build_tests/simple/cvar_array.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - env["sources"] = glob("*.c") - env.Program("simple.exe", "${sources}") - end +env do |env| + env["sources"] = glob("*.c") + env.Program("simple.exe", "${sources}") end diff --git a/build_tests/simple/directory.rb b/build_tests/simple/directory.rb index d6b6659..3b72da2 100644 --- a/build_tests/simple/directory.rb +++ b/build_tests/simple/directory.rb @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Directory("teh_dir") - end +env do |env| + env.Directory("teh_dir") end diff --git a/build_tests/simple/disassemble.rb b/build_tests/simple/disassemble.rb index 743bdc9..cba28b8 100644 --- a/build_tests/simple/disassemble.rb +++ b/build_tests/simple/disassemble.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - env.Object("simple.o", "simple.c") - env.Disassemble("simple.txt", "simple.o") - end +env do |env| + env.Object("simple.o", "simple.c") + env.Disassemble("simple.txt", "simple.o") end diff --git a/build_tests/simple/distclean.rb b/build_tests/simple/distclean.rb index f353e3e..e912c01 100644 --- a/build_tests/simple/distclean.rb +++ b/build_tests/simple/distclean.rb @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Object("simple.o", "simple.c") - end +env do |env| + env.Object("simple.o", "simple.c") end diff --git a/build_tests/simple/dump.rb b/build_tests/simple/dump.rb index eab53ce..8ea9b66 100644 --- a/build_tests/simple/dump.rb +++ b/build_tests/simple/dump.rb @@ -1,5 +1,5 @@ default do - env = Environment.new do |env| + env = env do |env| env["CFLAGS"] += %w[-O2 -fomit-frame-pointer] env[:foo] = :bar end diff --git a/build_tests/simple/error_circular_dependency.rb b/build_tests/simple/error_circular_dependency.rb index a579a3c..2c7b710 100644 --- a/build_tests/simple/error_circular_dependency.rb +++ b/build_tests/simple/error_circular_dependency.rb @@ -1,7 +1,5 @@ -default do - Environment.new do |env| - env.Command("foo", "bar") - env.Command("bar", "baz") - env.Command("baz", "foo") - end +env do |env| + env.Command("foo", "bar") + env.Command("bar", "baz") + env.Command("baz", "foo") end diff --git a/build_tests/simple/error_circular_dependency2.rb b/build_tests/simple/error_circular_dependency2.rb index 3d3e6c9..6cedbf4 100644 --- a/build_tests/simple/error_circular_dependency2.rb +++ b/build_tests/simple/error_circular_dependency2.rb @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Command("foo", "foo") - end +env do |env| + env.Command("foo", "foo") end diff --git a/build_tests/simple/error_produces_nonexistent_target.rb b/build_tests/simple/error_produces_nonexistent_target.rb index 5d246e3..91b03d3 100644 --- a/build_tests/simple/error_produces_nonexistent_target.rb +++ b/build_tests/simple/error_produces_nonexistent_target.rb @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.produces("foo", "bar") - end +env do |env| + env.produces("foo", "bar") end diff --git a/build_tests/simple/error_unknown_suffix.rb b/build_tests/simple/error_unknown_suffix.rb index bd1817d..8434a0a 100644 --- a/build_tests/simple/error_unknown_suffix.rb +++ b/build_tests/simple/error_unknown_suffix.rb @@ -1,8 +1,6 @@ -default do - Environment.new do |env| - File.open("foo.xyz", "wb") do |fh| - fh.puts("hi") - end - env.Object("foo.o", "foo.xyz") +env do |env| + File.open("foo.xyz", "wb") do |fh| + fh.puts("hi") 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 bae47f5..381cbdd 100644 --- a/build_tests/simple/link_flag_change.rb +++ b/build_tests/simple/link_flag_change.rb @@ -1,7 +1,5 @@ -default do - Environment.new(echo: :command) do |env| - env["LD"] = "gcc" - env["LIBPATH"] += ["libdir"] - env.Program('simple.exe', Dir['*.c']) - end +env(echo: :command) do |env| + env["LD"] = "gcc" + env["LIBPATH"] += ["libdir"] + env.Program('simple.exe', Dir['*.c']) end diff --git a/build_tests/simple/override_cccmd.rb b/build_tests/simple/override_cccmd.rb index 59cbd93..7140a32 100644 --- a/build_tests/simple/override_cccmd.rb +++ b/build_tests/simple/override_cccmd.rb @@ -1,6 +1,4 @@ -default do - Environment.new(echo: :command) do |env| - env.Object("simple.o", "simple.c", - "CCCMD" => %w[${CC} -c -o ${_TARGET} -Dfoobar ${_SOURCES}]) - end +env(echo: :command) do |env| + env.Object("simple.o", "simple.c", + "CCCMD" => %w[${CC} -c -o ${_TARGET} -Dfoobar ${_SOURCES}]) end diff --git a/build_tests/simple/override_depfilesuffix.rb b/build_tests/simple/override_depfilesuffix.rb index 80e1b25..dfb0f50 100644 --- a/build_tests/simple/override_depfilesuffix.rb +++ b/build_tests/simple/override_depfilesuffix.rb @@ -1,6 +1,4 @@ -default do - Environment.new(echo: :command) do |env| - env["DEPFILESUFFIX"] = ".deppy" - env.Object("simple.o", "simple.c") - end +env(echo: :command) do |env| + env["DEPFILESUFFIX"] = ".deppy" + env.Object("simple.o", "simple.c") end diff --git a/build_tests/simple/pathing.rb b/build_tests/simple/pathing.rb index 58f7c55..5be2e8e 100644 --- a/build_tests/simple/pathing.rb +++ b/build_tests/simple/pathing.rb @@ -1,10 +1,8 @@ path_prepend "path_prepend" path_append "path_append" -default do - Environment.new do |env| - system("flex") - system("foobar") - env.Object("simple.o", "simple.c") - end +env do |env| + system("flex") + system("foobar") + env.Object("simple.o", "simple.c") end diff --git a/build_tests/simple/phony_target.rb b/build_tests/simple/phony_target.rb index 77484c7..6ed5663 100644 --- a/build_tests/simple/phony_target.rb +++ b/build_tests/simple/phony_target.rb @@ -1,13 +1,11 @@ -default do - Environment.new do |env| - env.add_builder(:Checker) do |params| - 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 - true +env do |env| + env.add_builder(:Checker) do |params| + 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 - env.Program("simple.exe", "simple.c") - env.Checker(:checker, "simple.exe") + true 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 030ab4c..d88520d 100644 --- a/build_tests/simple/preprocess.rb +++ b/build_tests/simple/preprocess.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - env.Preprocess("simplepp.c", "simple.c") - env.Program("simple.exe", "simplepp.c") - end +env do |env| + env.Preprocess("simplepp.c", "simple.c") + env.Program("simple.exe", "simplepp.c") end diff --git a/build_tests/simple/progsuffix.rb b/build_tests/simple/progsuffix.rb index 6bec0d0..405ee01 100644 --- a/build_tests/simple/progsuffix.rb +++ b/build_tests/simple/progsuffix.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - env["PROGSUFFIX"] = ".out" - env.Program("simple", Dir["*.c"]) - end +env do |env| + env["PROGSUFFIX"] = ".out" + env.Program("simple", Dir["*.c"]) end diff --git a/build_tests/simple/progsuffix2.rb b/build_tests/simple/progsuffix2.rb index 7e9788d..3b99c86 100644 --- a/build_tests/simple/progsuffix2.rb +++ b/build_tests/simple/progsuffix2.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - env["MYSUFFIX"] = ".out" - env.Program("simple${MYSUFFIX}", Dir["*.c"]) - end +env do |env| + env["MYSUFFIX"] = ".out" + env.Program("simple${MYSUFFIX}", Dir["*.c"]) end diff --git a/build_tests/simple/progsuffix3.rb b/build_tests/simple/progsuffix3.rb index 6aed2cf..54c6368 100644 --- a/build_tests/simple/progsuffix3.rb +++ b/build_tests/simple/progsuffix3.rb @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Program("simple", Dir["*.c"], "PROGSUFFIX" => ".xyz") - end +env do |env| + env.Program("simple", Dir["*.c"], "PROGSUFFIX" => ".xyz") end diff --git a/build_tests/simple/register_target_in_build_hook.rb b/build_tests/simple/register_target_in_build_hook.rb index 0ad4ee4..dc03466 100644 --- a/build_tests/simple/register_target_in_build_hook.rb +++ b/build_tests/simple/register_target_in_build_hook.rb @@ -1,10 +1,8 @@ -default do - Environment.new do |env| - env.Program("simple.exe", Dir["*.c"]) - env.add_build_hook do |builder| - if builder.target.end_with?(".o") - env.Disassemble("#{builder.target}.txt", builder.target) - end +env do |env| + env.Program("simple.exe", Dir["*.c"]) + env.add_build_hook do |builder| + if builder.target.end_with?(".o") + env.Disassemble("#{builder.target}.txt", builder.target) end end end diff --git a/build_tests/simple/size.rb b/build_tests/simple/size.rb index bfa4efa..e57de2e 100644 --- a/build_tests/simple/size.rb +++ b/build_tests/simple/size.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - env.Program("simple.exe", glob("*.c")) - env.Size("simple.size", "simple.exe") - end +env do |env| + env.Program("simple.exe", glob("*.c")) + env.Size("simple.size", "simple.exe") end diff --git a/build_tests/simple/threading.rb b/build_tests/simple/threading.rb index f42d3db..deced25 100644 --- a/build_tests/simple/threading.rb +++ b/build_tests/simple/threading.rb @@ -17,13 +17,11 @@ class NonThreadedTestBuilder < Rscons::Builder end end -default do - Environment.new do |env| - env.add_builder(ThreadedTestBuilder) - env.add_builder(NonThreadedTestBuilder) - env.ThreadedTestBuilder("a") - env.ThreadedTestBuilder("b") - env.ThreadedTestBuilder("c") - env.NonThreadedTestBuilder("d") - end +env do |env| + env.add_builder(ThreadedTestBuilder) + env.add_builder(NonThreadedTestBuilder) + env.ThreadedTestBuilder("a") + env.ThreadedTestBuilder("b") + env.ThreadedTestBuilder("c") + env.NonThreadedTestBuilder("d") end diff --git a/build_tests/simple/user_dep_build_order.rb b/build_tests/simple/user_dep_build_order.rb index 43965f4..2ce76ec 100644 --- a/build_tests/simple/user_dep_build_order.rb +++ b/build_tests/simple/user_dep_build_order.rb @@ -13,11 +13,9 @@ class TestBuilder < Rscons::Builder end end -default do - Environment.new do |env| - env.add_builder(TestBuilder) - one = env.TestBuilder("one", [], "wait_time" => "3") - two = env.TestBuilder("two", [], "wait_time" => "0") - env.depends(two, one) - end +env do |env| + env.add_builder(TestBuilder) + one = env.TestBuilder("one", [], "wait_time" => "3") + two = env.TestBuilder("two", [], "wait_time" => "0") + env.depends(two, one) end diff --git a/build_tests/simple/user_dependencies.rb b/build_tests/simple/user_dependencies.rb index 04ae089..9ecaf80 100644 --- a/build_tests/simple/user_dependencies.rb +++ b/build_tests/simple/user_dependencies.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - program = env.Program("simple.exe", Dir["*.c"]) - env.depends(program, "program.ld") - end +env do |env| + program = env.Program("simple.exe", Dir["*.c"]) + env.depends(program, "program.ld") end diff --git a/build_tests/simple/user_dependencies_carat.rb b/build_tests/simple/user_dependencies_carat.rb index dddf9da..a877b93 100644 --- a/build_tests/simple/user_dependencies_carat.rb +++ b/build_tests/simple/user_dependencies_carat.rb @@ -8,11 +8,10 @@ class FileBuilder < Builder true end end -default do - Environment.new do |env| - env.add_builder(FileBuilder) - env.File("^/file.txt") - program = env.Program("^/simple.exe", Dir["*.c"]) - env.depends("^/simple.exe", "^/file.txt") - end + +env do |env| + env.add_builder(FileBuilder) + env.File("^/file.txt") + program = env.Program("^/simple.exe", Dir["*.c"]) + env.depends("^/simple.exe", "^/file.txt") end diff --git a/build_tests/simple/wait_for_builds_on_failure.rb b/build_tests/simple/wait_for_builds_on_failure.rb index c491d64..33dfc0b 100644 --- a/build_tests/simple/wait_for_builds_on_failure.rb +++ b/build_tests/simple/wait_for_builds_on_failure.rb @@ -11,12 +11,10 @@ class Fail < Rscons::Builder end end -default do - Environment.new do |env| - env.add_builder(Fail) - 4.times do |i| - wait_time = i + 1 - env.Fail("foo_#{wait_time}", [], "wait_time" => wait_time.to_s) - end +env do |env| + env.add_builder(Fail) + 4.times do |i| + wait_time = i + 1 + env.Fail("foo_#{wait_time}", [], "wait_time" => wait_time.to_s) end end diff --git a/build_tests/simple_cc/Rsconscript b/build_tests/simple_cc/Rsconscript index bd0600e..d328875 100644 --- a/build_tests/simple_cc/Rsconscript +++ b/build_tests/simple_cc/Rsconscript @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Program('simple.exe', Dir['*.cc']) - end +env do |env| + env.Program('simple.exe', Dir['*.cc']) end diff --git a/build_tests/simple_cc/cxxsuffix.rb b/build_tests/simple_cc/cxxsuffix.rb index a6659af..44bf478 100644 --- a/build_tests/simple_cc/cxxsuffix.rb +++ b/build_tests/simple_cc/cxxsuffix.rb @@ -1,7 +1,5 @@ -default do - Environment.new do |env| - env["CXXSUFFIX"] = %w[.cccc .cc] - env["CXXFLAGS"] += %w[-x c++] - env.Program("simple.exe", Dir["*.cc"] + Dir["*.cccc"]) - end +env do |env| + env["CXXSUFFIX"] = %w[.cccc .cc] + env["CXXFLAGS"] += %w[-x c++] + env.Program("simple.exe", Dir["*.cc"] + Dir["*.cccc"]) end diff --git a/build_tests/simple_cc/link_objects.rb b/build_tests/simple_cc/link_objects.rb index 8eccca2..fb6b050 100644 --- a/build_tests/simple_cc/link_objects.rb +++ b/build_tests/simple_cc/link_objects.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - env.Object("simple.o", "simple.cc") - env.Program("simple.exe", "simple.o") - end +env do |env| + env.Object("simple.o", "simple.cc") + env.Program("simple.exe", "simple.o") end diff --git a/build_tests/simple_cc/preprocess.rb b/build_tests/simple_cc/preprocess.rb index ac18dca..17e4611 100644 --- a/build_tests/simple_cc/preprocess.rb +++ b/build_tests/simple_cc/preprocess.rb @@ -1,6 +1,4 @@ -default do - Environment.new do |env| - env.Preprocess("simplepp.cc", "simple.cc") - env.Program("simple.exe", "simplepp.cc") - end +env do |env| + env.Preprocess("simplepp.cc", "simple.cc") + env.Program("simple.exe", "simplepp.cc") end diff --git a/build_tests/tasks/tasks.rb b/build_tests/tasks/tasks.rb index dc2e3ec..773ab62 100644 --- a/build_tests/tasks/tasks.rb +++ b/build_tests/tasks/tasks.rb @@ -2,7 +2,7 @@ task "one" do puts "one" end -task "two", deps: ["one", "three"] do +task "two", depends: ["one", "three"] do puts "two" end diff --git a/build_tests/two_sources/Rsconscript b/build_tests/two_sources/Rsconscript index f2baeee..799366b 100644 --- a/build_tests/two_sources/Rsconscript +++ b/build_tests/two_sources/Rsconscript @@ -1,6 +1,4 @@ -default do - Environment.new(echo: :command) do |env| - env.Object("one.o", "one.c", 'CPPFLAGS' => ['-DONE']) - env.Program('two_sources.exe', ['one.o', 'two.c']) - end +env(echo: :command) do |env| + env.Object("one.o", "one.c", 'CPPFLAGS' => ['-DONE']) + env.Program('two_sources.exe', ['one.o', 'two.c']) end diff --git a/build_tests/two_sources/assuffix.rb b/build_tests/two_sources/assuffix.rb index 2a57161..7803b97 100644 --- a/build_tests/two_sources/assuffix.rb +++ b/build_tests/two_sources/assuffix.rb @@ -1,9 +1,7 @@ -default do - 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 +env 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 diff --git a/build_tests/two_sources/cache_strict_deps.rb b/build_tests/two_sources/cache_strict_deps.rb index b052497..9901372 100644 --- a/build_tests/two_sources/cache_strict_deps.rb +++ b/build_tests/two_sources/cache_strict_deps.rb @@ -13,12 +13,10 @@ class StrictBuilder < Rscons::Builder end end -default do - Environment.new(echo: :command) do |env| - env.add_builder(StrictBuilder) - 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 +env(echo: :command) do |env| + env.add_builder(StrictBuilder) + 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 diff --git a/build_tests/two_sources/libsuffix.rb b/build_tests/two_sources/libsuffix.rb index cc5c648..2d7077f 100644 --- a/build_tests/two_sources/libsuffix.rb +++ b/build_tests/two_sources/libsuffix.rb @@ -1,8 +1,6 @@ -default do - 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 +env 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 diff --git a/build_tests/two_sources/objsuffix.rb b/build_tests/two_sources/objsuffix.rb index 203d1dd..c1fe952 100644 --- a/build_tests/two_sources/objsuffix.rb +++ b/build_tests/two_sources/objsuffix.rb @@ -1,8 +1,6 @@ -default do - 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 +env 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 diff --git a/build_tests/typical/Rsconscript b/build_tests/typical/Rsconscript index 46cada8..9898593 100644 --- a/build_tests/typical/Rsconscript +++ b/build_tests/typical/Rsconscript @@ -1,6 +1,4 @@ -default do - Environment.new(name: "typical") do |env| - env["CPPPATH"] += glob("src/**") - env.Program("^/typical.exe", glob("src/**/*.c")) - end +env "typical" do |env| + env["CPPPATH"] += glob("src/**") + env.Program("^/typical.exe", glob("src/**/*.c")) end diff --git a/build_tests/typical/build_hooks.rb b/build_tests/typical/build_hooks.rb index 6b67f9d..2fc31ce 100644 --- a/build_tests/typical/build_hooks.rb +++ b/build_tests/typical/build_hooks.rb @@ -1,13 +1,11 @@ -default do - Environment.new(echo: :command) do |env| - env.append('CPPPATH' => glob('src/**/*/')) - env.add_build_hook do |builder| - if File.basename(builder.sources.first) == "one.c" - builder.vars["CFLAGS"] << "-O1" - elsif File.basename(builder.sources.first) == "two.c" - builder.vars["CFLAGS"] << "-O2" - end +env(echo: :command) do |env| + env.append('CPPPATH' => glob('src/**/*/')) + env.add_build_hook do |builder| + if File.basename(builder.sources.first) == "one.c" + builder.vars["CFLAGS"] << "-O1" + elsif File.basename(builder.sources.first) == "two.c" + builder.vars["CFLAGS"] << "-O2" end - env.Program('build_hook.exe', glob('src/**/*.c')) end + env.Program('build_hook.exe', glob('src/**/*.c')) end diff --git a/build_tests/typical/build_hooks_override_vars.rb b/build_tests/typical/build_hooks_override_vars.rb index 5d8eada..d6810c3 100644 --- a/build_tests/typical/build_hooks_override_vars.rb +++ b/build_tests/typical/build_hooks_override_vars.rb @@ -1,17 +1,15 @@ -default do - Environment.new(echo: :command) do |env| - env.append('CPPPATH' => glob('src/**')) - env.add_build_hook do |builder| - if builder.name == "Object" && builder.sources.first =~ %r{one\.c} - builder.vars["CFLAGS"] << "-O1" - builder.sources = ['src/two/two.c'] - elsif builder.name == "Object" && builder.target =~ %r{two\.o} - new_vars = builder.vars.clone - new_vars["CFLAGS"] << "-O2" - builder.vars = new_vars - end +env(echo: :command) do |env| + env.append('CPPPATH' => glob('src/**')) + env.add_build_hook do |builder| + if builder.name == "Object" && builder.sources.first =~ %r{one\.c} + builder.vars["CFLAGS"] << "-O1" + builder.sources = ['src/two/two.c'] + elsif builder.name == "Object" && builder.target =~ %r{two\.o} + new_vars = builder.vars.clone + new_vars["CFLAGS"] << "-O2" + builder.vars = new_vars end - env.Object('one.o', 'src/one/one.c') - env.Object('two.o', 'src/two/two.c') end + env.Object('one.o', 'src/one/one.c') + env.Object('two.o', 'src/two/two.c') end diff --git a/build_tests/typical/carat.rb b/build_tests/typical/carat.rb index a8a5361..6e96d48 100644 --- a/build_tests/typical/carat.rb +++ b/build_tests/typical/carat.rb @@ -1,10 +1,8 @@ -default do - Environment.new(echo: :command) do |env| - env.append("CPPPATH" => glob("src/**")) - FileUtils.mkdir_p(env.build_root) - FileUtils.mv("src/one/one.c", env.build_root) - FileUtils.mv("src/two/two.c", Rscons.application.build_dir) - env.Object("^/one.o", "^/one.c") - env.Program("^^/program.exe", ["^/one.o", "^^/two.c"]) - end +env(echo: :command) do |env| + env.append("CPPPATH" => glob("src/**")) + FileUtils.mkdir_p(env.build_root) + FileUtils.mv("src/one/one.c", env.build_root) + FileUtils.mv("src/two/two.c", Rscons.application.build_dir) + env.Object("^/one.o", "^/one.c") + env.Program("^^/program.exe", ["^/one.o", "^^/two.c"]) end diff --git a/build_tests/typical/clone_and_name.rb b/build_tests/typical/clone_and_name.rb index 01e8b58..8dae2d5 100644 --- a/build_tests/typical/clone_and_name.rb +++ b/build_tests/typical/clone_and_name.rb @@ -1,9 +1,7 @@ -default do - base_env = Environment.new do |env| - env["CPPPATH"] += glob("src/**") - end - - base_env.clone(name: "typical") do |env| - env.Program("^/typical.exe", glob("src/**/*.c")) - end +base_env = env do |env| + env["CPPPATH"] += glob("src/**") +end + +base_env.clone "typical" do |env| + env.Program("^/typical.exe", glob("src/**/*.c")) end diff --git a/build_tests/typical/clone_with_lookup.rb b/build_tests/typical/clone_with_lookup.rb new file mode 100644 index 0000000..31a7232 --- /dev/null +++ b/build_tests/typical/clone_with_lookup.rb @@ -0,0 +1,7 @@ +env "first" do |env| + env["CPPPATH"] += glob("src/**") +end + +Environment["first"].clone "typical" do |env| + env.Program("^/typical.exe", glob("src/**/*.c")) +end diff --git a/build_tests/typical/copy.rb b/build_tests/typical/copy.rb index 23775b6..9c60ee1 100644 --- a/build_tests/typical/copy.rb +++ b/build_tests/typical/copy.rb @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Copy("inst.exe", "copy.rb") - end +env do |env| + env.Copy("inst.exe", "copy.rb") end diff --git a/build_tests/typical/copy_directory.rb b/build_tests/typical/copy_directory.rb index f586d4e..a4bfcd9 100644 --- a/build_tests/typical/copy_directory.rb +++ b/build_tests/typical/copy_directory.rb @@ -1,11 +1,9 @@ -default do - Environment.new do |env| - env.Directory("copy") - env.Copy("copy", "copy_directory.rb") +env do |env| + env.Directory("copy") + env.Copy("copy", "copy_directory.rb") - env.Copy("noexist/src", "src") + env.Copy("noexist/src", "src") - env.Directory("exist/src") - env.Copy("exist/src", "src") - end + env.Directory("exist/src") + env.Copy("exist/src", "src") end diff --git a/build_tests/typical/copy_multiple.rb b/build_tests/typical/copy_multiple.rb index 2c34ebe..ebd783d 100644 --- a/build_tests/typical/copy_multiple.rb +++ b/build_tests/typical/copy_multiple.rb @@ -1,5 +1,3 @@ -default do - Environment.new do |env| - env.Copy("dest", ["copy.rb", "copy_multiple.rb"]) - end +env do |env| + env.Copy("dest", ["copy.rb", "copy_multiple.rb"]) end diff --git a/build_tests/typical/csuffix.rb b/build_tests/typical/csuffix.rb index b4beaa9..f5b7bcd 100644 --- a/build_tests/typical/csuffix.rb +++ b/build_tests/typical/csuffix.rb @@ -1,8 +1,6 @@ -default do - Environment.new do |env| - env["CSUFFIX"] = %w[.yargh .c] - env["CFLAGS"] += %w[-x c] - env["CPPPATH"] += glob("src/**") - env.Program("program.exe", glob("src/**/*.{c,yargh}")) - end +env do |env| + env["CSUFFIX"] = %w[.yargh .c] + env["CFLAGS"] += %w[-x c] + env["CPPPATH"] += glob("src/**") + env.Program("program.exe", glob("src/**/*.{c,yargh}")) end diff --git a/build_tests/typical/echo_command_ruby_builder.rb b/build_tests/typical/echo_command_ruby_builder.rb index bc9192e..1018edb 100644 --- a/build_tests/typical/echo_command_ruby_builder.rb +++ b/build_tests/typical/echo_command_ruby_builder.rb @@ -1,7 +1,4 @@ -default do - Environment.new do |env| - env.echo = :command - env.Copy("copy.rb", "echo_command_ruby_builder.rb") - end - +env do |env| + env.echo = :command + env.Copy("copy.rb", "echo_command_ruby_builder.rb") end diff --git a/build_tests/typical/echo_command_string.rb b/build_tests/typical/echo_command_string.rb index 76358ac..b9c837e 100644 --- a/build_tests/typical/echo_command_string.rb +++ b/build_tests/typical/echo_command_string.rb @@ -5,10 +5,8 @@ class MyBuilder < Rscons::Builder end end -default do - Environment.new do |env| - env.echo = :command - env.add_builder(MyBuilder) - env.MyBuilder("foo") - end +env do |env| + env.echo = :command + env.add_builder(MyBuilder) + env.MyBuilder("foo") end diff --git a/build_tests/typical/error_env_nontask.rb b/build_tests/typical/error_env_nontask.rb new file mode 100644 index 0000000..f892ebe --- /dev/null +++ b/build_tests/typical/error_env_nontask.rb @@ -0,0 +1 @@ +env(depends: "foo", task: false) diff --git a/build_tests/typical/error_env_option.rb b/build_tests/typical/error_env_option.rb new file mode 100644 index 0000000..59f4717 --- /dev/null +++ b/build_tests/typical/error_env_option.rb @@ -0,0 +1 @@ +env(foo: :bar) diff --git a/build_tests/typical/install.rb b/build_tests/typical/install.rb index 67fd0f1..525525e 100644 --- a/build_tests/typical/install.rb +++ b/build_tests/typical/install.rb @@ -1,13 +1,13 @@ project_name "install_test" -Environment.new do |env| +env do |env| env["CPPPATH"] += glob("src/**") task "build" do env.Program("^/program.exe", glob("src/**/*.c")) end - task "install", deps: "build" do + task "install", depends: "build" do env.InstallDirectory("${prefix}/bin") env.Install("${prefix}/bin", "^/program.exe") env.InstallDirectory("${prefix}/share") @@ -17,4 +17,4 @@ Environment.new do |env| end end -default(deps: "build") +default(depends: "build") diff --git a/build_tests/typical/multiple_environments.rb b/build_tests/typical/multiple_environments.rb index 83609d4..d429794 100644 --- a/build_tests/typical/multiple_environments.rb +++ b/build_tests/typical/multiple_environments.rb @@ -1,12 +1,10 @@ -default do - Environment.new do |env| - env["CPPPATH"] += glob("src/**") - env.Program("^/prog.exe", glob("src/**/*.c")) - end - - Environment.new do |env| - env["CPPPATH"] += glob("src/**") - env["CCFLAGS"] += %w[-Wall -g] - env.Program("^/prog-debug.exe", glob("src/**/*.c")) - end +env do |env| + env["CPPPATH"] += glob("src/**") + env.Program("^/prog.exe", glob("src/**/*.c")) +end + +env do |env| + env["CPPPATH"] += glob("src/**") + env["CCFLAGS"] += %w[-Wall -g] + env.Program("^/prog-debug.exe", glob("src/**/*.c")) end diff --git a/build_tests/typical/multiple_targets_same_name.rb b/build_tests/typical/multiple_targets_same_name.rb index 137822d..b560f32 100644 --- a/build_tests/typical/multiple_targets_same_name.rb +++ b/build_tests/typical/multiple_targets_same_name.rb @@ -1,7 +1,5 @@ -default do - 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 +env do |env| + env["CPPPATH"] << "src/two" + env.Object("one.o", "src/one/one.c") + env.Object("one.o", "src/two/two.c") end diff --git a/build_tests/typical/post_build_hook_expansion.rb b/build_tests/typical/post_build_hook_expansion.rb index 528e03c..1e6549d 100644 --- a/build_tests/typical/post_build_hook_expansion.rb +++ b/build_tests/typical/post_build_hook_expansion.rb @@ -1,12 +1,10 @@ -default do - Environment.new do |env| - env["CPPPATH"] << "src/two" - env.Object("one.o", "src/one/one.c") - env.add_post_build_hook do |builder| - if builder.target == "one.o" - env["MODULE"] = "two" - env.Object("${MODULE}.o", "src/${MODULE}/${MODULE}.c") - end +env do |env| + env["CPPPATH"] << "src/two" + env.Object("one.o", "src/one/one.c") + env.add_post_build_hook do |builder| + if builder.target == "one.o" + env["MODULE"] = "two" + env.Object("${MODULE}.o", "src/${MODULE}/${MODULE}.c") end end end diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index 33d8c9e..a9f6a73 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -39,15 +39,32 @@ module Rscons # # @api private # - # @param tasks [Array] + # @param rsconscript [String] + # Build script file name. + # @param tasks_and_params [Hash Hash String>>] # List of task(s) to execute. + # @param show_tasks [Boolean] + # Flag to show tasks and exit. # # @return [Integer] # Process exit code (0 on success). - def run(tasks) + def run(rsconscript, tasks_and_params, show_tasks) Cache.instance["failed_commands"] = [] - tasks.each do |task| - Task[task].check_execute + @script.load(rsconscript) + if show_tasks + show_script_tasks + return 0 + end + apply_task_params(tasks_and_params) + if tasks_and_params.empty? + check_process_environments + if Task.tasks["default"] + Task["default"].check_execute + end + else + tasks_and_params.each do |task_name, params| + Task[task_name].check_execute + end end 0 end @@ -111,6 +128,20 @@ module Rscons end end + # Check if environments need to be processed. + # + # @api private + # + # @return [void] + def check_process_environments + unless @_processed_environments + Environment[].each do |env| + env.process + end + @_processed_environments = true + end + end + # Configure the project. # # @api private @@ -158,6 +189,36 @@ module Rscons cache.write end + private + + def show_script_tasks + puts "Tasks:" + Task[].each do |task_name, task| + if task.description + puts %[ #{sprintf("%-27s", task_name)} #{task.description}] + task.params.each do |param_name, param| + arg_text = "--#{param_name}" + if param.takes_arg + arg_text += "=#{param_name.upcase}" + end + puts %[ #{sprintf("%-25s", "#{arg_text}")} #{param.description}] + end + end + end + end + + def apply_task_params(tasks_and_params) + tasks_and_params.each do |task_name, task_params| + task_params.each do |param_name, param_value| + if param = Task[task_name].params[param_name] + param.value = param_value + else + raise RsconsError.new("Unknown parameter #{param_name.inspect} for task #{task_name}") + end + end + end + end + end end diff --git a/lib/rscons/cli.rb b/lib/rscons/cli.rb index a5c9b9b..2af0580 100644 --- a/lib/rscons/cli.rb +++ b/lib/rscons/cli.rb @@ -28,41 +28,32 @@ module Rscons private def parse_task_params(task, argv) + task_params = {} while argv.size > 0 - if argv[0].start_with?("-") - valid_arg = false - if argv[0] =~ /^--(\S+?)(?:=(.*))?$/ - param_name, value = $1, $2 - if param = Task[task].params[param_name] - param.value = value || argv[0] - argv.slice!(0) - valid_arg = true - end - end - unless valid_arg - $stderr.puts "Invalid task '#{task}' argument '#{argv[0].split("=").first}'" - $stderr.puts usage - exit 2 - end + if argv[0] =~ /^--(\S+?)(?:=(.*))?$/ + param_name, param_value = $1, $2 + param_value ||= true + task_params[param_name] = param_value + argv.slice!(0) else - return + break end end + task_params end def parse_tasks_and_params(argv) - tasks = [] + tasks_and_params = {} while argv.size > 0 task = argv.shift - parse_task_params(task, argv) - tasks << task + tasks_and_params[task] = parse_task_params(task, argv) end - tasks + tasks_and_params end def run_toplevel(argv) rsconscript = nil - do_help = false + show_tasks = false OptionParser.new do |opts| @@ -80,7 +71,8 @@ module Rscons end opts.on("-h", "--help") do - do_help = true + puts usage + return 0 end opts.on("-j NTHREADS") do |n_threads| @@ -96,6 +88,10 @@ module Rscons end end + opts.on("-T", "--tasks") do + show_tasks = true + end + opts.on("-v", "--verbose") do Rscons.application.verbose = true end @@ -107,6 +103,9 @@ module Rscons end.order!(argv) + # Parse the rest of the command line. + tasks_and_params = parse_tasks_and_params(argv) + # Find the build script. if rsconscript unless File.exists?(rsconscript) @@ -119,40 +118,16 @@ module Rscons end end + # Anything else requires a build script, so complain if we didn't find + # one. + unless rsconscript + $stderr.puts "Could not find the Rsconscript to execute." + $stderr.puts "Looked for: #{DEFAULT_RSCONSCRIPTS.join(", ")}" + return 1 + end + begin - # Load the build script. - if rsconscript - Rscons.application.script.load(rsconscript) - end - - # Do help after loading the build script (if found) so that any - # script-defined tasks and task options can be displayed. - if do_help - puts usage - return 0 - end - - # Anything else requires a build script, so complain if we didn't find - # one. - unless rsconscript - $stderr.puts "Could not find the Rsconscript to execute." - $stderr.puts "Looked for: #{DEFAULT_RSCONSCRIPTS.join(", ")}" - return 1 - end - - # Parse the rest of the command line. This is done after loading the - # build script so that script-defined tasks and task options can be - # taken into account. - tasks = parse_tasks_and_params(argv) - - # If no user specified tasks, run "default" task. - if tasks.empty? - tasks << "default" - end - - # Finally, with the script fully loaded and command-line parsed, run - # the application to execute all required tasks. - Rscons.application.run(tasks) + Rscons.application.run(rsconscript, tasks_and_params, show_tasks) rescue RsconsError => e Ansi.write($stderr, :red, e.message, :reset, "\n") 1 @@ -160,7 +135,7 @@ module Rscons end def usage - usage = <] - # All Environments. - attr_reader :environments - # @return [Environment] # The Environment that is currently executing a construction block. - attr_accessor :open_environment + attr_accessor :running_environment # Initialize class instance variables. def class_init + @environments_by_name = {} @environments = [] end @@ -36,9 +33,24 @@ module Rscons # Register an Environment. def register(env) - @environments ||= [] @environments << env + if env.name + @environments_by_name[env.name] = env + end end + + # Get an Environment by name. + # + # @param name [String] + # Environment name. + def [](name = nil) + if name + @environments_by_name[name] + else + @environments + end + end + end # @return [Hash] Set of !{"builder_name" => builder_object} pairs. @@ -61,28 +73,36 @@ module Rscons # Create an Environment object. # + # @overload initialize(name, options) + # @overload initialize(options) + # + # @param name [String] + # Environment name. This determines the folder name used to store all + # environment build files under the top-level build directory. # @param options [Hash] # @option options [Symbol] :echo # :command, :short, or :off (default :short) # @option options [Boolean] :exclude_builders # Whether to omit adding default builders (default false) - # @option options [String, nil] :name - # Environment name. This determines the folder name used to store all - # environment build files under the top-level build directory. # @option options [String, Array] :use # Use flag(s). If specified, any configuration flags which were saved # with a corresponding `:use` value will be applied to this Environment. # # If a block is given, the Environment object is yielded to the block and # when the block returns, the {#process} method is automatically called. - def initialize(options = {}) + def initialize(*args, &block) + @id = self.class.get_id + if args.first.is_a?(String) + @name = args.slice!(0) + else + @name = "e.#{@id}" + end + options = args.first || {} Rscons.application.check_configure unless Cache.instance["configuration_data"]["configured"] raise "Project must be configured before creating an Environment" end super(options) - @id = self.class.get_id - self.class.register(self) # Hash of Thread object => {Command} or {Builder}. @threads = {} @registered_build_dependencies = {} @@ -109,15 +129,13 @@ module Rscons else :short end - @name = options[:name] || "e.#{@id}" @build_root = "#{Rscons.application.build_dir}/#{@name}" @n_threads = Rscons.application.n_threads - - if block_given? - Environment.open_environment = self - yield self - Environment.open_environment = nil - process + self.class.register(self) + if block + Environment.running_environment = self + block[self] + Environment.running_environment = nil end end @@ -140,7 +158,11 @@ module Rscons # Any options that #initialize receives can also be specified here. # # @return [Environment] The newly created {Environment} object. - def clone(options = {}) + def clone(*args, &block) + if args.first.is_a?(String) + name = args.slice!(0) + end + options = args.first || {} options = options.dup clone = options[:clone] || :all clone = Set[:variables, :builders, :build_hooks] if clone == :all @@ -148,7 +170,9 @@ module Rscons clone = Set.new(clone) if clone.is_a?(Array) clone.delete(:builders) if options[:exclude_builders] options[:echo] ||= @echo - env = self.class.new(options.merge(exclude_builders: true)) + new_args = name ? [name] : [] + new_args << options.merge(exclude_builders: true) + env = self.class.new(*new_args) if clone.include?(:builders) @builders.each do |builder_name, builder| env.add_builder(builder) @@ -164,12 +188,10 @@ module Rscons end end env.instance_variable_set(:@n_threads, @n_threads) - - if block_given? - Environment.open_environment = env - yield env - Environment.open_environment = nil - env.process + if block + Environment.running_environment = self + block[env] + Environment.running_environment = nil end env end diff --git a/lib/rscons/script.rb b/lib/rscons/script.rb index 5bd85db..876e26e 100644 --- a/lib/rscons/script.rb +++ b/lib/rscons/script.rb @@ -93,6 +93,11 @@ module Rscons end end + # Create an environment. + def env(*args, &block) + Environment.new(*args, &block) + end + # Construct a task parameter. # # @param name [String] @@ -235,13 +240,8 @@ module Rscons end # Create or modify a task. - def task(name, options = {}, &block) - if task = Task.tasks[name] - task.modify(options, &block) - else - task = Task.new(name, options, &block) - end - task + def task(*args, &block) + Util.task(*args, &block) end [ diff --git a/lib/rscons/task.rb b/lib/rscons/task.rb index 42da156..c1ebe1e 100644 --- a/lib/rscons/task.rb +++ b/lib/rscons/task.rb @@ -95,13 +95,9 @@ module Rscons # Whether to automatically configure before running this task. attr_reader :autoconf - # @return [Array] - # Task dependencies. - attr_reader :deps - # @return [String, nil] # Task description, if given. - attr_reader :desc + attr_reader :description # @return [String] # Task name. @@ -122,8 +118,8 @@ module Rscons # true). def initialize(name, options, &block) @autoconf = true - @deps = [] - @desc = nil + @dependencies = [] + @description = nil @name = name @params = {} @actions = [] @@ -153,9 +149,10 @@ module Rscons @executed = true if @autoconf Rscons.application.check_configure + Rscons.application.check_process_environments end - @deps.each do |dep| - Task[dep].check_execute + @dependencies.each do |dependency| + Task[dependency].check_execute end if @name == "configure" Rscons.application.configure @@ -193,10 +190,10 @@ module Rscons @autoconf = options[:autoconf] end if options.include?(:desc) - @desc = options[:desc] + @description = options[:desc] end - if options.include?(:deps) - @deps += Array(options[:deps]) + if options.include?(:depends) + @dependencies += Array(options[:depends]) end if options.include?(:params) Array(options[:params]).each do |param| @@ -204,7 +201,7 @@ module Rscons end end if block - if env = Environment.open_environment + if env = Environment.running_environment @actions << proc do block[] env.process diff --git a/lib/rscons/util.rb b/lib/rscons/util.rb index 89ec9bb..e394b78 100644 --- a/lib/rscons/util.rb +++ b/lib/rscons/util.rb @@ -191,6 +191,16 @@ module Rscons deps end + # Create or modify a task. + def task(name, options = {}, &block) + if task = Task.tasks[name] + task.modify(options, &block) + else + task = Task.new(name, options, &block) + end + task + end + # Wait for any of a number of threads to complete. # # @param threads [Array] diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 7bb34d4..96ba08e 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1095,6 +1095,15 @@ EOF expect(Dir.exist?("build/e.1")).to be_falsey end + it "allows looking up environments by name" do + test_dir "typical" + + result = run_rscons(args: %w[-f clone_with_lookup.rb]) + expect(File.exist?("build/typical/typical.exe")).to be_truthy + expect(File.exist?("build/typical/src/one/one.c.o")).to be_truthy + expect(Dir.exist?("build/first")).to be_falsey + end + context "colored output" do it "does not output in color with --color=off" do test_dir("simple") @@ -1774,8 +1783,7 @@ EOF test_dir "simple" result = run_rscons(args: %w[configure --xyz]) expect(result.stderr).to_not match /Traceback/ - expect(result.stderr).to match /Invalid task 'configure' argument.*--xyz/ - expect(result.stderr).to match /Usage:/ + expect(result.stderr).to match /Unknown parameter "xyz" for task configure/ expect(result.status).to_not eq 0 end end @@ -2890,7 +2898,7 @@ EOF result = run_rscons(args: %w[-f tasks.rb four --myparam=cli-value --myp2 one]) expect(result.stderr).to eq "" expect(result.status).to eq 0 - expect(result.stdout).to eq %[four\nmyparam:"cli-value"\nmyp2:"--myp2"\none\n] + expect(result.stdout).to eq %[four\nmyparam:"cli-value"\nmyp2:true\none\n] end it "allows accessing task arguments via Task#[]" do @@ -2914,20 +2922,22 @@ EOF expect(result.status).to_not eq 0 end - it "displays tasks and their arguments in the help info" do - test_dir "tasks" - result = run_rscons(args: %w[-f tasks.rb -h]) - expect(result.stderr).to eq "" - expect(result.status).to eq 0 - verify_lines(lines(result.stdout), [ - "Tasks:", - /\bthree\b\s+Task three/, - /\bfour\b\s+Task four/, - /--myparam=MYPARAM\s+My special parameter/, - /--myp2\s+My parameter 2/, - ]) - expect(result.stdout).to_not match /^\s*one\b/ - expect(result.stdout).to_not match /^\s*two\b/ + context "with -T flag" do + it "displays tasks and their parameters" do + test_dir "tasks" + result = run_rscons(args: %w[-f tasks.rb -T]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + verify_lines(lines(result.stdout), [ + "Tasks:", + /\bthree\b\s+Task three/, + /\bfour\b\s+Task four/, + /--myparam=MYPARAM\s+My special parameter/, + /--myp2\s+My parameter 2/, + ]) + expect(result.stdout).to_not match /^\s*one\b/ + expect(result.stdout).to_not match /^\s*two\b/ + end end context "download script method" do