From bd9cf55b85895a4230cc4656dd0628341485463c Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 30 Jan 2022 13:45:06 -0500 Subject: [PATCH] Add tasks - close #139 --- bin/rscons | 2 +- build_tests/cfile/Rsconscript | 2 +- build_tests/cfile/error_unknown_extension.rb | 2 +- build_tests/clone_env/Rsconscript | 2 +- build_tests/clone_env/clone_all.rb | 2 +- build_tests/configure/autoconf_fail.rb | 1 + build_tests/configure/autoconf_false.rb | 2 + build_tests/configure/autoconf_rebuild.rb | 2 +- build_tests/configure/check_c_compiler.rb | 1 + .../configure/check_c_header_cpppath.rb | 2 +- .../check_c_header_no_fail_set_define.rb | 2 +- .../check_c_header_success_set_define.rb | 2 +- build_tests/configure/check_cfg.rb | 2 +- build_tests/configure/check_cfg_package.rb | 2 +- build_tests/configure/check_cfg_use.rb | 2 +- .../configure/check_cxx_header_cpppath.rb | 2 +- .../configure/check_d_import_d_import_path.rb | 2 +- build_tests/configure/check_lib_libpath1.rb | 2 +- build_tests/configure/check_lib_libpath2.rb | 2 +- build_tests/configure/check_lib_success.rb | 2 +- build_tests/configure/check_lib_use.rb | 2 +- build_tests/configure/check_lib_use_false.rb | 2 +- build_tests/configure/custom_config_check.rb | 2 +- ...error_env_construction_before_configure.rb | 3 - build_tests/configure/multiple_set_define.rb | 2 +- build_tests/custom_builder/Rsconscript | 2 +- build_tests/custom_builder/build_after.rb | 2 +- build_tests/custom_builder/cvar_expansion.rb | 2 +- build_tests/custom_builder/cvar_lambda.rb | 2 +- .../custom_builder/error_run_return_value.rb | 2 +- build_tests/custom_builder/error_wait_for.rb | 2 +- .../custom_builder/multiple_targets.rb | 2 +- build_tests/custom_builder/produces.rb | 2 +- build_tests/custom_builder/produces_env.rb | 2 +- build_tests/custom_builder/wait_for_thread.rb | 2 +- build_tests/d/Rsconscript | 2 +- build_tests/d/build-ldc2.rb | 2 +- build_tests/d/link_objects.rb | 2 +- build_tests/direct/c_program.rb | 2 +- build_tests/direct/c_shared_library.rb | 2 +- build_tests/header/Rsconscript | 2 +- build_tests/json_to_yaml/Rsconscript | 2 +- build_tests/library/Rsconscript | 2 +- build_tests/library/library_from_object.rb | 2 +- build_tests/library/override_arcmd.rb | 2 +- build_tests/multiple_basename/Rsconscript | 2 +- build_tests/preprocess/Rsconscript | 2 +- build_tests/sh/sh.rb | 2 +- build_tests/sh/sh_fail.rb | 2 +- build_tests/sh/sh_fail_continue.rb | 2 +- build_tests/shared_library/Rsconscript | 2 +- .../shared_library/error_unknown_suffix.rb | 2 +- .../shared_library/shared_library_as.rb | 2 +- .../shared_library/shared_library_cxx.rb | 2 +- .../shared_library/shared_library_d.rb | 2 +- .../shared_library_from_object.rb | 2 +- .../shared_library/shared_library_set_shld.rb | 2 +- build_tests/simple/Rsconscript | 2 +- build_tests/simple/absolute_source_path.rb | 2 +- build_tests/simple/barrier.rb | 2 +- build_tests/simple/builder_as_source.rb | 2 +- build_tests/simple/builder_no_sources.rb | 2 +- .../simple/builder_wait_for_builder.rb | 2 +- build_tests/simple/cache_command_change.rb | 2 +- build_tests/simple/cache_debugging.rb | 12 +- .../simple/cache_dep_checksum_change.rb | 2 +- build_tests/simple/cache_new_dep1.rb | 2 +- build_tests/simple/cache_new_dep2.rb | 2 +- .../cache_successful_builds_when_one_fails.rb | 2 +- build_tests/simple/cache_user_dep.rb | 2 +- build_tests/simple/cache_varset.rb | 2 +- build_tests/simple/clear_targets.rb | 2 +- build_tests/simple/clone_n_threads.rb | 2 +- build_tests/simple/command.rb | 2 +- build_tests/simple/command_builder.rb | 2 +- build_tests/simple/command_redirect.rb | 2 +- build_tests/simple/cvar_array.rb | 2 +- build_tests/simple/directory.rb | 2 +- build_tests/simple/disassemble.rb | 2 +- build_tests/simple/distclean.rb | 2 +- build_tests/simple/dump.rb | 2 +- .../simple/error_circular_dependency.rb | 2 +- .../simple/error_circular_dependency2.rb | 2 +- .../error_produces_nonexistent_target.rb | 2 +- build_tests/simple/error_unknown_suffix.rb | 2 +- build_tests/simple/link_flag_change.rb | 2 +- build_tests/simple/override_cccmd.rb | 2 +- build_tests/simple/override_depfilesuffix.rb | 2 +- build_tests/simple/pathing.rb | 2 +- build_tests/simple/phony_target.rb | 2 +- build_tests/simple/preprocess.rb | 2 +- build_tests/simple/progsuffix.rb | 2 +- build_tests/simple/progsuffix2.rb | 2 +- build_tests/simple/progsuffix3.rb | 2 +- .../simple/register_target_in_build_hook.rb | 2 +- build_tests/simple/size.rb | 2 +- build_tests/simple/threading.rb | 2 +- build_tests/simple/user_dep_build_order.rb | 2 +- build_tests/simple/user_dependencies.rb | 2 +- build_tests/simple/user_dependencies_carat.rb | 2 +- .../simple/wait_for_builds_on_failure.rb | 2 +- build_tests/simple_cc/Rsconscript | 2 +- build_tests/simple_cc/cxxsuffix.rb | 2 +- build_tests/simple_cc/link_objects.rb | 2 +- build_tests/simple_cc/preprocess.rb | 2 +- build_tests/subsidiary/Rsconscript | 4 +- build_tests/subsidiary/Rsconscript_dir | 4 +- build_tests/subsidiary/Rsconscript_fail | 4 +- build_tests/subsidiary/Rsconscript_samedir | 4 +- build_tests/subsidiary/second | 2 +- build_tests/subsidiary/sub/Rsconscript | 2 +- build_tests/subsidiary/sub/Rsconscript2 | 2 +- build_tests/subsidiary/sub/Rsconscript_fail | 2 +- build_tests/tasks/tasks.rb | 28 + build_tests/two_sources/Rsconscript | 2 +- build_tests/two_sources/assuffix.rb | 2 +- build_tests/two_sources/cache_strict_deps.rb | 2 +- build_tests/two_sources/libsuffix.rb | 2 +- build_tests/two_sources/objsuffix.rb | 2 +- build_tests/typical/Rsconscript | 2 +- build_tests/typical/build_hooks.rb | 2 +- .../typical/build_hooks_override_vars.rb | 2 +- build_tests/typical/carat.rb | 2 +- build_tests/typical/clone_and_name.rb | 2 +- build_tests/typical/copy.rb | 2 +- build_tests/typical/copy_directory.rb | 2 +- build_tests/typical/copy_multiple.rb | 2 +- build_tests/typical/csuffix.rb | 2 +- .../typical/echo_command_ruby_builder.rb | 2 +- build_tests/typical/echo_command_string.rb | 2 +- build_tests/typical/fileutils_methods.rb | 2 +- build_tests/typical/install.rb | 12 +- build_tests/typical/multiple_environments.rb | 2 +- .../typical/multiple_targets_same_name.rb | 2 +- .../typical/post_build_hook_expansion.rb | 2 +- doc/user_guide.md | 641 +++++++++++----- lib/rscons.rb | 8 +- lib/rscons/application.rb | 180 ++--- lib/rscons/builder.rb | 8 - lib/rscons/builder_set.rb | 2 +- lib/rscons/builders/copy.rb | 85 +-- lib/rscons/builders/directory.rb | 27 +- lib/rscons/cli.rb | 264 +++---- lib/rscons/configure_op.rb | 25 +- lib/rscons/environment.rb | 41 +- lib/rscons/script.rb | 110 ++- lib/rscons/task.rb | 232 ++++++ rb/build_dist.rb | 2 +- spec/build_tests_spec.rb | 693 ++++++++++-------- 149 files changed, 1578 insertions(+), 1063 deletions(-) delete mode 100644 build_tests/configure/error_env_construction_before_configure.rb create mode 100644 build_tests/tasks/tasks.rb create mode 100644 lib/rscons/task.rb diff --git a/bin/rscons b/bin/rscons index d915827..f3b5d40 100755 --- a/bin/rscons +++ b/bin/rscons @@ -3,5 +3,5 @@ require "rscons/cli" if __FILE__ == $0 - Rscons::Cli.run(ARGV) + Rscons::Cli.new.run(ARGV) end diff --git a/build_tests/cfile/Rsconscript b/build_tests/cfile/Rsconscript index e383baa..96818d0 100644 --- a/build_tests/cfile/Rsconscript +++ b/build_tests/cfile/Rsconscript @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.CFile("lexer.c", "lexer.l") env.CFile("parser.c", "parser.y") diff --git a/build_tests/cfile/error_unknown_extension.rb b/build_tests/cfile/error_unknown_extension.rb index 05cceb7..af5b2b1 100644 --- a/build_tests/cfile/error_unknown_extension.rb +++ b/build_tests/cfile/error_unknown_extension.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.CFile("file.c", "foo.bar") end diff --git a/build_tests/clone_env/Rsconscript b/build_tests/clone_env/Rsconscript index 9df798d..fe88c89 100644 --- a/build_tests/clone_env/Rsconscript +++ b/build_tests/clone_env/Rsconscript @@ -1,4 +1,4 @@ -build do +default do debug = Environment.new(echo: :command) do |env| env['CFLAGS'] = '-O2' env['CPPFLAGS'] = '-DSTRING="Debug Version"' diff --git a/build_tests/clone_env/clone_all.rb b/build_tests/clone_env/clone_all.rb index 6da6e39..08eebd1 100644 --- a/build_tests/clone_env/clone_all.rb +++ b/build_tests/clone_env/clone_all.rb @@ -1,4 +1,4 @@ -build do +default do env1 = Environment.new(echo: :command) do |env| env['CFLAGS'] = '-O2' env.add_build_hook do |builder| diff --git a/build_tests/configure/autoconf_fail.rb b/build_tests/configure/autoconf_fail.rb index 6caedf6..d72e071 100644 --- a/build_tests/configure/autoconf_fail.rb +++ b/build_tests/configure/autoconf_fail.rb @@ -1,3 +1,4 @@ configure do check_c_compiler "nope.nope" end +default diff --git a/build_tests/configure/autoconf_false.rb b/build_tests/configure/autoconf_false.rb index d630ac1..6c81396 100644 --- a/build_tests/configure/autoconf_false.rb +++ b/build_tests/configure/autoconf_false.rb @@ -1 +1,3 @@ autoconf false +Environment.new do |env| +end diff --git a/build_tests/configure/autoconf_rebuild.rb b/build_tests/configure/autoconf_rebuild.rb index 381b6f1..38731d9 100644 --- a/build_tests/configure/autoconf_rebuild.rb +++ b/build_tests/configure/autoconf_rebuild.rb @@ -3,7 +3,7 @@ configure do check_c_header "stdio.h" end -build do +default do Environment.new do |env| env.Program("simple.exe", "simple.c") end diff --git a/build_tests/configure/check_c_compiler.rb b/build_tests/configure/check_c_compiler.rb index 44522a9..fcfcafc 100644 --- a/build_tests/configure/check_c_compiler.rb +++ b/build_tests/configure/check_c_compiler.rb @@ -1,3 +1,4 @@ configure do check_c_compiler end +default diff --git a/build_tests/configure/check_c_header_cpppath.rb b/build_tests/configure/check_c_header_cpppath.rb index c3fd28c..6e6cf72 100644 --- a/build_tests/configure/check_c_header_cpppath.rb +++ b/build_tests/configure/check_c_header_cpppath.rb @@ -3,7 +3,7 @@ configure do check_c_header "frobulous.h", check_cpppath: ["./usr2"] end -build do +default do Environment.new 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 79bb8ff..16a5f61 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,7 +2,7 @@ configure do check_c_header "not___found.h", set_define: "HAVE_NOT___FOUND_H" end -build do +default do Environment.new(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 8e82084..59a4b8c 100644 --- a/build_tests/configure/check_c_header_success_set_define.rb +++ b/build_tests/configure/check_c_header_success_set_define.rb @@ -2,7 +2,7 @@ configure do check_c_header "string.h", set_define: "HAVE_STRING_H" end -build do +default do Environment.new(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 4187ba0..fcf40e4 100644 --- a/build_tests/configure/check_cfg.rb +++ b/build_tests/configure/check_cfg.rb @@ -2,7 +2,7 @@ configure do check_cfg program: "my-config" end -build do +default do Environment.new(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 6b63385..26ccfde 100644 --- a/build_tests/configure/check_cfg_package.rb +++ b/build_tests/configure/check_cfg_package.rb @@ -2,7 +2,7 @@ configure do check_cfg package: "mypackage" end -build do +default do Environment.new(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 7403b76..1a7bb9f 100644 --- a/build_tests/configure/check_cfg_use.rb +++ b/build_tests/configure/check_cfg_use.rb @@ -2,7 +2,7 @@ configure do check_cfg package: "mypackage", use: "myp" end -build do +default do Environment.new(echo: :command) do |env| env.Copy("myconfigtest1.c", "simple.c") env.Program("myconfigtest1.exe", "myconfigtest1.c") diff --git a/build_tests/configure/check_cxx_header_cpppath.rb b/build_tests/configure/check_cxx_header_cpppath.rb index 242e919..5650389 100644 --- a/build_tests/configure/check_cxx_header_cpppath.rb +++ b/build_tests/configure/check_cxx_header_cpppath.rb @@ -3,7 +3,7 @@ configure do check_cxx_header "frobulous.h", check_cpppath: ["./usr2"] end -build do +default do Environment.new 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 58bb313..012a428 100644 --- a/build_tests/configure/check_d_import_d_import_path.rb +++ b/build_tests/configure/check_d_import_d_import_path.rb @@ -4,7 +4,7 @@ configure do check_d_import "frobulous", check_d_import_path: ["./usr2"] end -build do +default do Environment.new 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 c5897ce..2e6aa30 100644 --- a/build_tests/configure/check_lib_libpath1.rb +++ b/build_tests/configure/check_lib_libpath1.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new(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 c0998c2..96534ce 100644 --- a/build_tests/configure/check_lib_libpath2.rb +++ b/build_tests/configure/check_lib_libpath2.rb @@ -3,7 +3,7 @@ configure do check_lib "frobulous", check_libpath: ["./usr2"] end -build do +default do Environment.new(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 92dbe8a..ad5b7ae 100644 --- a/build_tests/configure/check_lib_success.rb +++ b/build_tests/configure/check_lib_success.rb @@ -2,7 +2,7 @@ configure do check_lib "m" end -build do +default do Environment.new(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 0638d41..d198332 100644 --- a/build_tests/configure/check_lib_use.rb +++ b/build_tests/configure/check_lib_use.rb @@ -2,7 +2,7 @@ configure do check_lib "m", use: :m end -build do +default do Environment.new(echo: :command) do |env| env.Copy("test1.c", "simple.c") env.Program("test2.exe", "test1.c") diff --git a/build_tests/configure/check_lib_use_false.rb b/build_tests/configure/check_lib_use_false.rb index 75f03ac..b9cf3bc 100644 --- a/build_tests/configure/check_lib_use_false.rb +++ b/build_tests/configure/check_lib_use_false.rb @@ -2,7 +2,7 @@ configure do check_lib "m", use: false end -build do +default do Environment.new(echo: :command) do |env| env.Copy("test1.c", "simple.c") env.Program("test2.exe", "test1.c") diff --git a/build_tests/configure/custom_config_check.rb b/build_tests/configure/custom_config_check.rb index a110626..487859a 100644 --- a/build_tests/configure/custom_config_check.rb +++ b/build_tests/configure/custom_config_check.rb @@ -23,7 +23,7 @@ configure do end end -build do +default do Environment.new do |env| puts env["CPPDEFINES"] end diff --git a/build_tests/configure/error_env_construction_before_configure.rb b/build_tests/configure/error_env_construction_before_configure.rb deleted file mode 100644 index 83e7703..0000000 --- a/build_tests/configure/error_env_construction_before_configure.rb +++ /dev/null @@ -1,3 +0,0 @@ -Environment.new do |env| - env.Object("simple.o", "simple.cc") -end diff --git a/build_tests/configure/multiple_set_define.rb b/build_tests/configure/multiple_set_define.rb index da7bf2f..eefedc8 100644 --- a/build_tests/configure/multiple_set_define.rb +++ b/build_tests/configure/multiple_set_define.rb @@ -3,7 +3,7 @@ configure do check_c_header "stdio.h", set_define: "HAVE_STDIO_H" end -build do +default do Environment.new(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 73e9a89..99a461c 100644 --- a/build_tests/custom_builder/Rsconscript +++ b/build_tests/custom_builder/Rsconscript @@ -9,7 +9,7 @@ EOF end end -build do +default do Environment.new do |env| env.add_builder(MySource) env.MySource('inc.h', []) diff --git a/build_tests/custom_builder/build_after.rb b/build_tests/custom_builder/build_after.rb index 3cbbad0..3c40645 100644 --- a/build_tests/custom_builder/build_after.rb +++ b/build_tests/custom_builder/build_after.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Command("inc.c", [], diff --git a/build_tests/custom_builder/cvar_expansion.rb b/build_tests/custom_builder/cvar_expansion.rb index ef8cc48..07f55aa 100644 --- a/build_tests/custom_builder/cvar_expansion.rb +++ b/build_tests/custom_builder/cvar_expansion.rb @@ -9,7 +9,7 @@ EOF end end -build do +default do env = Environment.new do |env| env["hdr"] = "inc.h" env["src"] = "program.c" diff --git a/build_tests/custom_builder/cvar_lambda.rb b/build_tests/custom_builder/cvar_lambda.rb index 33e341b..96affd7 100644 --- a/build_tests/custom_builder/cvar_lambda.rb +++ b/build_tests/custom_builder/cvar_lambda.rb @@ -9,7 +9,7 @@ EOF end end -build do +default do e1 = Environment.new do |env| env.add_builder(MySource) env["one"] = "5" diff --git a/build_tests/custom_builder/error_run_return_value.rb b/build_tests/custom_builder/error_run_return_value.rb index bae5ef7..6abd8ce 100644 --- a/build_tests/custom_builder/error_run_return_value.rb +++ b/build_tests/custom_builder/error_run_return_value.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.add_builder(:MyBuilder) do |options| "hi" diff --git a/build_tests/custom_builder/error_wait_for.rb b/build_tests/custom_builder/error_wait_for.rb index da93ec9..1fb605f 100644 --- a/build_tests/custom_builder/error_wait_for.rb +++ b/build_tests/custom_builder/error_wait_for.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.add_builder(:MyBuilder) do |options| wait_for(1) diff --git a/build_tests/custom_builder/multiple_targets.rb b/build_tests/custom_builder/multiple_targets.rb index 73267dd..292bb2e 100644 --- a/build_tests/custom_builder/multiple_targets.rb +++ b/build_tests/custom_builder/multiple_targets.rb @@ -12,7 +12,7 @@ class CHGen < Rscons::Builder end end -build do +default do Environment.new do |env| env.add_builder(CHGen) env.CHGen("inc.c", ["program.c"]) diff --git a/build_tests/custom_builder/produces.rb b/build_tests/custom_builder/produces.rb index 98e9c4c..552b94c 100644 --- a/build_tests/custom_builder/produces.rb +++ b/build_tests/custom_builder/produces.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["build_root"] = env.build_root env["inc_h"] = "inc.h" diff --git a/build_tests/custom_builder/produces_env.rb b/build_tests/custom_builder/produces_env.rb index 9bd9a64..727f66e 100644 --- a/build_tests/custom_builder/produces_env.rb +++ b/build_tests/custom_builder/produces_env.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["build_root"] = env.build_root env["inc_h"] = "inc.h" diff --git a/build_tests/custom_builder/wait_for_thread.rb b/build_tests/custom_builder/wait_for_thread.rb index ffb422f..dbfb2c1 100644 --- a/build_tests/custom_builder/wait_for_thread.rb +++ b/build_tests/custom_builder/wait_for_thread.rb @@ -13,7 +13,7 @@ class MyBuilder < Rscons::Builder end end -build do +default do Environment.new do |env| env.add_builder(MyBuilder) env.MyBuilder("foo") diff --git a/build_tests/d/Rsconscript b/build_tests/d/Rsconscript index 0a9e126..046b8b5 100644 --- a/build_tests/d/Rsconscript +++ b/build_tests/d/Rsconscript @@ -2,7 +2,7 @@ configure do check_d_compiler "gdc" end -build do +default do Environment.new(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 0d1c7a5..a435d40 100644 --- a/build_tests/d/build-ldc2.rb +++ b/build_tests/d/build-ldc2.rb @@ -2,7 +2,7 @@ configure do check_d_compiler "ldc2" end -build do +default do Environment.new(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 0b8178b..69fba89 100644 --- a/build_tests/d/link_objects.rb +++ b/build_tests/d/link_objects.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new(echo: :command) do |env| env.Object("main.o", "main.d") env.Object("mod.o", "mod.d") diff --git a/build_tests/direct/c_program.rb b/build_tests/direct/c_program.rb index cddff17..ffcfe82 100644 --- a/build_tests/direct/c_program.rb +++ b/build_tests/direct/c_program.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new 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 12d5c94..fa257b2 100644 --- a/build_tests/direct/c_shared_library.rb +++ b/build_tests/direct/c_shared_library.rb @@ -1,4 +1,4 @@ -build do +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" => ["."]) diff --git a/build_tests/header/Rsconscript b/build_tests/header/Rsconscript index 27fb446..d3dbd70 100644 --- a/build_tests/header/Rsconscript +++ b/build_tests/header/Rsconscript @@ -1,4 +1,4 @@ -build do +default do Environment.new 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 f1bba01..f3e3a31 100644 --- a/build_tests/json_to_yaml/Rsconscript +++ b/build_tests/json_to_yaml/Rsconscript @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| require 'json' require 'yaml' diff --git a/build_tests/library/Rsconscript b/build_tests/library/Rsconscript index c6a8df5..b0bc5fd 100644 --- a/build_tests/library/Rsconscript +++ b/build_tests/library/Rsconscript @@ -1,4 +1,4 @@ -build do +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']) diff --git a/build_tests/library/library_from_object.rb b/build_tests/library/library_from_object.rb index 367203d..fe39fa4 100644 --- a/build_tests/library/library_from_object.rb +++ b/build_tests/library/library_from_object.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Program("library.exe", ["lib.a", "three.c"]) env.Object("two.o", "two.c") diff --git a/build_tests/library/override_arcmd.rb b/build_tests/library/override_arcmd.rb index f14f9d8..efa72cf 100644 --- a/build_tests/library/override_arcmd.rb +++ b/build_tests/library/override_arcmd.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new(echo: :command) do |env| env["ARCMD"] = %w[ar rcf ${_TARGET} ${_SOURCES}] env.Library("lib.a", glob("*.c")) diff --git a/build_tests/multiple_basename/Rsconscript b/build_tests/multiple_basename/Rsconscript index ad7f7b8..c35302f 100644 --- a/build_tests/multiple_basename/Rsconscript +++ b/build_tests/multiple_basename/Rsconscript @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Program("foo.exe", glob("*.cc", "*.c")) end diff --git a/build_tests/preprocess/Rsconscript b/build_tests/preprocess/Rsconscript index 020419a..793d6d3 100644 --- a/build_tests/preprocess/Rsconscript +++ b/build_tests/preprocess/Rsconscript @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Preprocess("pp", "foo.h") end diff --git a/build_tests/sh/sh.rb b/build_tests/sh/sh.rb index 90b2082..59704e1 100644 --- a/build_tests/sh/sh.rb +++ b/build_tests/sh/sh.rb @@ -1,4 +1,4 @@ -build do +default do sh "echo", "hi there" sh(["echo 1 2"]) end diff --git a/build_tests/sh/sh_fail.rb b/build_tests/sh/sh_fail.rb index 230c2dd..e3052e4 100644 --- a/build_tests/sh/sh_fail.rb +++ b/build_tests/sh/sh_fail.rb @@ -1,4 +1,4 @@ -build do +default do sh "foobar42" sh "echo", "continued" end diff --git a/build_tests/sh/sh_fail_continue.rb b/build_tests/sh/sh_fail_continue.rb index b5c25bd..dd9724d 100644 --- a/build_tests/sh/sh_fail_continue.rb +++ b/build_tests/sh/sh_fail_continue.rb @@ -1,4 +1,4 @@ -build do +default do sh "foobar42", continue: true sh "echo", "continued" end diff --git a/build_tests/shared_library/Rsconscript b/build_tests/shared_library/Rsconscript index 746d1cc..1e46959 100644 --- a/build_tests/shared_library/Rsconscript +++ b/build_tests/shared_library/Rsconscript @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["CPPPATH"] << "src/lib" libmine = env.SharedLibrary("mine", glob("src/lib/*.c")) diff --git a/build_tests/shared_library/error_unknown_suffix.rb b/build_tests/shared_library/error_unknown_suffix.rb index 3552069..49dfb09 100644 --- a/build_tests/shared_library/error_unknown_suffix.rb +++ b/build_tests/shared_library/error_unknown_suffix.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| File.open("foo.xyz", "wb") do |fh| fh.puts("hi") diff --git a/build_tests/shared_library/shared_library_as.rb b/build_tests/shared_library/shared_library_as.rb index c24f4a5..7b54422 100644 --- a/build_tests/shared_library/shared_library_as.rb +++ b/build_tests/shared_library/shared_library_as.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["CPPPATH"] << "src/lib" env.Object("file.S", "src/lib/one.c", "CFLAGS" => env["CFLAGS"] + ["-S"]) diff --git a/build_tests/shared_library/shared_library_cxx.rb b/build_tests/shared_library/shared_library_cxx.rb index c148ac3..97f5c5d 100644 --- a/build_tests/shared_library/shared_library_cxx.rb +++ b/build_tests/shared_library/shared_library_cxx.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["CPPPATH"] << "src/lib" libmine = env.SharedLibrary("mine", glob("src/lib/*.cc")) diff --git a/build_tests/shared_library/shared_library_d.rb b/build_tests/shared_library/shared_library_d.rb index 50e5a93..36c6352 100644 --- a/build_tests/shared_library/shared_library_d.rb +++ b/build_tests/shared_library/shared_library_d.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["CPPPATH"] << "src/lib" libmine = env.SharedLibrary("mine", glob("src/lib/*.d")) diff --git a/build_tests/shared_library/shared_library_from_object.rb b/build_tests/shared_library/shared_library_from_object.rb index 1322b96..9df7d4d 100644 --- a/build_tests/shared_library/shared_library_from_object.rb +++ b/build_tests/shared_library/shared_library_from_object.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["CPPPATH"] << "src/lib" env.SharedObject("one.o", "src/lib/one.c") diff --git a/build_tests/shared_library/shared_library_set_shld.rb b/build_tests/shared_library/shared_library_set_shld.rb index 3c44570..54d7a3e 100644 --- a/build_tests/shared_library/shared_library_set_shld.rb +++ b/build_tests/shared_library/shared_library_set_shld.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["CPPPATH"] << "src/lib" env["SHLD"] = "gcc" diff --git a/build_tests/simple/Rsconscript b/build_tests/simple/Rsconscript index b679de6..d80cb69 100644 --- a/build_tests/simple/Rsconscript +++ b/build_tests/simple/Rsconscript @@ -1,4 +1,4 @@ -build do +default do Environment.new 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 3358796..08d8b5c 100644 --- a/build_tests/simple/absolute_source_path.rb +++ b/build_tests/simple/absolute_source_path.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new(echo: :command) do |env| tempdir = ENV["TEMP"] || ENV["TMP"] || "/tmp" source_file = File.join(tempdir, "abs.c") diff --git a/build_tests/simple/barrier.rb b/build_tests/simple/barrier.rb index 2be4b6e..aed2974 100644 --- a/build_tests/simple/barrier.rb +++ b/build_tests/simple/barrier.rb @@ -10,7 +10,7 @@ class ThreadedTestBuilder < Rscons::Builder end end -build do +default do Environment.new do |env| env.add_builder(ThreadedTestBuilder) env.ThreadedTestBuilder("T3", [], "delay" => 3) diff --git a/build_tests/simple/builder_as_source.rb b/build_tests/simple/builder_as_source.rb index 953fcad..46a7a41 100644 --- a/build_tests/simple/builder_as_source.rb +++ b/build_tests/simple/builder_as_source.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| object = env.Object("simple.o", "simple.c") env.Program("simple.exe", object) diff --git a/build_tests/simple/builder_no_sources.rb b/build_tests/simple/builder_no_sources.rb index 4c3b7c1..16c4fe8 100644 --- a/build_tests/simple/builder_no_sources.rb +++ b/build_tests/simple/builder_no_sources.rb @@ -3,7 +3,7 @@ class TestBuilder < Rscons::Builder true end end -build do +default do Environment.new do |env| env.add_builder(TestBuilder) env.TestBuilder("file") diff --git a/build_tests/simple/builder_wait_for_builder.rb b/build_tests/simple/builder_wait_for_builder.rb index 5266987..c0cc255 100644 --- a/build_tests/simple/builder_wait_for_builder.rb +++ b/build_tests/simple/builder_wait_for_builder.rb @@ -14,7 +14,7 @@ class MyObject < Rscons::Builder end end -build do +default do Environment.new do |env| env.add_builder(MyObject) env.MyObject("simple.o", "simple.c") diff --git a/build_tests/simple/cache_command_change.rb b/build_tests/simple/cache_command_change.rb index 7a00743..d39ea04 100644 --- a/build_tests/simple/cache_command_change.rb +++ b/build_tests/simple/cache_command_change.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["LIBS"] += ["m"] env.Program('simple.exe', Dir['*.c']) diff --git a/build_tests/simple/cache_debugging.rb b/build_tests/simple/cache_debugging.rb index df58ff3..77a381d 100644 --- a/build_tests/simple/cache_debugging.rb +++ b/build_tests/simple/cache_debugging.rb @@ -4,17 +4,17 @@ class DebugBuilder < Rscons::Builder finalize_command else @command = %W[gcc -c -o #{@target} #{@sources.first}] - if Rscons.vars["command_change"] + if ENV["test"] == "command_change" @command += %w[-Wall] end - if Rscons.vars["new_dep"] + if ENV["test"] == "new_dep" @sources += ["extra"] end - if Rscons.vars["strict_deps1"] + if ENV["test"] == "strict_deps1" @sources += ["extra"] strict_deps = true end - if Rscons.vars["strict_deps2"] + if ENV["test"] == "strict_deps2" @sources = ["extra"] + @sources strict_deps = true end @@ -27,10 +27,10 @@ class DebugBuilder < Rscons::Builder end end -build do +default do Environment.new do |env| env.add_builder(DebugBuilder) - if Rscons.vars["new_user_dep"] + if ENV["test"] == "new_user_dep" env.depends("foo.o", "new_dep") end env.DebugBuilder("foo.o", "simple.c") diff --git a/build_tests/simple/cache_dep_checksum_change.rb b/build_tests/simple/cache_dep_checksum_change.rb index 2328628..6ac75b7 100644 --- a/build_tests/simple/cache_dep_checksum_change.rb +++ b/build_tests/simple/cache_dep_checksum_change.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new 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 f9e45c4..381d5ec 100644 --- a/build_tests/simple/cache_new_dep1.rb +++ b/build_tests/simple/cache_new_dep1.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Object("simple.o", "simple.c") env.process diff --git a/build_tests/simple/cache_new_dep2.rb b/build_tests/simple/cache_new_dep2.rb index b3467d5..d21029f 100644 --- a/build_tests/simple/cache_new_dep2.rb +++ b/build_tests/simple/cache_new_dep2.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Object("simple.o", "simple.c") env["LDCMD"] = %w[gcc -o ${_TARGET} simple.o] 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 3213e69..f7a700a 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,4 @@ -build do +default do Environment.new do |env| env.Object("simple.o", "simple.c") env.Object("two.o", "two.c") diff --git a/build_tests/simple/cache_user_dep.rb b/build_tests/simple/cache_user_dep.rb index 85f60c6..4ba98f1 100644 --- a/build_tests/simple/cache_user_dep.rb +++ b/build_tests/simple/cache_user_dep.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| target = env.Program("simple.exe", "simple.c") user_deps = File.read("user_deps", mode: "rb").split(" ") diff --git a/build_tests/simple/cache_varset.rb b/build_tests/simple/cache_varset.rb index 5a4bde9..85b8c77 100644 --- a/build_tests/simple/cache_varset.rb +++ b/build_tests/simple/cache_varset.rb @@ -13,7 +13,7 @@ class TestBuilder < Rscons::Builder end end -build do +default do Environment.new do |env| env.add_builder(TestBuilder) env.TestBuilder("foo") diff --git a/build_tests/simple/clear_targets.rb b/build_tests/simple/clear_targets.rb index dbacdf4..101fb47 100644 --- a/build_tests/simple/clear_targets.rb +++ b/build_tests/simple/clear_targets.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Program("simple.exe", "simple.c") env.clear_targets diff --git a/build_tests/simple/clone_n_threads.rb b/build_tests/simple/clone_n_threads.rb index 2b6b5fc..17e7f09 100644 --- a/build_tests/simple/clone_n_threads.rb +++ b/build_tests/simple/clone_n_threads.rb @@ -1,4 +1,4 @@ -build do +default do base_env = Environment.new do |env| env.n_threads = 165 end diff --git a/build_tests/simple/command.rb b/build_tests/simple/command.rb index d9f1d18..cfa2c81 100644 --- a/build_tests/simple/command.rb +++ b/build_tests/simple/command.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new(echo: :command) do |env| env["LD"] = "gcc" env.Program('simple.exe', Dir['*.c']) diff --git a/build_tests/simple/command_builder.rb b/build_tests/simple/command_builder.rb index 1530f1b..c9bbe50 100644 --- a/build_tests/simple/command_builder.rb +++ b/build_tests/simple/command_builder.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| command = %W[gcc -o ${_TARGET} ${_SOURCES}] env.Command("simple.exe", diff --git a/build_tests/simple/command_redirect.rb b/build_tests/simple/command_redirect.rb index 6ce5f05..fe201cb 100644 --- a/build_tests/simple/command_redirect.rb +++ b/build_tests/simple/command_redirect.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Object("simple.o", "simple.c") env.Command("simple.txt", diff --git a/build_tests/simple/cvar_array.rb b/build_tests/simple/cvar_array.rb index f27fc45..3335f5a 100644 --- a/build_tests/simple/cvar_array.rb +++ b/build_tests/simple/cvar_array.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["sources"] = glob("*.c") env.Program("simple.exe", "${sources}") diff --git a/build_tests/simple/directory.rb b/build_tests/simple/directory.rb index bcafece..d6b6659 100644 --- a/build_tests/simple/directory.rb +++ b/build_tests/simple/directory.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Directory("teh_dir") end diff --git a/build_tests/simple/disassemble.rb b/build_tests/simple/disassemble.rb index 3c5e8c2..743bdc9 100644 --- a/build_tests/simple/disassemble.rb +++ b/build_tests/simple/disassemble.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Object("simple.o", "simple.c") env.Disassemble("simple.txt", "simple.o") diff --git a/build_tests/simple/distclean.rb b/build_tests/simple/distclean.rb index 7cdfc1c..f353e3e 100644 --- a/build_tests/simple/distclean.rb +++ b/build_tests/simple/distclean.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Object("simple.o", "simple.c") end diff --git a/build_tests/simple/dump.rb b/build_tests/simple/dump.rb index 959f168..eab53ce 100644 --- a/build_tests/simple/dump.rb +++ b/build_tests/simple/dump.rb @@ -1,4 +1,4 @@ -build do +default do env = Environment.new do |env| env["CFLAGS"] += %w[-O2 -fomit-frame-pointer] env[:foo] = :bar diff --git a/build_tests/simple/error_circular_dependency.rb b/build_tests/simple/error_circular_dependency.rb index 4684d31..a579a3c 100644 --- a/build_tests/simple/error_circular_dependency.rb +++ b/build_tests/simple/error_circular_dependency.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Command("foo", "bar") env.Command("bar", "baz") diff --git a/build_tests/simple/error_circular_dependency2.rb b/build_tests/simple/error_circular_dependency2.rb index 997f053..3d3e6c9 100644 --- a/build_tests/simple/error_circular_dependency2.rb +++ b/build_tests/simple/error_circular_dependency2.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new 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 2a35557..5d246e3 100644 --- a/build_tests/simple/error_produces_nonexistent_target.rb +++ b/build_tests/simple/error_produces_nonexistent_target.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new 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 76f3657..bd1817d 100644 --- a/build_tests/simple/error_unknown_suffix.rb +++ b/build_tests/simple/error_unknown_suffix.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| File.open("foo.xyz", "wb") do |fh| fh.puts("hi") diff --git a/build_tests/simple/link_flag_change.rb b/build_tests/simple/link_flag_change.rb index 5e9a752..bae47f5 100644 --- a/build_tests/simple/link_flag_change.rb +++ b/build_tests/simple/link_flag_change.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new(echo: :command) do |env| env["LD"] = "gcc" env["LIBPATH"] += ["libdir"] diff --git a/build_tests/simple/override_cccmd.rb b/build_tests/simple/override_cccmd.rb index 767b943..59cbd93 100644 --- a/build_tests/simple/override_cccmd.rb +++ b/build_tests/simple/override_cccmd.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new(echo: :command) do |env| env.Object("simple.o", "simple.c", "CCCMD" => %w[${CC} -c -o ${_TARGET} -Dfoobar ${_SOURCES}]) diff --git a/build_tests/simple/override_depfilesuffix.rb b/build_tests/simple/override_depfilesuffix.rb index 4cedf4c..80e1b25 100644 --- a/build_tests/simple/override_depfilesuffix.rb +++ b/build_tests/simple/override_depfilesuffix.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new(echo: :command) do |env| env["DEPFILESUFFIX"] = ".deppy" env.Object("simple.o", "simple.c") diff --git a/build_tests/simple/pathing.rb b/build_tests/simple/pathing.rb index 47a8039..58f7c55 100644 --- a/build_tests/simple/pathing.rb +++ b/build_tests/simple/pathing.rb @@ -1,7 +1,7 @@ path_prepend "path_prepend" path_append "path_append" -build do +default do Environment.new do |env| system("flex") system("foobar") diff --git a/build_tests/simple/phony_target.rb b/build_tests/simple/phony_target.rb index 4263a7c..77484c7 100644 --- a/build_tests/simple/phony_target.rb +++ b/build_tests/simple/phony_target.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.add_builder(:Checker) do |params| unless @cache.up_to_date?(@target, :Checker, @sources, @env) diff --git a/build_tests/simple/preprocess.rb b/build_tests/simple/preprocess.rb index 9e6191d..030ab4c 100644 --- a/build_tests/simple/preprocess.rb +++ b/build_tests/simple/preprocess.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Preprocess("simplepp.c", "simple.c") env.Program("simple.exe", "simplepp.c") diff --git a/build_tests/simple/progsuffix.rb b/build_tests/simple/progsuffix.rb index 29ad125..6bec0d0 100644 --- a/build_tests/simple/progsuffix.rb +++ b/build_tests/simple/progsuffix.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["PROGSUFFIX"] = ".out" env.Program("simple", Dir["*.c"]) diff --git a/build_tests/simple/progsuffix2.rb b/build_tests/simple/progsuffix2.rb index e1ca8e4..7e9788d 100644 --- a/build_tests/simple/progsuffix2.rb +++ b/build_tests/simple/progsuffix2.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["MYSUFFIX"] = ".out" env.Program("simple${MYSUFFIX}", Dir["*.c"]) diff --git a/build_tests/simple/progsuffix3.rb b/build_tests/simple/progsuffix3.rb index 91ff076..6aed2cf 100644 --- a/build_tests/simple/progsuffix3.rb +++ b/build_tests/simple/progsuffix3.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new 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 6366a98..0ad4ee4 100644 --- a/build_tests/simple/register_target_in_build_hook.rb +++ b/build_tests/simple/register_target_in_build_hook.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Program("simple.exe", Dir["*.c"]) env.add_build_hook do |builder| diff --git a/build_tests/simple/size.rb b/build_tests/simple/size.rb index cf978f0..bfa4efa 100644 --- a/build_tests/simple/size.rb +++ b/build_tests/simple/size.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Program("simple.exe", glob("*.c")) env.Size("simple.size", "simple.exe") diff --git a/build_tests/simple/threading.rb b/build_tests/simple/threading.rb index 65f88a4..f42d3db 100644 --- a/build_tests/simple/threading.rb +++ b/build_tests/simple/threading.rb @@ -17,7 +17,7 @@ class NonThreadedTestBuilder < Rscons::Builder end end -build do +default do Environment.new do |env| env.add_builder(ThreadedTestBuilder) env.add_builder(NonThreadedTestBuilder) diff --git a/build_tests/simple/user_dep_build_order.rb b/build_tests/simple/user_dep_build_order.rb index 1fe62ac..43965f4 100644 --- a/build_tests/simple/user_dep_build_order.rb +++ b/build_tests/simple/user_dep_build_order.rb @@ -13,7 +13,7 @@ class TestBuilder < Rscons::Builder end end -build do +default do Environment.new do |env| env.add_builder(TestBuilder) one = env.TestBuilder("one", [], "wait_time" => "3") diff --git a/build_tests/simple/user_dependencies.rb b/build_tests/simple/user_dependencies.rb index 63537e3..04ae089 100644 --- a/build_tests/simple/user_dependencies.rb +++ b/build_tests/simple/user_dependencies.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| program = env.Program("simple.exe", Dir["*.c"]) env.depends(program, "program.ld") diff --git a/build_tests/simple/user_dependencies_carat.rb b/build_tests/simple/user_dependencies_carat.rb index 0e08f2d..dddf9da 100644 --- a/build_tests/simple/user_dependencies_carat.rb +++ b/build_tests/simple/user_dependencies_carat.rb @@ -8,7 +8,7 @@ class FileBuilder < Builder true end end -build do +default do Environment.new do |env| env.add_builder(FileBuilder) env.File("^/file.txt") diff --git a/build_tests/simple/wait_for_builds_on_failure.rb b/build_tests/simple/wait_for_builds_on_failure.rb index 7e8025b..c491d64 100644 --- a/build_tests/simple/wait_for_builds_on_failure.rb +++ b/build_tests/simple/wait_for_builds_on_failure.rb @@ -11,7 +11,7 @@ class Fail < Rscons::Builder end end -build do +default do Environment.new do |env| env.add_builder(Fail) 4.times do |i| diff --git a/build_tests/simple_cc/Rsconscript b/build_tests/simple_cc/Rsconscript index 2bd2d8a..bd0600e 100644 --- a/build_tests/simple_cc/Rsconscript +++ b/build_tests/simple_cc/Rsconscript @@ -1,4 +1,4 @@ -build do +default do Environment.new 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 8b3e3c1..a6659af 100644 --- a/build_tests/simple_cc/cxxsuffix.rb +++ b/build_tests/simple_cc/cxxsuffix.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["CXXSUFFIX"] = %w[.cccc .cc] env["CXXFLAGS"] += %w[-x c++] diff --git a/build_tests/simple_cc/link_objects.rb b/build_tests/simple_cc/link_objects.rb index 9173eba..8eccca2 100644 --- a/build_tests/simple_cc/link_objects.rb +++ b/build_tests/simple_cc/link_objects.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Object("simple.o", "simple.cc") env.Program("simple.exe", "simple.o") diff --git a/build_tests/simple_cc/preprocess.rb b/build_tests/simple_cc/preprocess.rb index 1d2100d..ac18dca 100644 --- a/build_tests/simple_cc/preprocess.rb +++ b/build_tests/simple_cc/preprocess.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Preprocess("simplepp.cc", "simple.cc") env.Program("simple.exe", "simplepp.cc") diff --git a/build_tests/subsidiary/Rsconscript b/build_tests/subsidiary/Rsconscript index 2d402d5..37e8129 100644 --- a/build_tests/subsidiary/Rsconscript +++ b/build_tests/subsidiary/Rsconscript @@ -4,7 +4,7 @@ configure do puts "top configure" end -build do - rscons "sub/Rsconscript2", "build" +default do + rscons "sub/Rsconscript2" puts "top build" end diff --git a/build_tests/subsidiary/Rsconscript_dir b/build_tests/subsidiary/Rsconscript_dir index e149536..ed5236c 100644 --- a/build_tests/subsidiary/Rsconscript_dir +++ b/build_tests/subsidiary/Rsconscript_dir @@ -4,7 +4,7 @@ configure do puts "top configure" end -build do - rscons "sub", "-f", "Rsconscript2", "build" +default do + rscons "sub", "-f", "Rsconscript2" puts "top build" end diff --git a/build_tests/subsidiary/Rsconscript_fail b/build_tests/subsidiary/Rsconscript_fail index 26a7dc2..6ffea77 100644 --- a/build_tests/subsidiary/Rsconscript_fail +++ b/build_tests/subsidiary/Rsconscript_fail @@ -3,7 +3,7 @@ configure do puts "top configure" end -build do - rscons "sub/Rsconscript2", "build" +default do + rscons "sub/Rsconscript2" puts "top build" end diff --git a/build_tests/subsidiary/Rsconscript_samedir b/build_tests/subsidiary/Rsconscript_samedir index 1ff8f9d..e817523 100644 --- a/build_tests/subsidiary/Rsconscript_samedir +++ b/build_tests/subsidiary/Rsconscript_samedir @@ -1,4 +1,4 @@ -build do - rscons "second", "build" +default do + rscons "second", "default" puts "top build" end diff --git a/build_tests/subsidiary/second b/build_tests/subsidiary/second index 33c102b..9896dcb 100644 --- a/build_tests/subsidiary/second +++ b/build_tests/subsidiary/second @@ -1,3 +1,3 @@ -build do +default do puts "second build" end diff --git a/build_tests/subsidiary/sub/Rsconscript b/build_tests/subsidiary/sub/Rsconscript index 93ee01b..742e699 100644 --- a/build_tests/subsidiary/sub/Rsconscript +++ b/build_tests/subsidiary/sub/Rsconscript @@ -2,6 +2,6 @@ configure do puts "sub Rsconscript configure" end -build do +default do puts "sub Rsconscript build" end diff --git a/build_tests/subsidiary/sub/Rsconscript2 b/build_tests/subsidiary/sub/Rsconscript2 index d201857..2ea32d4 100644 --- a/build_tests/subsidiary/sub/Rsconscript2 +++ b/build_tests/subsidiary/sub/Rsconscript2 @@ -2,6 +2,6 @@ configure do puts "sub Rsconscript2 configure" end -build do +default do puts "sub Rsconscript2 build" end diff --git a/build_tests/subsidiary/sub/Rsconscript_fail b/build_tests/subsidiary/sub/Rsconscript_fail index baae3c9..b680bfe 100644 --- a/build_tests/subsidiary/sub/Rsconscript_fail +++ b/build_tests/subsidiary/sub/Rsconscript_fail @@ -3,6 +3,6 @@ configure do check_program "foobarfailure" end -build do +default do puts "sub Rsconscript build" end diff --git a/build_tests/tasks/tasks.rb b/build_tests/tasks/tasks.rb new file mode 100644 index 0000000..dc2e3ec --- /dev/null +++ b/build_tests/tasks/tasks.rb @@ -0,0 +1,28 @@ +task "one" do + puts "one" +end + +task "two", deps: ["one", "three"] do + puts "two" +end + +task "three", desc: "Task three" do + puts "three" +end + +task "four", desc: "Task four", params: [ + param("myparam", "defaultvalue", true, "My special parameter"), + param("myp2", nil, false, "My parameter 2"), +] do |task, params| + puts "four" + puts "myparam:" + params["myparam"].inspect + puts "myp2:" + params["myp2"].inspect +end + +task "five" do + puts "four myparam value is #{Task["four"]["myparam"]}" +end + +task "six" do |task| + puts task["nope"] +end diff --git a/build_tests/two_sources/Rsconscript b/build_tests/two_sources/Rsconscript index 34db499..f2baeee 100644 --- a/build_tests/two_sources/Rsconscript +++ b/build_tests/two_sources/Rsconscript @@ -1,4 +1,4 @@ -build do +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']) diff --git a/build_tests/two_sources/assuffix.rb b/build_tests/two_sources/assuffix.rb index e3959bd..2a57161 100644 --- a/build_tests/two_sources/assuffix.rb +++ b/build_tests/two_sources/assuffix.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["ASSUFFIX"] = %w[.ssss .sss] env["CFLAGS"] += %w[-S] diff --git a/build_tests/two_sources/cache_strict_deps.rb b/build_tests/two_sources/cache_strict_deps.rb index 045d45e..b052497 100644 --- a/build_tests/two_sources/cache_strict_deps.rb +++ b/build_tests/two_sources/cache_strict_deps.rb @@ -13,7 +13,7 @@ class StrictBuilder < Rscons::Builder end end -build do +default do Environment.new(echo: :command) do |env| env.add_builder(StrictBuilder) env.Object("one.o", "one.c", "CCFLAGS" => %w[-DONE]) diff --git a/build_tests/two_sources/libsuffix.rb b/build_tests/two_sources/libsuffix.rb index dd2a3de..cc5c648 100644 --- a/build_tests/two_sources/libsuffix.rb +++ b/build_tests/two_sources/libsuffix.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new() do |env| env["LIBSUFFIX"] = %w[.aaaa .aaa] env.Library("one.aaaa", "one.c", "CPPFLAGS" => ["-DONE"]) diff --git a/build_tests/two_sources/objsuffix.rb b/build_tests/two_sources/objsuffix.rb index af366a6..203d1dd 100644 --- a/build_tests/two_sources/objsuffix.rb +++ b/build_tests/two_sources/objsuffix.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["OBJSUFFIX"] = %w[.oooo .ooo] env.Object("one.oooo", "one.c", "CPPFLAGS" => ["-DONE"]) diff --git a/build_tests/typical/Rsconscript b/build_tests/typical/Rsconscript index 32ef1d5..46cada8 100644 --- a/build_tests/typical/Rsconscript +++ b/build_tests/typical/Rsconscript @@ -1,4 +1,4 @@ -build do +default do Environment.new(name: "typical") do |env| env["CPPPATH"] += glob("src/**") env.Program("^/typical.exe", glob("src/**/*.c")) diff --git a/build_tests/typical/build_hooks.rb b/build_tests/typical/build_hooks.rb index d477c46..6b67f9d 100644 --- a/build_tests/typical/build_hooks.rb +++ b/build_tests/typical/build_hooks.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new(echo: :command) do |env| env.append('CPPPATH' => glob('src/**/*/')) env.add_build_hook do |builder| diff --git a/build_tests/typical/build_hooks_override_vars.rb b/build_tests/typical/build_hooks_override_vars.rb index 3dda2cf..5d8eada 100644 --- a/build_tests/typical/build_hooks_override_vars.rb +++ b/build_tests/typical/build_hooks_override_vars.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new(echo: :command) do |env| env.append('CPPPATH' => glob('src/**')) env.add_build_hook do |builder| diff --git a/build_tests/typical/carat.rb b/build_tests/typical/carat.rb index 604ed2b..a8a5361 100644 --- a/build_tests/typical/carat.rb +++ b/build_tests/typical/carat.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new(echo: :command) do |env| env.append("CPPPATH" => glob("src/**")) FileUtils.mkdir_p(env.build_root) diff --git a/build_tests/typical/clone_and_name.rb b/build_tests/typical/clone_and_name.rb index ab4b28d..01e8b58 100644 --- a/build_tests/typical/clone_and_name.rb +++ b/build_tests/typical/clone_and_name.rb @@ -1,4 +1,4 @@ -build do +default do base_env = Environment.new do |env| env["CPPPATH"] += glob("src/**") end diff --git a/build_tests/typical/copy.rb b/build_tests/typical/copy.rb index 3629a76..23775b6 100644 --- a/build_tests/typical/copy.rb +++ b/build_tests/typical/copy.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new 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 a873c7a..f586d4e 100644 --- a/build_tests/typical/copy_directory.rb +++ b/build_tests/typical/copy_directory.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.Directory("copy") env.Copy("copy", "copy_directory.rb") diff --git a/build_tests/typical/copy_multiple.rb b/build_tests/typical/copy_multiple.rb index 91aa97f..2c34ebe 100644 --- a/build_tests/typical/copy_multiple.rb +++ b/build_tests/typical/copy_multiple.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new 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 0c3b30d..b4beaa9 100644 --- a/build_tests/typical/csuffix.rb +++ b/build_tests/typical/csuffix.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["CSUFFIX"] = %w[.yargh .c] env["CFLAGS"] += %w[-x c] diff --git a/build_tests/typical/echo_command_ruby_builder.rb b/build_tests/typical/echo_command_ruby_builder.rb index 3e4fdf9..bc9192e 100644 --- a/build_tests/typical/echo_command_ruby_builder.rb +++ b/build_tests/typical/echo_command_ruby_builder.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env.echo = :command env.Copy("copy.rb", "echo_command_ruby_builder.rb") diff --git a/build_tests/typical/echo_command_string.rb b/build_tests/typical/echo_command_string.rb index 016f203..76358ac 100644 --- a/build_tests/typical/echo_command_string.rb +++ b/build_tests/typical/echo_command_string.rb @@ -5,7 +5,7 @@ class MyBuilder < Rscons::Builder end end -build do +default do Environment.new do |env| env.echo = :command env.add_builder(MyBuilder) diff --git a/build_tests/typical/fileutils_methods.rb b/build_tests/typical/fileutils_methods.rb index e5f5459..8096d7a 100644 --- a/build_tests/typical/fileutils_methods.rb +++ b/build_tests/typical/fileutils_methods.rb @@ -1,4 +1,4 @@ -build do +default do mkdir "foo" cd "foo" do mkdir_p ["bar/baz", "bar/booz"] diff --git a/build_tests/typical/install.rb b/build_tests/typical/install.rb index 4cc3ad0..67fd0f1 100644 --- a/build_tests/typical/install.rb +++ b/build_tests/typical/install.rb @@ -1,9 +1,13 @@ project_name "install_test" -build do - Environment.new do |env| - env["CPPPATH"] += glob("src/**") +Environment.new do |env| + env["CPPPATH"] += glob("src/**") + + task "build" do env.Program("^/program.exe", glob("src/**/*.c")) + end + + task "install", deps: "build" do env.InstallDirectory("${prefix}/bin") env.Install("${prefix}/bin", "^/program.exe") env.InstallDirectory("${prefix}/share") @@ -12,3 +16,5 @@ build do env.Install("${prefix}/src", "src") end end + +default(deps: "build") diff --git a/build_tests/typical/multiple_environments.rb b/build_tests/typical/multiple_environments.rb index 2a8d679..83609d4 100644 --- a/build_tests/typical/multiple_environments.rb +++ b/build_tests/typical/multiple_environments.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["CPPPATH"] += glob("src/**") env.Program("^/prog.exe", glob("src/**/*.c")) diff --git a/build_tests/typical/multiple_targets_same_name.rb b/build_tests/typical/multiple_targets_same_name.rb index 96405a8..137822d 100644 --- a/build_tests/typical/multiple_targets_same_name.rb +++ b/build_tests/typical/multiple_targets_same_name.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["CPPPATH"] << "src/two" env.Object("one.o", "src/one/one.c") diff --git a/build_tests/typical/post_build_hook_expansion.rb b/build_tests/typical/post_build_hook_expansion.rb index ffac3c1..528e03c 100644 --- a/build_tests/typical/post_build_hook_expansion.rb +++ b/build_tests/typical/post_build_hook_expansion.rb @@ -1,4 +1,4 @@ -build do +default do Environment.new do |env| env["CPPPATH"] << "src/two" env.Object("one.o", "src/one/one.c") diff --git a/doc/user_guide.md b/doc/user_guide.md index c0eedfe..b83d270 100644 --- a/doc/user_guide.md +++ b/doc/user_guide.md @@ -11,6 +11,7 @@ It supports the following features: * compatible with Windows, Linux, OS X, and FreeBSD * colorized output with build progress * build hooks + * user-defined tasks with dependencies and custom parameters At its core, Rscons is mainly an engine to: @@ -22,7 +23,16 @@ Along the way, Rscons provides a concise syntax for specifying common types of build operations, but also provides an extensible framework for performing custom build operations as well. -Rscons is written in Ruby, and is inspired by [SCons](https://scons.org/) and [waf](https://waf.io/). +Rscons takes inspiration from: + * [SCons](https://scons.org/) + * [waf](https://waf.io/) + * [rake](https://github.com/ruby/rake) + * [CMake](https://cmake.org/) + * [Autoconf](https://www.gnu.org/software/autoconf/) + +Rscons is written in Ruby. +The only requirement to run Rscons is that the system has a Ruby interpreter +installed. ${remove} WARNING: This user guide is meant to be preprocessed and rendered by a custom @@ -131,75 +141,44 @@ version control systems): #> Command-Line Operation Rscons is typically invoked from the command-line as `./rscons`. -Rscons supports several build *operations*: - * configure - * build - * clean - * distclean - * install - * uninstall + ./rscons [global options] [[task] [task options] ...] -##> Configure Operation + Global options: + -b BUILD, --build=BUILD Set build directory (default: build) + -f FILE Use FILE as Rsconscript + -F, --show-failure Show failed command log from previous build and exit + -h, --help Show rscons help and exit + -j N, --nthreads=N Set number of threads + -r COLOR, --color=COLOR Set color mode (off, auto, force) + -v, --verbose Run verbosely + --version Show rscons version and exit -The `configure` operation will initialize the Rscons cache file and build -directory. -It will also perform any configuration checks requested by the build script. -Such configuration checks can include: +The user can list any number of tasks on the command line. +Any parameters beginning with a "-" that follow a task are interpreted as task +arguments until another parameter is seen that does not begin with "-". +For example: - * verifying operation of a compiler - * loading compilation/linker flags from a config program (e.g. `pkg-config`) - * verifying presence of a C/C++ header file - * verifying presence of a D import - * verifying presence of a library - * verifying presence of an executable - * any custom user-supplied configuration check + ./rscons -v build1 --build1-opt=val1 --flag build2 -##> Build Operation +The above command line is interpreted as follows: -If a `build` operation is requested and a `configure` operation has not yet -been performed, a `configure` operation will be automatically invoked. + * The user is passing the -v global option to run verbosely. + * The user requests to run task build1 with task parameters "--build1-opt=val1" and "--flag". + * The user requests to run task build2 with no task parameters. -The `build` operation will execute all builders registered to produce build -targets. +If no tasks are specified on the command line, Rscons executes the `default` +task. -If a `build` operation fails (e.g. due to a compilation failure), Rscons will -log the failed commands. +If a task fails due to a command failure (e.g. compilation or linking failed), +Rscons will log the failed commands. By default Rscons does not print the failed commands to the console so that it is easier for the user to focus on the actual compiler failure messages rather than the compilation command itself. -However, if the user wishes to see the compilation commands, rscons can be -invoked with the `-v` command-line option to show all complilation commands -while building, or, alternatively, following a compilation failure, the user -can invoke rscons with the -F option which will not rebuild but will show the -failed command log from the previous build operation. - -##> Clean Operation - -A `clean` operation will remove all built target files. -It will not remove items installed by an `install` operation. -It will not remove the cached configuration options. - -##> Distclean Operation - -A `distclean` operation will remove all built target files and all cached -configuration options. -Generally it will get the project directory back to the state it was in when -unpacked before any configuration or build operations took place. -It will not removed items installed by an `install` operation. - -##> Install Operation - -An `install` operation will perform a `build` (and if necessary, first a -`configure` as well). -In addition it will execute any `Install` or `InstallDirectory` builders to -install items into the specified install directory. - -##> Uninstall Operation - -An `uninstall` operation will remove any items installed by an `install` -operation. -It will not remove all built target files, just the installed copies. +The user can run `./rscons -F` to see the command that failed on the prior +Rscons execution. +The user can also invoke Rscons with the `-v` global command-line option which +will cause Rscons to print each command it is executing. #> The Build Script @@ -208,7 +187,7 @@ called `Rsconscript` (or `Rsconscript.rb`). Here is a simple example `Rsconscript` file: ```ruby -build do +default do Environment.new do |env| env.Program("myprog.exe", glob("src/**/*.c")) end @@ -221,176 +200,253 @@ called `myprog.exe` which is to be built from all C source files found The `Rsconscript` file is a Ruby script. -##> Build Script Methods +##> Tasks -`rscons` provides several methods that a build script can use. +Tasks are the high-level user interface for performing functionality in a build +script. +Tasks can create Environments that perform compilation/linking steps. +Tasks can also execute arbitrary commands or perform any miscellaneous logic. - * `glob` (see ${#Finding Files: The glob Method}) - * `path_append` (see ${#PATH Management}) - * `path_components` (see ${#PATH Management}) - * `path_prepend` (see ${#PATH Management}) - * `path_set` (see ${#PATH Management}) - * `rscons` (see ${#Using Subsidiary Build Scripts: The rscons Method}) - * `sh` (see (${#Executing Commands: The sh Method}) +Tasks can have dependencies, which are specified as names of other tasks that +should be executed before this task executes. -Additionally, the following methods from the Ruby -[FileUtils](https://ruby-doc.org/stdlib-3.1.0/libdoc/fileutils/rdoc/FileUtils.html) -module are made available for the build script to call directly: +Tasks can have action blocks. +When a task is executed, all of its action blocks are called in the order in +which they were added. - * `cd` - * `chmod` - * `chmod_R` - * `chown` - * `chown_R` - * `cp` - * `cp_lr` - * `cp_r` - * `install` - * `ln` - * `ln_s` - * `ln_sf` - * `mkdir` - * `mkdir_p` - * `mv` - * `pwd` - * `rm` - * `rm_f` - * `rm_r` - * `rm_rf` - * `rmdir` - * `touch` - -###> Finding Files: The glob Method - -The [`glob`](../yard/Rscons/Script/GlobalDsl.html#glob-instance_method) method can be -used to find files matching the patterns specified. -It supports a syntax similar to the Ruby [Dir.glob method](https://ruby-doc.org/core-3.1.0/Dir.html#method-c-glob) but operates more deterministically. - -Example use: +Example: ```ruby -build do +task "build" do Environment.new do |env| - env.Program("mytests", glob("src/**/*.cc", "test/**/*.cc")) + env.Program("^^/proj.elf", glob("src/**/*.c")) + end +end + +task "flash", deps: "build" do + sh "nrfjprog", "-f", "NRF52", "--program", env.expand_path("^^/proj.elf") +end +``` + +In this example, the `flash` task depends on the `build` task. +So if the project had not yet been built, and the user executes +`./rscons flash`, the project would first be built and then flashed to the +target. + +If the `task` method is called again with the name of an already existing task, +the task is not overwritten, but rather modified. +Any newly specified dependencies are added to the current dependencies. +Any action block is appended to the task's list of action blocks to execute +when the task is executed. + +###> Task Parameters + +Tasks can also take parameters. +Parameters are defined by the build script author, and have default values. +The user can override parameter values on the command line. + +Task parameters are defined by passing a parameter constructed with the Rscons +`param()` method to the `:params` argument of the `task()` method. +The signature of the `param` method is: + +```ruby +def param(name, value, takes_arg, description) +``` + +For example: + +```ruby +task "build", params: [ + param("myparam", "defaultvalue", true, "My special parameter"), + param("xyz", nil, false, "Enable the xyz feature"), +] do |task, params| + Environment.new do |env| + env["CPPDEFINES"] << "SOMEMACRO=#{params["myparam"]}" + if params["flag"] + env["CPPDEFINES"] << "ENABLE_FEATURE_XYZ" + end end end ``` -This example would build the `mytests` executable from all `.cc` source files -found recursively under the `src` or `test` directory. +With the above `Rsconscript`, the user could invoke Rscons as: -###> PATH Management + ./rscons build --myparam=pvalue --xyz -`rscons` provides methods for management of the `PATH` environment variable. +This would pass in "pvalue" as the value to the "myparam" parameter, and a +truthy value ("--xyz") as the value of the "xyz" parameter. -The -[`path_append`](../yard/Rscons/Script/GlobalDsl.html#path_append-instance_method) -and -[`path_prepend`](../yard/Rscons/Script/GlobalDsl.html#path_prepend-instance_method) -methods can be used to append or prepend a path to the `PATH` environment -variable. +As seen above, task parameter values can be accessed within a task's action +block by using the second parameter (`params`) to the action block. +Task parameter values can also be accessed with the `Task#[]` method on any +task object. +This allows accessing the parameter values of any task object, not just the +task owning the action block being executed. + +Example: ```ruby -path_prepend "i686-elf-gcc/bin" +task "one", params: param("flag", nil, false, "Enable a flag") + +task "two" do + puts "Task one's flag #{Task["one"]["flag"] ? "is" : "is not"} set" +end ``` -The -[`path_set`](../yard/Rscons/Script/GlobalDsl.html#path_set-instance_method) -method sets the `PATH` environment variable to the given Array or String. +###> Tasks with Special Meaning -The -[`path_components`](../yard/Rscons/Script/GlobalDsl.html#path_components-instance_method) -method returns an Array of the components in the `PATH` -environment variable. +Rscons recognizes special meaning for a few tasks: -###> Using Subsidiary Build Scripts: The rscons Method - -The -[`rscons`](../yard/Rscons/Script/GlobalDsl.html#rscons-instance_method) -build script method can be used to invoke an rscons subprocess to -perform an operation using a subsidiary rscons build script. -This can be used, for example, when a subproject is imported and a top-level -`configure` or `build` operation should also perform the same operation in the -subproject directory. - -The first argument to the `rscons` method specifies either a directory name, or -the path to the subsidiary Rsconscript file to execute. -Any additional arguments are passed to `rscons` when it executes the subsidiary -script. -`rscons` will change working directories to the directory containing the -subsidiary script when executing it. + * configure + * default + * clean + * distclean + * install + * uninstall +For each of these tasks, a shortcut method of the same name as the task is +provided which is equivalent to calling the `task()` method with the first +argument (task name) automatically filled in by the shortcut method. For example: ```ruby +default deps: "unpack_compiler" do + puts "default task" +end +``` + +is equivalent to: + +```ruby +task "default", deps: "unpack_compiler" do + puts "default task" +end +``` + +####> Configure Task + +The `configure` task allows Rscons to perform any one-time setup operations +required by a project, for example locating compilers and setting any initial +construction variable values based on the host environment in use. +It will also perform any configuration checks requested by the build script. +Such configuration checks can include: + + * verifying operation of a compiler + * loading compilation/linker flags from a config program (e.g. `pkg-config`) + * verifying presence of a C/C++ header file + * verifying presence of a D import + * verifying presence of a library + * verifying presence of an executable + * any custom user-supplied configuration check + +The configure task is implicitly a dependency of every other task unless that +task is configured with its `autoconf` option set to `false`. + +The global build script `autoconf` setting can also be set to `false` to +disable automatic invocation of the configure task. +For example: + +```ruby +autoconf false + configure do - rscons "subproject", "configure" + puts "configure" end -build do - rscons "subproject/Rsconscript", "build" +default do + puts "default" end ``` -It is also perfectly valid to perform a different operation in the subsidiary -script from the one being performed in the top-level script. -For example, in a project that requires a particular cross compiler, the -top-level `configure` script could build the necessary cross compiler using a -subsidiary build script. -This could look something like: +With the above Rsconscript, even if the project has not yet been configured, +a configure operation would not take place when the default task is executed. +The user would have to explicitly request the configure task from the command +line. + +The build script method `project_name` can be used to set the project name +which will be reported to the user during a configure operation. +For example: ```ruby +project_name "My awesome project" + configure do - rscons "cross/Rsconscript" - check_c_compiler "i686-elf-gcc" + check_d_compiler end ``` -This would build, and if necessary first configure, using the cross/Rsconscript -subsidiary build script. -Subsidiary build scripts are executed from within the directory containing the -build script. +See ${#Configuring the Project} for more details on how to make use of the +configuration functionality that Rscons provides. -###> Executing Commands: The sh Method +####> Default Task -The -[`sh`](../yard/Rscons/Script/GlobalDsl.html#sh-instance_method) -build script method can be used to directly execute commands. -The `sh` method accepts either a single String argument or an Array of Strings. -When an Array is given, if the array length is greater than 1, then the command -will not be executed and interpreted by the system shell. -Otherwise, it will be executed and interpreted by the system shell. +The `default` task is special in that Rscons will execute it if no other task +has been requested by the user on the command line. +It is entirely feasible for the default task to be the only task defined for a +project, and simple projects may wish to do just that. +The default task can also be used to declare a dependency on another task that +would effectively become the default. For example: ```ruby -build do - # Run "make" in imported "subcomponent" directory. - sh "cd subcomponent; make" - # Move a file around. - sh "mv", "subcomponent/file with spaces.txt", "new_name.txt" +task "build" do + ... end + +task "flash" do + ... +end + +default deps: "build" ``` -If the command fails, rscons will normally print the error and terminate -execution. -If the `:continue` option is set, then rscons will not terminate execution. +Then when the user runs `./rscons` the "build" task will be executed. + +####> Clean Task + +The `clean` task is built-in to Rscons. +It removes all built target files. +It will not remove items installed by an Install builder. +It will not remove the cached configuration options. + +####> Distclean Task + +The `distclean` task is built-in to Rscons. +It removes all built target files and all cached configuration options. +Generally it will get the project directory back to the state it was in when +unpacked before any configuration or build operations took place. +It will not remove items installed by an Install builder. + +####> Install Task + +The `install` task is not built-in to Rscons but rather is just a convention +for the build script author to use. +The suggested use is for the `install` task to invoke any `Install` or +`InstallDirectory` builders to install items into the specified installation +directory. + +The `install` shortcut method can be used. For example: ```ruby -build do - # This command will fail and a message will be printed. - sh "false", continue: true - # However, due to the :continue option being set, execution will continue. - sh "echo hi" +install do + env.Install("${prefix}/bin", "app.exe") + env.Install("${prefix}/share", "share") end ``` -##> Configuration Operations +####> Uninstall Task -A `configure` block is optional. -It can be used to perform various checks and setup operations for a project. -Example `configure` block: +The `uninstall` task is built-in to Rscons. +It removes any items installed by an Install builder. +It will not remove all built target files, just the installed copies. + +##> Configuring the Project + +Configure task actions can be used to perform various checks and setup +operations for a project. +Example `configure` action block: ```ruby configure do @@ -399,6 +455,17 @@ configure do end ``` +If any configure task action blocks are present, they will be execute when the +configure operation is performed. +This happens if the user requests the `configure` task from the command line. +It also happens if all of the following are true: + + * The project has not yet been configured. + * A task that does not have `autoconf` set to `false` is being executed. + * The global `autoconf` setting has not been set to `false`. + +See ${#Configure Task} for more information about `autoconf`. + ###> Checking for a Compiler The following methods can be used within a `configure` block to check for a @@ -647,15 +714,17 @@ end If set, a build define of the specified String will be added to the `CPPDEFINES` construction variable array if the requested package is found. -##> Build Operations +##> Building Targets -The `build` block is used to create Environments and register build targets. -An Rscons build script would not be very useful without a `build` block. +Building target files is accomplished by using Environments. +Environments are typically created within the default task or any user-defined +tasks. -Here is an example `build` block demonstrating how to register a build target: +Here is an example `default` task block demonstrating how to create an +Environment and register a build target: ```ruby -build do +default do Environment.new do |env| env.Program("myprog.exe", glob("src/**/*.c")) end @@ -687,7 +756,7 @@ to produce a user-specified build target. For example, for the `Rsconscript`: ```ruby -build do +default do Environment.new(name: "myproj") do |env| env.Program("myprog.exe", glob("src/**/*.c")) end @@ -711,7 +780,7 @@ construction variables. Example: ```ruby -build do +default do Environment.new do |env| env["CCFLAGS"] += %w[-O2 -Wall] env["LIBS"] += %w[m] @@ -1046,7 +1115,7 @@ build target or source file names. Example: ```ruby -build do +default do Environment.new do |env| env["CFLAGS"] << "-Wall" env.add_build_hook do |builder| @@ -1080,6 +1149,184 @@ In other words, build targets are not parallelized across a barrier. env.barrier ``` +##> Build Script Methods + +`rscons` provides several methods that a build script can use. + + * `autoconf` (see ${#Configure Task}) + * `clean` (see ${#Clean Task}) + * `configure` (see ${#Configure Task}) + * `default` (see ${#Default Task}) + * `distclean` (see ${#Distclean Task}) + * `glob` (see ${#Finding Files: The glob Method}) + * `install` (see ${#Install Task}) + * `param` (see ${#Task Parameters}) + * `path_append` (see ${#PATH Management}) + * `path_components` (see ${#PATH Management}) + * `path_prepend` (see ${#PATH Management}) + * `path_set` (see ${#PATH Management}) + * `project_name` (see ${#Configure Task}) + * `rscons` (see ${#Using Subsidiary Build Scripts: The rscons Method}) + * `sh` (see (${#Executing Commands: The sh Method}) + * `task` (see ${#Tasks}) + * `uninstall` (see ${#Uninstall Task}) + +Additionally, the following methods from the Ruby +[FileUtils](https://ruby-doc.org/stdlib-3.1.0/libdoc/fileutils/rdoc/FileUtils.html) +module are made available for the build script to call directly: + + * `cd` + * `chmod` + * `chmod_R` + * `chown` + * `chown_R` + * `cp` + * `cp_lr` + * `cp_r` + * `install` + * `ln` + * `ln_s` + * `ln_sf` + * `mkdir` + * `mkdir_p` + * `mv` + * `pwd` + * `rm` + * `rm_f` + * `rm_r` + * `rm_rf` + * `rmdir` + * `touch` + +###> Finding Files: The glob Method + +The [`glob`](../yard/Rscons/Script/GlobalDsl.html#glob-instance_method) method +can be used to find files matching the patterns specified. +It supports a syntax similar to the Ruby +[Dir.glob method](https://ruby-doc.org/core-3.1.0/Dir.html#method-c-glob) +but operates more deterministically (results are ordered based on file names +rather than file system directory ordering). + +Example use: + +```ruby +default do + Environment.new do |env| + env.Program("mytests", glob("src/**/*.cc", "test/**/*.cc")) + end +end +``` + +This example would build the `mytests` executable from all `.cc` source files +found recursively under the `src` or `test` directory. + +###> PATH Management + +`rscons` provides methods for management of the `PATH` environment variable. + +The +[`path_append`](../yard/Rscons/Script/GlobalDsl.html#path_append-instance_method) +and +[`path_prepend`](../yard/Rscons/Script/GlobalDsl.html#path_prepend-instance_method) +methods can be used to append or prepend a path to the `PATH` environment +variable. + +```ruby +path_prepend "i686-elf-gcc/bin" +``` + +The +[`path_set`](../yard/Rscons/Script/GlobalDsl.html#path_set-instance_method) +method sets the `PATH` environment variable to the given Array or String. + +The +[`path_components`](../yard/Rscons/Script/GlobalDsl.html#path_components-instance_method) +method returns an Array of the components in the `PATH` +environment variable. + +###> Using Subsidiary Build Scripts: The rscons Method + +The +[`rscons`](../yard/Rscons/Script/GlobalDsl.html#rscons-instance_method) +build script method can be used to invoke an rscons subprocess to +perform an operation using a subsidiary rscons build script. +This can be used, for example, when a subproject is imported and a top-level +`configure` or `build` operation should also perform the same operation in the +subproject directory. + +The first argument to the `rscons` method specifies either a directory name, or +the path to the subsidiary Rsconscript file to execute. +Any additional arguments are passed to `rscons` when it executes the subsidiary +script. +`rscons` will change working directories to the directory containing the +subsidiary script when executing it. + +For example: + +```ruby +configure do + rscons "subproject", "configure" +end + +task "build" do + rscons "subproject/Rsconscript", "build" +end +``` + +It is also perfectly valid to perform a different operation in the subsidiary +script from the one being performed in the top-level script. +For example, in a project that requires a particular cross compiler, the +top-level `configure` script could build the necessary cross compiler using a +subsidiary build script. +This could look something like: + +```ruby +configure do + rscons "cross/Rsconscript" + check_c_compiler "i686-elf-gcc" +end +``` + +This would build, and if necessary first configure, using the cross/Rsconscript +subsidiary build script. +Subsidiary build scripts are executed from within the directory containing the +build script. + +###> Executing Commands: The sh Method + +The +[`sh`](../yard/Rscons/Script/GlobalDsl.html#sh-instance_method) +build script method can be used to directly execute commands. +The `sh` method accepts either a single String argument or an Array of Strings. +When an Array is given, if the array length is greater than 1, then the command +will not be executed and interpreted by the system shell. +Otherwise, it will be executed and interpreted by the system shell. + +For example: + +```ruby +default do + # Run "make" in imported "subcomponent" directory. + sh "cd subcomponent; make" + # Move a file around. + sh "mv", "subcomponent/file with spaces.txt", "new_name.txt" +end +``` + +If the command fails, rscons will normally print the error and terminate +execution. +If the `:continue` option is set, then rscons will not terminate execution. +For example: + +```ruby +default do + # This command will fail and a message will be printed. + sh "false", continue: true + # However, due to the :continue option being set, execution will continue. + sh "echo hi" +end +``` + ##> Extending Rscons ### Adding New Languages @@ -1131,7 +1378,7 @@ For example: class Rscons::Builders::Mine < Rscons::Builder end -build do +default do Environment.new do |env| env.add_builder(Rscons::Builders::Mine) end @@ -1154,7 +1401,7 @@ Rscons::DEFAULT_BUILDERS << :Special #Rsconscript load "SpecialBuilder.rb" -build do +default do Environment.new do |env| # A build target using the "Special" builder can be registered. env.Special("target", "source") @@ -1383,7 +1630,7 @@ ${include lib/rscons/default_construction_variables.rb} ### Example: Building a C Program ```ruby -build do +default do Environment.new do |env| env["CFLAGS"] << "-Wall" env.Program("program", glob("src/**/*.c")) @@ -1394,7 +1641,7 @@ end ### Example: Building a D Program ```ruby -build do +default do Environment.new do |env| env["DFLAGS"] << "-Wall" env.Program("program", glob("src/**/*.d")) @@ -1405,7 +1652,7 @@ end ### Example: Cloning an Environment ```ruby -build do +default do main_env = Environment.new do |env| env["CFLAGS"] = ["-DSOME_DEFINE", "-O3"] env["LIBS"] = ["SDL"] @@ -1436,7 +1683,7 @@ EOF end end -build do +default do Environment.new do |env| env.add_builder(GenerateFoo) env.GenerateFoo("foo.h", []) @@ -1448,11 +1695,11 @@ end ### Example: Using different compilation flags for some sources ```ruby -build do +default do Environment.new do |env| env["CFLAGS"] = ["-O3", "-Wall"] - env.add_build_hook do |build_op| - if build_op[:target] =~ %r{build/third-party} + env.add_build_hook do |builder| + if builder.sources.first =~ %r{src/third-party/} build_op[:vars]["CFLAGS"] -= ["-Wall"] end end @@ -1464,7 +1711,7 @@ end ### Example: Creating a static library ```ruby -build do +default do Environment.new do |env| env.Library("mylib.a", glob("src/**/*.c")) end @@ -1474,7 +1721,7 @@ end ### Example: Creating a C++ parser source from a Yacc/Bison input file ```ruby -build do +default do Environment.new do |env| env.CFile("^/parser.tab.cc", "parser.yy") end diff --git a/lib/rscons.rb b/lib/rscons.rb index fd70a72..bfd14a1 100644 --- a/lib/rscons.rb +++ b/lib/rscons.rb @@ -10,6 +10,7 @@ require_relative "rscons/configure_op" require_relative "rscons/default_construction_variables" require_relative "rscons/environment" require_relative "rscons/script" +require_relative "rscons/task" require_relative "rscons/util" require_relative "rscons/varset" require_relative "rscons/version" @@ -49,13 +50,6 @@ module Rscons @application ||= Application.new end - # Access any variables set on the rscons command-line. - # - # @return [VarSet] - def vars(*args) - application.vars(*args) - end - # Return whether the given target is a phony target. # # @param target [Symbol, String] Target name. diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index d0050c0..33d8c9e 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -17,141 +17,57 @@ module Rscons # The number of threads to use when scheduling subprocesses. attr_accessor :n_threads + # @return [Script] + # Build script. + attr_reader :script + # @return [Boolean] # Whether to run verbosely. attr_accessor :verbose - # @return [VarSet] - # Access any variables set on the rscons command-line. - attr_reader :vars - # Create Application instance. def initialize + @script = Script.new @build_dir = ENV["RSCONS_BUILD_DIR"] || "build" ENV.delete("RSCONS_BUILD_DIR") @n_threads = Util.determine_n_threads - @vars = VarSet.new - @operations = Set.new - @build_step = 0 end - # Check whether a requested operation is active. + # Run the application. # - # @param op [String] - # Operation name. + # Execute user-specified tasks. # - # @return [Boolean] - # Whether the requested operation is active. - def operation(op) - @operations.include?(op) - end - - # Run the specified operation. + # @api private # - # @param operation [String] - # The operation to perform (e.g. "clean", "configure", "build", etc...) - # @param script [Script] - # The script. - # @param operation_options [Hash] - # Option values from the CLI for the operation. - # @param options [Hash] - # Optional parameters. - # @option sub_op [Boolean] - # Whether this operation is not the top-level operation. + # @param tasks [Array] + # List of task(s) to execute. # # @return [Integer] # Process exit code (0 on success). - def run(operation, script, operation_options, options = {}) - @start_time = Time.new - @script = script - @operations << operation - puts "Starting '#{operation}' at #{Time.new}" if verbose - rv = - case operation - when "build" - rv = 0 - unless Cache.instance["configuration_data"]["configured"] - rv = - if @script.autoconf - run("configure", script, operation_options, sub_op: false) - else - $stderr.puts "Project must be configured first, and autoconf is disabled" - 1 - end - end - if rv == 0 - build(operation_options) - else - rv - end - when "clean" - clean - when "configure" - configure(operation_options) - when "distclean" - distclean - when "install" - run("build", script, operation_options, sub_op: false) - when "uninstall" - uninstall - else - $stderr.puts "Unknown operation: #{operation}" - 1 - end - if verbose and options[:sub_op].nil? - time = Time.new - elapsed = time - @start_time - puts "'#{operation}' complete at #{time} (#{Util.format_elapsed_time(elapsed)})" + def run(tasks) + Cache.instance["failed_commands"] = [] + tasks.each do |task| + Task[task].check_execute end - rv + 0 end - # Get the next build step number. + # Show the last failures. # - # This is used internally by the {Environment} class. - # - # @api private - def get_next_build_step - @build_step += 1 - end - - # Get the total number of build steps. - # - # @return [Integer] - # The total number of build steps. - def get_total_build_steps - Environment.environments.reduce(@build_step) do |result, env| - result + env.build_steps_remaining - end - end - - private - - # Build the project. - # - # @param options [Hash] - # Options. - # - # @return [Integer] - # Exit code. - def build(options) - begin - Cache.instance["failed_commands"] = [] - @script.build - Environment.environments.each do |env| - env.process - end - 0 - rescue RsconsError => e - Ansi.write($stderr, :red, e.message, :reset, "\n") - 1 + # @return [void] + def show_failure + failed_commands = Cache.instance["failed_commands"] + failed_commands.each_with_index do |command, i| + Ansi.write($stdout, :red, "Failed command (#{i + 1}/#{failed_commands.size}):", :reset, "\n") + $stdout.puts Util.command_to_s(command) end end # Remove all generated files. # - # @return [Integer] - # Exit code. + # @api private + # + # @return [void] def clean cache = Cache.instance # remove all built files @@ -168,49 +84,60 @@ module Rscons end end cache.write - 0 end # Remove the build directory and clear the cache. # - # @return [Integer] - # Exit code. + # @api private + # + # @return [void] def distclean cache = Cache.instance clean FileUtils.rm_rf(@build_dir) cache.clear - 0 + end + + # Check if the project needs to be configured. + # + # @api private + # + # @return [void] + def check_configure + unless Cache.instance["configuration_data"]["configured"] + if @script.autoconf + configure + end + end end # Configure the project. # + # @api private + # # @param options [Hash] # Options. # - # @return [Integer] - # Exit code. - def configure(options) - rv = 0 - options = options.merge(project_name: @script.project_name) - co = ConfigureOp.new(options) + # @return [void] + def configure + co = ConfigureOp.new(@script) begin @script.configure(co) rescue RsconsError => e - if e.message and e.message != "" - $stderr.puts e.message - end - Ansi.write($stderr, :red, "Configuration failed", :reset, "\n") - rv = 1 + co.close(false) + raise e end - co.close(rv == 0) - rv + co.close(true) end # Remove installed files. # + # @api private + # # @return [Integer] # Exit code. + # + # @return [void] def uninstall cache = Cache.instance cache.targets(true).each do |target| @@ -229,7 +156,6 @@ module Rscons end end cache.write - 0 end end diff --git a/lib/rscons/builder.rb b/lib/rscons/builder.rb index 5fe5cbf..abdbf22 100644 --- a/lib/rscons/builder.rb +++ b/lib/rscons/builder.rb @@ -87,14 +87,6 @@ module Rscons self.class.name end - # Return whether the builder is a no-op. - # - # @return [Boolean] - # Whether the builder is a no-op. - def nop? - false - end - # Manually record a given build target as depending on the specified files. # # @param user_deps [Array] diff --git a/lib/rscons/builder_set.rb b/lib/rscons/builder_set.rb index c36e86e..8373d78 100644 --- a/lib/rscons/builder_set.rb +++ b/lib/rscons/builder_set.rb @@ -37,7 +37,7 @@ module Rscons # The number of remaining build steps. def build_steps_remaining self.reduce(0) do |result, (target, builders)| - result + builders.select {|b| not b.nop?}.size + result + builders.size end end diff --git a/lib/rscons/builders/copy.rb b/lib/rscons/builders/copy.rb index e0dad5a..6278dae 100644 --- a/lib/rscons/builders/copy.rb +++ b/lib/rscons/builders/copy.rb @@ -9,61 +9,48 @@ module Rscons def initialize(*args) super @install_builder = self.class.name == "Install" - @nop = @install_builder && !Rscons.application.operation("install") - end - - # Return whether the builder is a no-op. - # - # @return [Boolean] - # Whether the builder is a no-op. - def nop? - @nop end # Run the builder to produce a build target. def run(options) - if @nop - true + target_is_dir = (@sources.length > 1) || + Dir.exists?(@sources.first) || + Dir.exists?(@target) + outdir = target_is_dir ? @target : File.dirname(@target) + # Collect the list of files to copy over. + file_map = {} + if target_is_dir + @sources.each do |src| + if Dir.exists? src + Dir.glob("#{src}/**/*", File::FNM_DOTMATCH).select do |f| + File.file?(f) + end.each do |subfile| + subpath = Pathname.new(subfile).relative_path_from(Pathname.new(src)).to_s + file_map[subfile] = "#{outdir}/#{subpath}" + end + else + file_map[src] = "#{outdir}/#{File.basename(src)}" + end + end else - target_is_dir = (@sources.length > 1) || - Dir.exists?(@sources.first) || - Dir.exists?(@target) - outdir = target_is_dir ? @target : File.dirname(@target) - # Collect the list of files to copy over. - file_map = {} - if target_is_dir - @sources.each do |src| - if Dir.exists? src - Dir.glob("#{src}/**/*", File::FNM_DOTMATCH).select do |f| - File.file?(f) - end.each do |subfile| - subpath = Pathname.new(subfile).relative_path_from(Pathname.new(src)).to_s - file_map[subfile] = "#{outdir}/#{subpath}" - end - else - file_map[src] = "#{outdir}/#{File.basename(src)}" - end - end - else - file_map[sources.first] = target - end - printed_message = false - file_map.each do |src, dest| - # Check the cache and copy if necessary - unless @cache.up_to_date?(dest, :Copy, [src], @env) - unless printed_message - message = "#{name} #{Util.short_format_paths(@sources)} => #{@target}" - print_run_message(message, nil) - printed_message = true - end - @cache.mkdir_p(File.dirname(dest), install: @install_builder) - FileUtils.rm_f(dest) - FileUtils.cp(src, dest, :preserve => true) - end - @cache.register_build(dest, :Copy, [src], @env, install: @install_builder) - end - (target_is_dir ? Dir.exists?(@target) : File.exists?(@target)) ? true : false + file_map[sources.first] = target end + printed_message = false + file_map.each do |src, dest| + # Check the cache and copy if necessary + unless @cache.up_to_date?(dest, :Copy, [src], @env) + unless printed_message + message = "#{name} #{Util.short_format_paths(@sources)} => #{@target}" + print_run_message(message, nil) + printed_message = true + end + @cache.mkdir_p(File.dirname(dest), install: @install_builder) + FileUtils.rm_f(dest) + FileUtils.cp(src, dest, :preserve => true) + end + @cache.register_build(dest, :Copy, [src], @env, install: @install_builder) + end + (target_is_dir ? Dir.exists?(@target) : File.exists?(@target)) ? true : false end end diff --git a/lib/rscons/builders/directory.rb b/lib/rscons/builders/directory.rb index 10b61b9..c6e321f 100644 --- a/lib/rscons/builders/directory.rb +++ b/lib/rscons/builders/directory.rb @@ -8,32 +8,19 @@ module Rscons def initialize(*args) super @install_builder = self.class.name == "InstallDirectory" - @nop = @install_builder && !Rscons.application.operation("install") - end - - # Return whether the builder is a no-op. - # - # @return [Boolean] - # Whether the builder is a no-op. - def nop? - @nop end # Run the builder to produce a build target. def run(options) - if @nop + if File.directory?(@target) true + elsif File.exists?(@target) + Ansi.write($stderr, :red, "Error: `#{@target}' already exists and is not a directory", :reset, "\n") + false else - if File.directory?(@target) - true - elsif File.exists?(@target) - Ansi.write($stderr, :red, "Error: `#{@target}' already exists and is not a directory", :reset, "\n") - false - else - print_run_message("Creating directory #{@target}", nil) - @cache.mkdir_p(@target, install: @install_builder) - true - end + print_run_message("Creating directory #{@target}", nil) + @cache.mkdir_p(@target, install: @install_builder) + true end end diff --git a/lib/rscons/cli.rb b/lib/rscons/cli.rb index e651bcc..a5c9b9b 100644 --- a/lib/rscons/cli.rb +++ b/lib/rscons/cli.rb @@ -1,65 +1,88 @@ require "rscons" require "optparse" -# CLI usage string. -USAGE = < io + $stderr.puts io.message + $stderr.puts usage + exit 2 + end + end - # Run the Rscons CLI. - # - # @param argv [Array] - # Command-line parameters. - # - # @return [void] - def run(argv) - argv = argv.dup - begin - exit run_toplevel(argv) - rescue OptionParser::InvalidOption => io - $stderr.puts io.message - $stderr.puts USAGE - exit 2 + private + + def parse_task_params(task, argv) + 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 + else + return end end + end - private + def parse_tasks_and_params(argv) + tasks = [] + while argv.size > 0 + task = argv.shift + parse_task_params(task, argv) + tasks << task + end + tasks + end + + def run_toplevel(argv) + rsconscript = nil + do_help = false + + OptionParser.new do |opts| - def add_global_options(opts) opts.on("-b", "--build DIR") do |build_dir| Rscons.application.build_dir = build_dir end + opts.on("-f FILE") do |f| + rsconscript = f + end + + opts.on("-F", "--show-failure") do + Rscons.application.show_failure + return 0 + end + + opts.on("-h", "--help") do + do_help = true + end + opts.on("-j NTHREADS") do |n_threads| Rscons.application.n_threads = n_threads.to_i end @@ -76,103 +99,96 @@ module Rscons opts.on("-v", "--verbose") do Rscons.application.verbose = true end + + opts.on("--version") do + puts "Rscons version #{Rscons::VERSION}" + return 0 + end + + end.order!(argv) + + # Find the build script. + if rsconscript + unless File.exists?(rsconscript) + $stderr.puts "Cannot read #{rsconscript}" + return 1 + end + else + rsconscript = DEFAULT_RSCONSCRIPTS.find do |f| + File.exists?(f) + end end - def run_toplevel(argv) - rsconscript = nil - do_help = false - - OptionParser.new do |opts| - - add_global_options(opts) - - opts.on("-f FILE") do |f| - rsconscript = f - end - - opts.on("-F", "--show-failure") do - show_failure - exit 0 - end - - opts.on("--version") do - puts "Rscons version #{Rscons::VERSION}" - exit 0 - end - - opts.on("-h", "--help") do - do_help = true - end - - end.order!(argv) - - # Retrieve the operation, or default to build. - operation = argv.shift || "build" - - argv.each do |arg| - if arg =~ /^([^=]+)=(.*)$/ - Rscons.application.vars[$1] = $2 - end - end - + begin + # Load the build script. if rsconscript - unless File.exists?(rsconscript) - $stderr.puts "Cannot read #{rsconscript}" - exit 1 - end - else - rsconscript = DEFAULT_RSCONSCRIPTS.find do |f| - File.exists?(f) - end - end - - if rsconscript - script = Script.new - script.load(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 - exit 0 + 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(", ")}" - exit 1 + return 1 end - operation_options = parse_operation_args(operation, argv) || {} + # 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) - exit Rscons.application.run(operation, script, operation_options) - end - - def parse_operation_args(operation, argv) - options = {} - OptionParser.new do |opts| - add_global_options(opts) - case operation - when "configure" - parse_configure_args(opts, argv, options) - end - end.order!(argv) - options - end - - def parse_configure_args(opts, argv, options) - opts.on("--prefix PREFIX") do |prefix| - options[:prefix] = prefix + # If no user specified tasks, run "default" task. + if tasks.empty? + tasks << "default" end - end - def show_failure - failed_commands = Cache.instance["failed_commands"] - failed_commands.each_with_index do |command, i| - Ansi.write($stdout, :red, "Failed command (#{i + 1}/#{failed_commands.size}):", :reset, "\n") - $stdout.puts Util.command_to_s(command) - end + # Finally, with the script fully loaded and command-line parsed, run + # the application to execute all required tasks. + Rscons.application.run(tasks) + rescue RsconsError => e + Ansi.write($stderr, :red, e.message, :reset, "\n") + 1 end - end + + def usage + usage = < options[:prefix]) + vars = {} + Task["configure"].params.each do |name, param| + Ansi.write($stdout, "Setting #{name}... ", :green, param.value, :reset, "\n") + vars[name] = param.value + end + store_merge(vars) end # Close the log file handle. @@ -399,7 +396,7 @@ module Rscons options[:on_fail].call end if should_fail - raise RsconsError.new + raise RsconsError.new("Configuration failed") end end end diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 44761ed..aba5988 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -14,6 +14,10 @@ module Rscons # All Environments. attr_reader :environments + # @return [Environment] + # The Environment that is currently executing a construction block. + attr_accessor :open_environment + # Initialize class instance variables. def class_init @environments = [] @@ -72,6 +76,7 @@ module Rscons # 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 = {}) + Rscons.application.check_configure unless Cache.instance["configuration_data"]["configured"] raise "Project must be configured before creating an Environment" end @@ -109,7 +114,10 @@ module Rscons @n_threads = Rscons.application.n_threads if block_given? + Environment.open_environment = self yield self + Environment.open_environment = nil + process end end @@ -158,7 +166,10 @@ module Rscons env.instance_variable_set(:@n_threads, @n_threads) if block_given? + Environment.open_environment = env yield env + Environment.open_environment = nil + env.process end env end @@ -274,6 +285,10 @@ module Rscons @process_commands_waiting_to_run = [] @process_builder_waits = {} @process_builders_to_run = [] + @build_step = 0 + @build_steps = @builder_sets.reduce(0) do |result, builder_set| + result + builder_set.build_steps_remaining + end begin while @builder_sets.size > 0 or @threads.size > 0 or @process_commands_waiting_to_run.size > 0 process_step @@ -524,7 +539,7 @@ module Rscons message = short_description if short_description end if message - total_build_steps = Rscons.application.get_total_build_steps.to_s + total_build_steps = @build_steps.to_s this_build_step = sprintf("%#{total_build_steps.size}d", builder.build_step) progress = "[#{this_build_step}/#{total_build_steps}]" Ansi.write($stdout, *Util.colorize_markup("#{progress} #{message}"), "\n") @@ -549,16 +564,6 @@ module Rscons @builder_sets << build_builder_set end - # Get the number of build steps remaining. - # - # @return [Integer] - # The number of build steps remaining. - def build_steps_remaining - @builder_sets.reduce(0) do |result, builder_set| - result + builder_set.build_steps_remaining - end - end - private # Build a BuilderSet. @@ -569,6 +574,16 @@ module Rscons BuilderSet.new(@registered_build_dependencies, @side_effects) end + # Get the next build step number. + # + # @api private + # + # @return [Integer] + # Next build step number. + def get_next_build_step + @build_step += 1 + end + # Run a builder and process its return value. # # @param builder [Builder] @@ -576,9 +591,7 @@ module Rscons # # @return [void] def run_builder(builder) - unless builder.nop? - builder.build_step ||= Rscons.application.get_next_build_step - end + builder.build_step ||= get_next_build_step case result = builder.run({}) when Array result.each do |waititem| diff --git a/lib/rscons/script.rb b/lib/rscons/script.rb index 5bf0993..799a264 100644 --- a/lib/rscons/script.rb +++ b/lib/rscons/script.rb @@ -5,6 +5,10 @@ module Rscons # Global DSL methods. class GlobalDsl + # Create a GlobalDsl. + def initialize(script) + @script = script + end # Return a list of paths matching the specified pattern(s). # @@ -33,6 +37,20 @@ module Rscons end.sort end + # Construct a task parameter. + # + # @param name [String] + # Param name. + # @param value [String, nil] + # Param value. + # @param takes_arg [String] + # Whether the parameter takes an argument. + # @param description [String] + # Param description. + def param(name, value, takes_arg, description) + Task::Param.new(name, value, takes_arg, description) + end + # Return path components from the PATH variable. # # @return [Array] @@ -159,6 +177,16 @@ module Rscons end 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 + [ :cd, :chmod, @@ -191,12 +219,7 @@ module Rscons end # Top-level DSL available to the Rsconscript. - class Dsl < GlobalDsl - # Create a Dsl. - def initialize(script) - @script = script - end - + class TopLevelDsl < GlobalDsl # Set the project name. def project_name(project_name) @script.project_name = project_name @@ -207,14 +230,18 @@ 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 + # Shortcut methods to create task blocks for special tasks. + [ + :clean, + :distclean, + :configure, + :default, + :install, + :uninstall, + ].each do |method_name| + define_method(method_name) do |*args, &block| + task(method_name.to_s, *args, &block) + end end end @@ -222,9 +249,12 @@ module Rscons class ConfigureDsl < GlobalDsl # Create a ConfigureDsl. # + # @param script [Script] + # The Script being evaluated. # @param configure_op [ConfigureOp] # The configure operation object. - def initialize(configure_op) + def initialize(script, configure_op) + super(script) @configure_op = configure_op end @@ -263,18 +293,36 @@ module Rscons attr_accessor :project_name # @return [Boolean] - # Whether to autoconfigure if the user does not explicitly perform a - # configure operation before building (default: true). + # Whether to autoconfigure if the user does not explicitly configure + # before calling a normal task (default: true). attr_accessor :autoconf - # @return [Hash] - # Operation lambdas. - attr_reader :operations - # Construct a Script. def initialize @autoconf = true - @operations = {} + TopLevelDsl.new(self).instance_eval do + task("clean", + desc: "Remove build artifacts (but not configuration)", + autoconf: false) do + Rscons.application.clean + end + task("configure", + desc: "Configure the project", + autoconf: false, + params: [param("prefix", "/usr/local", true, "Set installation prefix (default: /usr/local)")]) + task("distclean", + desc: "Remove build directory and configuration", + autoconf: false) do + Rscons.application.distclean + end + task("install", + desc: "Install project to configured installation prefix") + task("uninstall", + desc: "Uninstall project", + autoconf: false) do + Rscons.application.uninstall + end + end end # Load a script from the specified file. @@ -285,21 +333,15 @@ module Rscons # @return [void] def load(path) script_contents = File.read(path, mode: "rb") - Dsl.new(self).instance_eval(script_contents, path, 1) + TopLevelDsl.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. + # Perform configure action. def configure(configure_op) - if operation_lambda = @operations["configure"] - cdsl = ConfigureDsl.new(configure_op) - cdsl.instance_eval(&operation_lambda) + cdsl = ConfigureDsl.new(self, configure_op) + configure_task = Task["configure"] + configure_task.actions.each do |action| + cdsl.instance_exec(configure_task, configure_task.param_values, &action) end end diff --git a/lib/rscons/task.rb b/lib/rscons/task.rb new file mode 100644 index 0000000..42da156 --- /dev/null +++ b/lib/rscons/task.rb @@ -0,0 +1,232 @@ +module Rscons + + # A task is a named collection of actions and/or dependencies. + class Task + + class << self + + # Access a task by name. + # + # @param name [String, nil] + # Task name, or nil to return a Hash of all tasks. + # + # @return [Hash, Task, nil] + # Hash of all tasks if name is nil, otherwise Task with the given name, + # if found. + def [](name = nil) + if name + if task = tasks[name] + task + else + raise RsconsError.new("Task '#{name}' not found") + end + else + tasks + end + end + + # Register a newly created task. + # + # @api private + # + # @param task [Task] + # Task to register. + # + # @return [void] + def register(task) + tasks[task.name] = task + end + + # Get all registered tasks. + # + # @api private + # + # @return [Hash] + # All registered tasks. + def tasks + @tasks ||= {} + end + + end + + # Class to represent a task parameter. + class Param + + # @return [String] + # Param name. + attr_reader :name + + # @return [String] + # Param description. + attr_reader :description + + # @return [Boolean] + # Whether the parameter takes an argument. + attr_reader :takes_arg + + # @return [String, nil] + # Param value. + attr_accessor :value + + # Construct a Param. + # + # @param name [String] + # Param name. + # @param value [String, nil] + # Param value. + # @param takes_arg [String] + # Whether the parameter takes an argument. + # @param description [String] + # Param description. + def initialize(name, value, takes_arg, description) + @name = name + @value = value + @takes_arg = takes_arg + @description = description + end + + end + + # @return [Array] + # Task action blocks. + attr_reader :actions + + # @return [Boolean] + # 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 + + # @return [String] + # Task name. + attr_reader :name + + # @return [Hash Param>] + # Task params. + attr_reader :params + + # Construct a task. + # + # @param name [String] + # Task name. + # @param options [Hash] + # Options. + # @option options [Boolean] :autoconf + # Whether to automatically configure before running this task (default + # true). + def initialize(name, options, &block) + @autoconf = true + @deps = [] + @desc = nil + @name = name + @params = {} + @actions = [] + Task.register(self) + modify(options, &block) + end + + # Get a parameter's value. + # + # @param param_name [String] + # Parameter name. + # + # @return [String] + # Parameter value. + def [](param_name) + param = @params[param_name] + unless param + raise RsconsError.new("Could not find parameter '#{param_name}'") + end + param.value + end + + # Execute a task's actions. + # + # @return [void] + def execute + @executed = true + if @autoconf + Rscons.application.check_configure + end + @deps.each do |dep| + Task[dep].check_execute + end + if @name == "configure" + Rscons.application.configure + else + @actions.each do |action| + action[self, param_values] + end + end + end + + # Check if the task has been executed, and if not execute it. + # + # @return [void] + def check_execute + unless executed? + execute + end + end + + # Check if the task has been executed. + # + # @return [Boolean] + # Whether the task has been executed. + def executed? + @executed + end + + # Modify a task. + # + # @api private + # + # @return [void] + def modify(options, &block) + if options.include?(:autoconf) + @autoconf = options[:autoconf] + end + if options.include?(:desc) + @desc = options[:desc] + end + if options.include?(:deps) + @deps += Array(options[:deps]) + end + if options.include?(:params) + Array(options[:params]).each do |param| + @params[param.name] = param + end + end + if block + if env = Environment.open_environment + @actions << proc do + block[] + env.process + end + else + @actions << block + end + end + end + + # Get parameter values as a Hash. + # + # @return [Hash] + # Parameter values. + def param_values + param_values = {} + @params.each do |name, param| + param_values[name] = param.value + end + param_values + end + + end + +end diff --git a/rb/build_dist.rb b/rb/build_dist.rb index 914800b..b8992b2 100755 --- a/rb/build_dist.rb +++ b/rb/build_dist.rb @@ -88,7 +88,7 @@ unless File.exists?(script) end load script if __FILE__ == $0 - Rscons::Cli.run(ARGV) + Rscons::Cli.new.run(ARGV) end #==>#{encoded_compressed_script} EOF diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index ad95cfb..6aa82ed 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -89,26 +89,13 @@ describe Rscons do end def run_rscons(options = {}) - operation = options[:op] || "build" - if operation.is_a?(Symbol) - operation = operation.to_s - end - unless operation.is_a?(Array) - operation = [operation] - end - rsconscript_args = - if options[:rsconscript] - %W[-f #{options[:rsconscript]}] - else - [] - end - rscons_args = options[:rscons_args] || [] + args = Array(options[:args]) || [] if ENV["dist_specs"] exe = "#{@owd}/test/rscons.rb" else exe = "#{@owd}/bin/rscons" end - command = %W[ruby -I. -r _simplecov_setup #{exe}] + rsconscript_args + rscons_args + operation + command = %W[ruby -I. -r _simplecov_setup #{exe}] + args @statics[:build_test_id] ||= 0 @statics[:build_test_id] += 1 command_prefix = @@ -210,7 +197,7 @@ EOF it "uses the build directory specified with -b" do test_dir("simple") - result = run_rscons(rscons_args: %w[-b b]) + result = run_rscons(args: %w[-b b]) expect(result.stderr).to eq "" expect(Dir.exist?("build")).to be_falsey expect(File.exists?("b/e.1/simple.c.o")).to be_truthy @@ -227,7 +214,7 @@ EOF it "allows specifying a Builder object as the source to another build target" do test_dir("simple") - result = run_rscons(rsconscript: "builder_as_source.rb") + result = run_rscons(args: %w[-f builder_as_source.rb]) expect(result.stderr).to eq "" expect(File.exists?("simple.o")).to be_truthy expect(nr(`./simple.exe`)).to eq "This is a simple C program\n" @@ -235,7 +222,7 @@ EOF it 'prints commands as they are executed' do test_dir('simple') - result = run_rscons(rsconscript: "command.rb") + result = run_rscons(args: %w[-f command.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{gcc -c -o build/e.1/simple.c.o -MMD -MF build/e.1/simple.c.o.mf simple.c}, @@ -304,13 +291,13 @@ EOF it 're-links a program when the link flags have changed' do test_dir('simple') - result = run_rscons(rsconscript: "command.rb") + result = run_rscons(args: %w[-f command.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{gcc -c -o build/e.1/simple.c.o -MMD -MF build/e.1/simple.c.o.mf simple.c}, %r{gcc -o simple.exe build/e.1/simple.c.o}, ]) - result = run_rscons(rsconscript: "link_flag_change.rb") + result = run_rscons(args: %w[-f link_flag_change.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{gcc -o simple.exe build/e.1/simple.c.o -Llibdir}, @@ -319,7 +306,7 @@ EOF it "supports barriers and prevents parallelizing builders across them" do test_dir "simple" - result = run_rscons(rsconscript: "barrier.rb", rscons_args: %w[-j 3]) + result = run_rscons(args: %w[-f barrier.rb -j 3]) expect(result.stderr).to eq "" slines = lines(result.stdout).select {|line| line =~ /T\d/} expect(slines).to eq [ @@ -340,7 +327,7 @@ EOF it "expands target and source paths starting with ^/ and ^^/" do test_dir("typical") - result = run_rscons(rsconscript: "carat.rb", rscons_args: %w[-b bld]) + result = run_rscons(args: %w[-f carat.rb -b bld]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{gcc -c -o bld/e.1/one.o -MMD -MF bld/e.1/one.o.mf -Isrc -Isrc/one -Isrc/two bld/e.1/one.c}, @@ -359,7 +346,7 @@ EOF it "raises an error when a side-effect file is registered for a build target that is not registered" do test_dir "simple" - result = run_rscons(rsconscript: "error_produces_nonexistent_target.rb") + result = run_rscons(args: %w[-f error_produces_nonexistent_target.rb]) expect(result.stderr).to match /Could not find a registered build target "foo"/ end @@ -370,7 +357,7 @@ EOF expect(result.stderr).to eq "" expect(`./simple.exe`).to match /This is a simple C program/ expect(File.exists?('build/e.1/simple.c.o')).to be_truthy - result = run_rscons(op: %w[clean]) + result = run_rscons(args: %w[clean]) expect(File.exists?('build/e.1/simple.c.o')).to be_falsey expect(File.exists?('build/e.1')).to be_falsey expect(File.exists?('simple.exe')).to be_falsey @@ -384,7 +371,7 @@ EOF expect(`./simple.exe`).to match /This is a simple C program/ expect(File.exists?('build/e.1/simple.c.o')).to be_truthy File.open('build/e.1/dum', 'w') { |fh| fh.puts "dum" } - result = run_rscons(op: %w[clean]) + result = run_rscons(args: %w[clean]) expect(File.exists?('build/e.1')).to be_truthy expect(File.exists?('build/e.1/dum')).to be_truthy end @@ -393,15 +380,15 @@ EOF test_dir "typical" Dir.mktmpdir do |prefix| - result = run_rscons(rsconscript: "install.rb", op: %W[configure --prefix=#{prefix}]) + result = run_rscons(args: %W[-f install.rb configure --prefix=#{prefix}]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "install.rb", op: %W[install]) + result = run_rscons(args: %w[-f install.rb install]) expect(result.stderr).to eq "" expect(File.exists?("#{prefix}/bin/program.exe")).to be_truthy expect(File.exists?("build/e.1/src/one/one.c.o")).to be_truthy - result = run_rscons(rsconscript: "install.rb", op: %W[clean]) + result = run_rscons(args: %w[-f install.rb clean]) expect(result.stderr).to eq "" expect(File.exists?("#{prefix}/bin/program.exe")).to be_truthy expect(File.exists?("build/e.1/src/one/one.c.o")).to be_falsey @@ -412,18 +399,18 @@ EOF test_dir "typical" Dir.mktmpdir do |prefix| - result = run_rscons(rsconscript: "install.rb", op: %W[configure --prefix=#{prefix}]) + result = run_rscons(args: %W[-f install.rb configure --prefix=#{prefix}]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "install.rb", op: %W[install]) + result = run_rscons(args: %w[-f install.rb install]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "install.rb", op: %W[clean]) + result = run_rscons(args: %w[-f install.rb clean]) expect(result.stderr).to eq "" expect(File.exists?("#{prefix}/bin/program.exe")).to be_truthy expect(File.exists?("build/e.1/src/one/one.c.o")).to be_falsey - result = run_rscons(rsconscript: "install.rb", op: %W[uninstall -v]) + result = run_rscons(args: %w[-f install.rb -v uninstall]) expect(result.stderr).to eq "" expect(result.stdout).to match %r{Removing #{prefix}/bin/program.exe} expect(Dir.entries(prefix)).to match_array %w[. ..] @@ -445,7 +432,7 @@ EOF it 'supports custom builders with multiple targets' do test_dir('custom_builder') - result = run_rscons(rsconscript: "multiple_targets.rb") + result = run_rscons(args: %w[-f multiple_targets.rb]) expect(result.stderr).to eq "" slines = lines(result.stdout) verify_lines(slines, [ @@ -459,7 +446,7 @@ EOF expect(nr(`./program.exe`)).to eq "The value is 42\n" File.open("inc.c", "w") {|fh| fh.puts "int THE_VALUE = 33;"} - result = run_rscons(rsconscript: "multiple_targets.rb") + result = run_rscons(args: %w[-f multiple_targets.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{CHGen inc.c}]) expect(nr(`./program.exe`)).to eq "The value is 42\n" @@ -467,21 +454,21 @@ EOF it 'raises an error when a custom builder returns an invalid value from #run' do test_dir("custom_builder") - result = run_rscons(rsconscript: "error_run_return_value.rb") + result = run_rscons(args: %w[-f error_run_return_value.rb]) expect(result.stderr).to match /Unrecognized MyBuilder builder return value: "hi"/ expect(result.status).to_not eq 0 end it 'raises an error when a custom builder returns an invalid value using Builder#wait_for' do test_dir("custom_builder") - result = run_rscons(rsconscript: "error_wait_for.rb") + result = run_rscons(args: %w[-f error_wait_for.rb]) expect(result.stderr).to match /Unrecognized MyBuilder builder return item: 1/ expect(result.status).to_not eq 0 end it 'supports a Builder waiting for a custom Thread object' do test_dir "custom_builder" - result = run_rscons(rsconscript: "wait_for_thread.rb") + result = run_rscons(args: %w[-f wait_for_thread.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 verify_lines(lines(result.stdout), [%r{MyBuilder foo}]) @@ -490,7 +477,7 @@ EOF it 'supports a Builder waiting for another Builder' do test_dir "simple" - result = run_rscons(rsconscript: "builder_wait_for_builder.rb") + result = run_rscons(args: %w[-f builder_wait_for_builder.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 verify_lines(lines(result.stdout), [%r{MyObject simple.o}]) @@ -512,7 +499,7 @@ EOF it 'clones all attributes of an Environment object by default' do test_dir('clone_env') - result = run_rscons(rsconscript: "clone_all.rb") + result = run_rscons(args: %w[-f clone_all.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{gcc -c -o build/e.1/src/program.c.o -MMD -MF build/e.1/src/program.c.o.mf -DSTRING="Hello" -O2 src/program.c}, @@ -535,7 +522,7 @@ EOF it "links with the C++ linker when object files were built from C++ sources" do test_dir("simple_cc") - result = run_rscons(rsconscript: "link_objects.rb") + result = run_rscons(args: %w[-f link_objects.rb]) expect(result.stderr).to eq "" expect(File.exists?("simple.o")).to be_truthy expect(nr(`./simple.exe`)).to eq "This is a simple C++ program\n" @@ -571,7 +558,7 @@ EOF it 'supports build hooks to override construction variables' do test_dir("typical") - result = run_rscons(rsconscript: "build_hooks.rb") + result = run_rscons(args: %w[-f build_hooks.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{gcc -c -o build/e.1/src/one/one.c.o -MMD -MF build/e.1/src/one/one.c.o.mf -Isrc/one -Isrc/two -O1 src/one/one.c}, @@ -583,7 +570,7 @@ EOF it 'supports build hooks to override the entire vars hash' do test_dir("typical") - result = run_rscons(rsconscript: "build_hooks_override_vars.rb") + result = run_rscons(args: %w[-f build_hooks_override_vars.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{gcc -c -o one.o -MMD -MF build/e.1/one.o.mf -Isrc -Isrc/one -Isrc/two -O1 src/two/two.c}, @@ -597,7 +584,7 @@ EOF test_dir('simple') File.open("program.ld", "w") {|fh| fh.puts("1")} - result = run_rscons(rsconscript: "user_dependencies.rb") + result = run_rscons(args: %w[-f user_dependencies.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling simple.c}, @@ -607,16 +594,16 @@ EOF expect(nr(`./simple.exe`)).to eq "This is a simple C program\n" File.open("program.ld", "w") {|fh| fh.puts("2")} - result = run_rscons(rsconscript: "user_dependencies.rb") + result = run_rscons(args: %w[-f user_dependencies.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Linking simple.exe}]) File.unlink("program.ld") - result = run_rscons(rsconscript: "user_dependencies.rb") + result = run_rscons(args: %w[-f user_dependencies.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Linking simple.exe}]) - result = run_rscons(rsconscript: "user_dependencies.rb") + result = run_rscons(args: %w[-f user_dependencies.rb]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" end @@ -625,7 +612,7 @@ EOF test_dir("simple") passenv["file_contents"] = "1" - result = run_rscons(rsconscript: "user_dependencies_carat.rb") + result = run_rscons(args: %w[-f user_dependencies_carat.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling simple.c}, @@ -633,11 +620,11 @@ EOF ]) passenv["file_contents"] = "2" - result = run_rscons(rsconscript: "user_dependencies_carat.rb") + result = run_rscons(args: %w[-f user_dependencies_carat.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Linking .*simple.exe}]) - result = run_rscons(rsconscript: "user_dependencies_carat.rb") + result = run_rscons(args: %w[-f user_dependencies_carat.rb]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" end @@ -657,7 +644,7 @@ EOF it "supports building D sources with ldc2" do test_dir("d") - result = run_rscons(rsconscript: "build-ldc2.rb") + result = run_rscons(args: %w[-f build-ldc2.rb]) expect(result.stderr).to eq "" slines = lines(result.stdout) verify_lines(slines, [%r{ldc2 -c -of build/e.1/main.d.o(bj)? -deps=build/e.1/main.d.o(bj)?.mf main.d}]) @@ -668,7 +655,7 @@ EOF it "rebuilds D modules with ldc2 when deep dependencies change" do test_dir("d") - result = run_rscons(rsconscript: "build-ldc2.rb") + result = run_rscons(args: %w[-f build-ldc2.rb]) expect(result.stderr).to eq "" slines = lines(result.stdout) verify_lines(slines, [%r{ldc2 -c -of build/e.1/main.d.o(bj)? -deps=build/e.1/main.d.o(bj)?.mf main.d}]) @@ -679,7 +666,7 @@ EOF File.open("mod.d", "wb") do |fh| fh.write(contents) end - result = run_rscons(rsconscript: "build-ldc2.rb") + result = run_rscons(args: %w[-f build-ldc2.rb]) expect(result.stderr).to eq "" slines = lines(result.stdout) verify_lines(slines, [%r{ldc2 -c -of build/e.1/main.d.o(bj)? -deps=build/e.1/main.d.o(bj)?.mf main.d}]) @@ -691,7 +678,7 @@ EOF unless RUBY_PLATFORM =~ /mingw|msys/ it "links with the D linker when object files were built from D sources" do test_dir("d") - result = run_rscons(rsconscript: "link_objects.rb") + result = run_rscons(args: %w[-f link_objects.rb]) expect(result.stderr).to eq "" expect(File.exists?("main.o")).to be_truthy expect(File.exists?("mod.o")).to be_truthy @@ -721,7 +708,7 @@ EOF it "creates shared libraries using D" do test_dir("shared_library") - result = run_rscons(rsconscript: "shared_library_d.rb") + result = run_rscons(args: %w[-f shared_library_d.rb]) expect(result.stderr).to eq "" slines = lines(result.stdout) if RUBY_PLATFORM =~ /mingw|msys/ @@ -735,19 +722,19 @@ EOF it "supports disassembling object files" do test_dir("simple") - result = run_rscons(rsconscript: "disassemble.rb") + result = run_rscons(args: %w[-f disassemble.rb]) expect(result.stderr).to eq "" expect(File.exists?("simple.txt")).to be_truthy expect(File.read("simple.txt")).to match /Disassembly of section .text:/ - result = run_rscons(rsconscript: "disassemble.rb") + result = run_rscons(args: %w[-f disassemble.rb]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" end it "supports preprocessing C sources" do test_dir("simple") - result = run_rscons(rsconscript: "preprocess.rb") + result = run_rscons(args: %w[-f preprocess.rb]) expect(result.stderr).to eq "" expect(File.read("simplepp.c")).to match /# \d+ "simple.c"/ expect(nr(`./simple.exe`)).to eq "This is a simple C program\n" @@ -755,7 +742,7 @@ EOF it "supports preprocessing C++ sources" do test_dir("simple_cc") - result = run_rscons(rsconscript: "preprocess.rb") + result = run_rscons(args: %w[-f preprocess.rb]) expect(result.stderr).to eq "" expect(File.read("simplepp.cc")).to match /# \d+ "simple.cc"/ expect(nr(`./simple.exe`)).to eq "This is a simple C++ program\n" @@ -763,13 +750,13 @@ EOF it "supports invoking builders with no sources" do test_dir("simple") - result = run_rscons(rsconscript: "builder_no_sources.rb") + result = run_rscons(args: %w[-f builder_no_sources.rb]) expect(result.stderr).to eq "" end it "expands construction variables in builder target and sources before invoking the builder" do test_dir('custom_builder') - result = run_rscons(rsconscript: "cvar_expansion.rb") + result = run_rscons(args: %w[-f cvar_expansion.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling program.c}, @@ -781,14 +768,14 @@ EOF it "supports lambdas as construction variable values" do test_dir "custom_builder" - result = run_rscons(rsconscript: "cvar_lambda.rb") + result = run_rscons(args: %w[-f cvar_lambda.rb]) expect(result.stderr).to eq "" expect(nr(`./program.exe`)).to eq "The value is 5678\n" end it "supports registering build targets from within a build hook" do test_dir("simple") - result = run_rscons(rsconscript: "register_target_in_build_hook.rb") + result = run_rscons(args: %w[-f register_target_in_build_hook.rb]) expect(result.stderr).to eq "" expect(File.exists?("build/e.1/simple.c.o")).to be_truthy expect(File.exists?("build/e.1/simple.c.o.txt")).to be_truthy @@ -798,7 +785,7 @@ EOF it "supports multiple values for CXXSUFFIX" do test_dir("simple_cc") File.open("other.cccc", "w") {|fh| fh.puts} - result = run_rscons(rsconscript: "cxxsuffix.rb") + result = run_rscons(args: %w[-f cxxsuffix.rb]) expect(result.stderr).to eq "" expect(File.exists?("build/e.1/simple.cc.o")).to be_truthy expect(File.exists?("build/e.1/other.cccc.o")).to be_truthy @@ -808,7 +795,7 @@ EOF it "supports multiple values for CSUFFIX" do test_dir("typical") FileUtils.mv("src/one/one.c", "src/one/one.yargh") - result = run_rscons(rsconscript: "csuffix.rb") + result = run_rscons(args: %w[-f csuffix.rb]) expect(result.stderr).to eq "" expect(File.exists?("build/e.1/src/one/one.yargh.o")).to be_truthy expect(File.exists?("build/e.1/src/two/two.c.o")).to be_truthy @@ -817,7 +804,7 @@ EOF it "supports multiple values for OBJSUFFIX" do test_dir("two_sources") - result = run_rscons(rsconscript: "objsuffix.rb") + result = run_rscons(args: %w[-f objsuffix.rb]) expect(result.stderr).to eq "" expect(File.exists?("two_sources.exe")).to be_truthy expect(File.exists?("one.oooo")).to be_truthy @@ -827,7 +814,7 @@ EOF it "supports multiple values for LIBSUFFIX" do test_dir("two_sources") - result = run_rscons(rsconscript: "libsuffix.rb") + result = run_rscons(args: %w[-f libsuffix.rb]) expect(result.stderr).to eq "" expect(File.exists?("two_sources.exe")).to be_truthy expect(nr(`./two_sources.exe`)).to eq "This is a C program with two sources.\n" @@ -835,7 +822,7 @@ EOF it "supports multiple values for ASSUFFIX" do test_dir("two_sources") - result = run_rscons(rsconscript: "assuffix.rb") + result = run_rscons(args: %w[-f assuffix.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling one.c}, @@ -850,7 +837,7 @@ EOF it "supports dumping an Environment's construction variables" do test_dir("simple") - result = run_rscons(rsconscript: "dump.rb") + result = run_rscons(args: %w[-f dump.rb]) expect(result.stderr).to eq "" slines = lines(result.stdout) expect(slines.include?(%{:foo => :bar})).to be_truthy @@ -881,7 +868,7 @@ EOF it "allows construction variable references which expand to arrays in sources of a build target" do test_dir("simple") - result = run_rscons(rsconscript: "cvar_array.rb") + result = run_rscons(args: %w[-f cvar_array.rb]) expect(result.stderr).to eq "" expect(File.exists?("build/e.1/simple.c.o")).to be_truthy expect(nr(`./simple.exe`)).to eq "This is a simple C program\n" @@ -889,7 +876,7 @@ EOF it "supports registering multiple build targets with the same target path" do test_dir("typical") - result = run_rscons(rsconscript: "multiple_targets_same_name.rb") + result = run_rscons(args: %w[-f multiple_targets_same_name.rb]) expect(result.stderr).to eq "" expect(File.exists?("one.o")).to be_truthy verify_lines(lines(result.stdout), [ @@ -900,7 +887,7 @@ EOF it "expands target and source paths when builders are registered in build hooks" do test_dir("typical") - result = run_rscons(rsconscript: "post_build_hook_expansion.rb") + result = run_rscons(args: %w[-f post_build_hook_expansion.rb]) expect(result.stderr).to eq "" expect(File.exists?("one.o")).to be_truthy expect(File.exists?("two.o")).to be_truthy @@ -915,15 +902,13 @@ EOF File.open("two.c", "w") do |fh| fh.puts("FOO") end - result = run_rscons(rsconscript: "cache_successful_builds_when_one_fails.rb", - rscons_args: %w[-j1]) + result = run_rscons(args: %w[-f cache_successful_builds_when_one_fails.rb -j1]) expect(result.stderr).to match /FOO/ expect(File.exists?("simple.o")).to be_truthy expect(File.exists?("two.o")).to be_falsey File.open("two.c", "w") {|fh|} - result = run_rscons(rsconscript: "cache_successful_builds_when_one_fails.rb", - rscons_args: %w[-j1]) + result = run_rscons(args: %w[-f cache_successful_builds_when_one_fails.rb -j1]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling two.c}, @@ -932,7 +917,7 @@ EOF it "allows overriding PROGSUFFIX" do test_dir("simple") - result = run_rscons(rsconscript: "progsuffix.rb") + result = run_rscons(args: %w[-f progsuffix.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling simple.c}, @@ -942,7 +927,7 @@ EOF it "does not use PROGSUFFIX when the Program target name expands to a value already containing an extension" do test_dir("simple") - result = run_rscons(rsconscript: "progsuffix2.rb") + result = run_rscons(args: %w[-f progsuffix2.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling simple.c}, @@ -952,7 +937,7 @@ EOF it "allows overriding PROGSUFFIX from extra vars passed in to the builder" do test_dir("simple") - result = run_rscons(rsconscript: "progsuffix3.rb") + result = run_rscons(args: %w[-f progsuffix3.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling simple.c}, @@ -962,7 +947,7 @@ EOF it "creates object files under the build root for absolute source paths" do test_dir("simple") - result = run_rscons(rsconscript: "absolute_source_path.rb") + result = run_rscons(args: %w[-f absolute_source_path.rb]) expect(result.stderr).to eq "" slines = lines(result.stdout) verify_lines(slines, [%r{build/e.1/.*/abs\.c.o$}]) @@ -995,7 +980,7 @@ EOF it "creates shared libraries using assembly" do test_dir("shared_library") - result = run_rscons(rsconscript: "shared_library_as.rb") + result = run_rscons(args: %w[-f shared_library_as.rb]) expect(result.stderr).to eq "" expect(File.exists?("file.S")).to be_truthy end @@ -1003,7 +988,7 @@ EOF it "creates shared libraries using C++" do test_dir("shared_library") - result = run_rscons(rsconscript: "shared_library_cxx.rb") + result = run_rscons(args: %w[-f shared_library_cxx.rb]) expect(result.stderr).to eq "" slines = lines(result.stdout) if RUBY_PLATFORM =~ /mingw|msys/ @@ -1012,7 +997,7 @@ EOF verify_lines(slines, [%r{Linking libmine.so}]) end - result = run_rscons(rsconscript: "shared_library_cxx.rb") + result = run_rscons(args: %w[-f shared_library_cxx.rb]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" @@ -1023,27 +1008,27 @@ EOF it "raises an error for a circular dependency" do test_dir("simple") - result = run_rscons(rsconscript: "error_circular_dependency.rb") + result = run_rscons(args: %w[-f error_circular_dependency.rb]) expect(result.stderr).to match /Possible circular dependency for (foo|bar|baz)/ expect(result.status).to_not eq 0 end it "raises an error for a circular dependency where a build target contains itself in its source list" do test_dir("simple") - result = run_rscons(rsconscript: "error_circular_dependency2.rb") + result = run_rscons(args: %w[-f error_circular_dependency2.rb]) expect(result.stderr).to match /Possible circular dependency for foo/ expect(result.status).to_not eq 0 end it "orders builds to respect user dependencies" do test_dir("simple") - result = run_rscons(rsconscript: "user_dep_build_order.rb", rscons_args: %w[-j4]) + result = run_rscons(args: %w[-f user_dep_build_order.rb -j4]) expect(result.stderr).to eq "" end it "waits for all parallelized builds to complete if one fails" do test_dir("simple") - result = run_rscons(rsconscript: "wait_for_builds_on_failure.rb", rscons_args: %w[-j4]) + result = run_rscons(args: %w[-f wait_for_builds_on_failure.rb -j4]) expect(result.status).to_not eq 0 expect(result.stderr).to match /Failed to build foo_1/ expect(result.stderr).to match /Failed to build foo_2/ @@ -1053,7 +1038,7 @@ EOF it "clones n_threads attribute when cloning an Environment" do test_dir("simple") - result = run_rscons(rsconscript: "clone_n_threads.rb") + result = run_rscons(args: %w[-f clone_n_threads.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [/165/]) end @@ -1061,7 +1046,7 @@ EOF it "prints a builder's short description with 'command' echo mode if there is no command" do test_dir("typical") - result = run_rscons(rsconscript: "echo_command_ruby_builder.rb") + result = run_rscons(args: %w[-f echo_command_ruby_builder.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Copy echo_command_ruby_builder.rb => copy.rb}]) end @@ -1069,7 +1054,7 @@ EOF it "supports a string for a builder's echoed 'command' with Environment#print_builder_run_message" do test_dir("typical") - result = run_rscons(rsconscript: "echo_command_string.rb") + result = run_rscons(args: %w[-f echo_command_string.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{MyBuilder foo command}]) end @@ -1086,7 +1071,7 @@ EOF expect(result.stderr).to match %r{^Use .*/rscons(\.rb)? -F.*to view the failed command log} expect(result.status).to_not eq 0 - result = run_rscons(rscons_args: %w[-F]) + result = run_rscons(args: %w[-F]) expect(result.stderr).to eq "" expect(result.stdout).to match %r{Failed command \(1/1\):} expect(result.stdout).to match %r{^gcc -} @@ -1104,7 +1089,7 @@ EOF it "names Environment during clone" do test_dir "typical" - result = run_rscons(rsconscript: "clone_and_name.rb") + result = run_rscons(args: %w[-f clone_and_name.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/e.1")).to be_falsey @@ -1113,7 +1098,7 @@ EOF context "colored output" do it "does not output in color with --color=off" do test_dir("simple") - result = run_rscons(rscons_args: %w[--color=off]) + result = run_rscons(args: %w[--color=off]) expect(result.stderr).to eq "" expect(result.stdout).to_not match(/\e\[/) end @@ -1121,14 +1106,14 @@ EOF it "displays output in color with --color=force" do test_dir("simple") - result = run_rscons(rscons_args: %w[--color=force]) + result = run_rscons(args: %w[--color=force]) expect(result.stderr).to eq "" expect(result.stdout).to match(/\e\[/) File.open("simple.c", "wb") do |fh| fh.write("foobar") end - result = run_rscons(rscons_args: %w[--color=force]) + result = run_rscons(args: %w[--color=force]) expect(result.stderr).to match(/\e\[/) end end @@ -1151,7 +1136,7 @@ EOF it "raises an error when an unknown source file is specified" do test_dir("cfile") - result = run_rscons(rsconscript: "error_unknown_extension.rb") + result = run_rscons(args: %w[-f error_unknown_extension.rb]) expect(result.stderr).to match /Unknown source file .foo.bar. for CFile builder/ expect(result.status).to_not eq 0 end @@ -1161,12 +1146,12 @@ EOF it "allows executing an arbitrary command" do test_dir('simple') - result = run_rscons(rsconscript: "command_builder.rb") + result = run_rscons(args: %w[-f command_builder.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{BuildIt simple.exe}]) expect(nr(`./simple.exe`)).to eq "This is a simple C program\n" - result = run_rscons(rsconscript: "command_builder.rb") + result = run_rscons(args: %w[-f command_builder.rb]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" end @@ -1174,7 +1159,7 @@ EOF it "allows redirecting standard output to a file" do test_dir("simple") - result = run_rscons(rsconscript: "command_redirect.rb") + result = run_rscons(args: %w[-f command_redirect.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling simple.c}, @@ -1187,7 +1172,7 @@ EOF context "Directory builder" do it "creates the requested directory" do test_dir("simple") - result = run_rscons(rsconscript: "directory.rb") + result = run_rscons(args: %w[-f directory.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Creating directory teh_dir}]) expect(File.directory?("teh_dir")).to be_truthy @@ -1196,7 +1181,7 @@ EOF it "succeeds when the requested directory already exists" do test_dir("simple") FileUtils.mkdir("teh_dir") - result = run_rscons(rsconscript: "directory.rb") + result = run_rscons(args: %w[-f directory.rb]) expect(result.stderr).to eq "" expect(lines(result.stdout)).to_not include a_string_matching /Creating directory/ expect(File.directory?("teh_dir")).to be_truthy @@ -1205,7 +1190,7 @@ EOF it "fails when the target path is a file" do test_dir("simple") FileUtils.touch("teh_dir") - result = run_rscons(rsconscript: "directory.rb") + result = run_rscons(args: %w[-f directory.rb]) expect(result.stderr).to match %r{Error: `teh_dir' already exists and is not a directory} end end @@ -1214,11 +1199,11 @@ EOF it "copies a file to the target file name" do test_dir("typical") - result = run_rscons(rsconscript: "copy.rb") + result = run_rscons(args: %w[-f copy.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Copy copy.rb => inst.exe}]) - result = run_rscons(rsconscript: "copy.rb") + result = run_rscons(args: %w[-f copy.rb]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" @@ -1226,7 +1211,7 @@ EOF expect(File.read("inst.exe", mode: "rb")).to eq(File.read("copy.rb", mode: "rb")) FileUtils.rm("inst.exe") - result = run_rscons(rsconscript: "copy.rb") + result = run_rscons(args: %w[-f copy.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Copy copy.rb => inst.exe}]) end @@ -1234,11 +1219,11 @@ EOF it "copies multiple files to the target directory name" do test_dir("typical") - result = run_rscons(rsconscript: "copy_multiple.rb") + result = run_rscons(args: %w[-f copy_multiple.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Copy copy.rb \(\+1\) => dest}]) - result = run_rscons(rsconscript: "copy_multiple.rb") + result = run_rscons(args: %w[-f copy_multiple.rb]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" @@ -1247,7 +1232,7 @@ EOF expect(File.exists?("dest/copy_multiple.rb")).to be_truthy FileUtils.rm_rf("dest") - result = run_rscons(rsconscript: "copy_multiple.rb") + result = run_rscons(args: %w[-f copy_multiple.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Copy copy.rb \(\+1\) => dest}]) end @@ -1255,20 +1240,20 @@ EOF it "copies a file to the target directory name" do test_dir("typical") - result = run_rscons(rsconscript: "copy_directory.rb") + result = run_rscons(args: %w[-f copy_directory.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Copy copy_directory.rb => copy}]) expect(File.exists?("copy/copy_directory.rb")).to be_truthy expect(File.read("copy/copy_directory.rb", mode: "rb")).to eq(File.read("copy_directory.rb", mode: "rb")) - result = run_rscons(rsconscript: "copy_directory.rb") + result = run_rscons(args: %w[-f copy_directory.rb]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" end it "copies a directory to the non-existent target directory name" do test_dir("typical") - result = run_rscons(rsconscript: "copy_directory.rb") + result = run_rscons(args: %w[-f copy_directory.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Copy src => noexist/src}]) %w[src/one/one.c src/two/two.c src/two/two.h].each do |f| @@ -1279,7 +1264,7 @@ EOF it "copies a directory to the existent target directory name" do test_dir("typical") - result = run_rscons(rsconscript: "copy_directory.rb") + result = run_rscons(args: %w[-f copy_directory.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Copy src => exist/src}]) %w[src/one/one.c src/two/two.c src/two/two.h].each do |f| @@ -1293,7 +1278,7 @@ EOF it "allows specifying a Symbol as a target name and reruns the builder if the sources or command have changed" do test_dir("simple") - result = run_rscons(rsconscript: "phony_target.rb") + result = run_rscons(args: %w[-f phony_target.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling simple.c}, @@ -1301,7 +1286,7 @@ EOF %r{Checker simple.exe}, ]) - result = run_rscons(rsconscript: "phony_target.rb") + result = run_rscons(args: %w[-f phony_target.rb]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" @@ -1310,7 +1295,7 @@ EOF File.open("simple.exe", "w") do |fh| fh.puts "Changed simple.exe" end - result = run_rscons(rsconscript: "phony_target2.rb") + result = run_rscons(args: %w[-f phony_target2.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Checker simple.exe}, @@ -1321,7 +1306,7 @@ EOF context "Environment#clear_targets" do it "clears registered targets" do test_dir("simple") - result = run_rscons(rsconscript: "clear_targets.rb") + result = run_rscons(args: %w[-f clear_targets.rb]) expect(result.stderr).to eq "" expect(lines(result.stdout)).to_not include a_string_matching %r{Linking} end @@ -1381,7 +1366,7 @@ EOF %r{Linking simple.exe}, ]) - result = run_rscons(rsconscript: "cache_command_change.rb") + result = run_rscons(args: %w[-f cache_command_change.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Linking simple.exe}, @@ -1391,14 +1376,14 @@ EOF it "forces a build when there is a new dependency" do test_dir("simple") - result = run_rscons(rsconscript: "cache_new_dep1.rb") + result = run_rscons(args: %w[-f cache_new_dep1.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling simple.c}, %r{Linking simple.exe}, ]) - result = run_rscons(rsconscript: "cache_new_dep2.rb") + result = run_rscons(args: %w[-f cache_new_dep2.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Linking simple.exe}, @@ -1408,14 +1393,14 @@ EOF it "forces a build when a dependency's checksum has changed" do test_dir("simple") - result = run_rscons(rsconscript: "cache_dep_checksum_change.rb") + result = run_rscons(args: %w[-f cache_dep_checksum_change.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Copy simple.c => simple.copy}]) File.open("simple.c", "wb") do |fh| fh.write("hi") end - result = run_rscons(rsconscript: "cache_dep_checksum_change.rb") + result = run_rscons(args: %w[-f cache_dep_checksum_change.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{Copy simple.c => simple.copy}]) end @@ -1426,18 +1411,18 @@ EOF File.open("sources", "wb") do |fh| fh.write("one.o two.o") end - result = run_rscons(rsconscript: "cache_strict_deps.rb") + result = run_rscons(args: %w[-f cache_strict_deps.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{gcc -o program.exe one.o two.o}]) - result = run_rscons(rsconscript: "cache_strict_deps.rb") + result = run_rscons(args: %w[-f cache_strict_deps.rb]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" File.open("sources", "wb") do |fh| fh.write("two.o one.o") end - result = run_rscons(rsconscript: "cache_strict_deps.rb") + result = run_rscons(args: %w[-f cache_strict_deps.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{gcc -o program.exe one.o two.o}]) end @@ -1447,7 +1432,7 @@ EOF File.open("foo", "wb") {|fh| fh.write("hi")} File.open("user_deps", "wb") {|fh| fh.write("")} - result = run_rscons(rsconscript: "cache_user_dep.rb") + result = run_rscons(args: %w[-f cache_user_dep.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling simple.c}, @@ -1455,7 +1440,7 @@ EOF ]) File.open("user_deps", "wb") {|fh| fh.write("foo")} - result = run_rscons(rsconscript: "cache_user_dep.rb") + result = run_rscons(args: %w[-f cache_user_dep.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Linking simple.exe}, @@ -1467,19 +1452,19 @@ EOF File.open("foo", "wb") {|fh| fh.write("hi")} File.open("user_deps", "wb") {|fh| fh.write("foo")} - result = run_rscons(rsconscript: "cache_user_dep.rb") + result = run_rscons(args: %w[-f cache_user_dep.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Compiling simple.c}, %r{Linking simple.exe}, ]) - result = run_rscons(rsconscript: "cache_user_dep.rb") + result = run_rscons(args: %w[-f cache_user_dep.rb]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" File.open("foo", "wb") {|fh| fh.write("hi2")} - result = run_rscons(rsconscript: "cache_user_dep.rb") + result = run_rscons(args: %w[-f cache_user_dep.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Linking simple.exe}, @@ -1488,12 +1473,12 @@ EOF it "allows a VarSet to be passed in as the command parameter" do test_dir("simple") - result = run_rscons(rsconscript: "cache_varset.rb") + result = run_rscons(args: %w[-f cache_varset.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{TestBuilder foo}, ]) - result = run_rscons(rsconscript: "cache_varset.rb") + result = run_rscons(args: %w[-f cache_varset.rb]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" end @@ -1512,7 +1497,7 @@ EOF it "allows prepending and appending to PATH" do test_dir "simple" - result = run_rscons(rsconscript: "pathing.rb") + result = run_rscons(args: %w[-f pathing.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match /flex!/ expect(result.stdout).to match /foobar!/ @@ -1521,7 +1506,7 @@ EOF it "writes the dependency file to the build root" do test_dir "simple" - result = run_rscons(rsconscript: "distclean.rb") + result = run_rscons(args: %w[-f distclean.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match /Compiling simple\.c/ expect(File.exist?("simple.o")).to be_truthy @@ -1532,7 +1517,7 @@ EOF context "debugging" do it "prints a message when the target does not exist" do test_dir("simple") - result = run_rscons(rsconscript: "cache_debugging.rb") + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match /Target foo\.o needs rebuilding because it does not exist on disk/ end @@ -1540,67 +1525,72 @@ EOF it "prints a message when there is no cached build information for the target" do test_dir("simple") FileUtils.touch("foo.o") - result = run_rscons(rsconscript: "cache_debugging.rb") + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match /Target foo\.o needs rebuilding because there is no cached build information for it/ end it "prints a message when the target file has changed on disk" do test_dir("simple") - result = run_rscons(rsconscript: "cache_debugging.rb") + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" File.open("foo.o", "wb") {|fh| fh.puts "hi"} - result = run_rscons(rsconscript: "cache_debugging.rb") + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match /Target foo\.o needs rebuilding because it has been changed on disk since being built last/ end it "prints a message when the command has changed" do test_dir("simple") - result = run_rscons(rsconscript: "cache_debugging.rb") + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "cache_debugging.rb", op: %w[build command_change=yes]) + passenv["test"] = "command_change" + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match /Target foo\.o needs rebuilding because the command used to build it has changed/ end it "prints a message when strict_deps is in use and the set of dependencies does not match" do test_dir("simple") - result = run_rscons(rsconscript: "cache_debugging.rb", op: %w[build strict_deps1=yes]) + passenv["test"] = "strict_deps1" + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "cache_debugging.rb", op: %w[build strict_deps2=yes]) + passenv["test"] = "strict_deps2" + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match /Target foo\.o needs rebuilding because the :strict_deps option is given and the set of dependencies does not match the previous set of dependencies/ end it "prints a message when there is a new dependency" do test_dir("simple") - result = run_rscons(rsconscript: "cache_debugging.rb") + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "cache_debugging.rb", op: %w[build new_dep=yes]) + passenv["test"] = "new_dep" + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match /Target foo\.o needs rebuilding because there are new dependencies/ end it "prints a message when there is a new user-specified dependency" do test_dir("simple") - result = run_rscons(rsconscript: "cache_debugging.rb") + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "cache_debugging.rb", op: %w[build new_user_dep=yes]) + passenv["test"] = "new_user_dep" + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match /Target foo\.o needs rebuilding because the set of user-specified dependency files has changed/ end it "prints a message when a dependency file has changed" do test_dir("simple") - result = run_rscons(rsconscript: "cache_debugging.rb") + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" f = File.read("simple.c", mode: "rb") f += "\n" File.open("simple.c", "wb") do |fh| fh.write(f) end - result = run_rscons(rsconscript: "cache_debugging.rb") + result = run_rscons(args: %w[-f cache_debugging.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match /Target foo\.o needs rebuilding because dependency file simple\.c has changed/ end @@ -1610,7 +1600,7 @@ EOF context "Object builder" do it "allows overriding CCCMD construction variable" do test_dir("simple") - result = run_rscons(rsconscript: "override_cccmd.rb") + result = run_rscons(args: %w[-f override_cccmd.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{gcc -c -o simple.o -Dfoobar simple.c}, @@ -1619,7 +1609,7 @@ EOF it "allows overriding DEPFILESUFFIX construction variable" do test_dir("simple") - result = run_rscons(rsconscript: "override_depfilesuffix.rb") + result = run_rscons(args: %w[-f override_depfilesuffix.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{gcc -c -o simple.o -MMD -MF build/e.1/simple.o.deppy simple.c}, @@ -1628,7 +1618,7 @@ EOF it "raises an error when given a source file with an unknown suffix" do test_dir("simple") - result = run_rscons(rsconscript: "error_unknown_suffix.rb") + result = run_rscons(args: %w[-f error_unknown_suffix.rb]) expect(result.stderr).to match /Unknown input file type: "foo.xyz"/ end end @@ -1636,7 +1626,7 @@ EOF context "SharedObject builder" do it "raises an error when given a source file with an unknown suffix" do test_dir("shared_library") - result = run_rscons(rsconscript: "error_unknown_suffix.rb") + result = run_rscons(args: %w[-f error_unknown_suffix.rb]) expect(result.stderr).to match /Unknown input file type: "foo.xyz"/ end end @@ -1644,14 +1634,14 @@ EOF context "Library builder" do it "allows overriding ARCMD construction variable" do test_dir("library") - result = run_rscons(rsconscript: "override_arcmd.rb") + result = run_rscons(args: %w[-f override_arcmd.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [%r{ar rcf lib.a build/e.1/one.c.o build/e.1/three.c.o build/e.1/two.c.o}]) end it "allows passing object files as sources" do test_dir("library") - result = run_rscons(rsconscript: "library_from_object.rb") + result = run_rscons(args: %w[-f library_from_object.rb]) expect(result.stderr).to eq "" expect(File.exists?("two.o")).to be_truthy verify_lines(lines(result.stdout), [%r{Building static library archive lib.a}]) @@ -1662,7 +1652,7 @@ EOF it "allows explicitly specifying SHLD construction variable value" do test_dir("shared_library") - result = run_rscons(rsconscript: "shared_library_set_shld.rb") + result = run_rscons(args: %w[-f shared_library_set_shld.rb]) expect(result.stderr).to eq "" slines = lines(result.stdout) if RUBY_PLATFORM =~ /mingw|msys/ @@ -1674,7 +1664,7 @@ EOF it "allows passing object files as sources" do test_dir "shared_library" - result = run_rscons(rsconscript: "shared_library_from_object.rb") + result = run_rscons(args: %w[-f shared_library_from_object.rb]) expect(result.stderr).to eq "" expect(File.exists?("one.c.o")) end @@ -1684,7 +1674,7 @@ EOF it "generates a size file" do test_dir "simple" - result = run_rscons(rsconscript: "size.rb") + result = run_rscons(args: %w[-f size.rb]) verify_lines(lines(result.stdout), [ /Linking .*simple\.exe/, /Size .*simple\.exe .*simple\.size/, @@ -1699,7 +1689,7 @@ EOF it "waits for subcommands in threads for builders that support threaded commands" do test_dir("simple") start_time = Time.new - result = run_rscons(rsconscript: "threading.rb", rscons_args: %w[-j 4]) + result = run_rscons(args: %w[-f threading.rb -j 4]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{ThreadedTestBuilder a}, @@ -1713,20 +1703,20 @@ EOF it "allows the user to specify that a target be built after another" do test_dir("custom_builder") - result = run_rscons(rsconscript: "build_after.rb", rscons_args: %w[-j 4]) + result = run_rscons(args: %w[-f build_after.rb -j 4]) expect(result.stderr).to eq "" end it "allows the user to specify side-effect files produced by another builder with Builder#produces" do test_dir("custom_builder") - result = run_rscons(rsconscript: "produces.rb", rscons_args: %w[-j 4]) + result = run_rscons(args: %w[-f produces.rb -j 4]) expect(result.stderr).to eq "" expect(File.exists?("copy_inc.h")).to be_truthy end it "allows the user to specify side-effect files produced by another builder with Environment#produces" do test_dir("custom_builder") - result = run_rscons(rsconscript: "produces_env.rb", rscons_args: %w[-j 4]) + result = run_rscons(args: %w[-f produces_env.rb -j 4]) expect(result.stderr).to eq "" expect(File.exists?("copy_inc.h")).to be_truthy end @@ -1735,7 +1725,7 @@ EOF context "CLI" do it "shows the version number and exits with --version argument" do test_dir("simple") - result = run_rscons(rscons_args: %w[--version]) + result = run_rscons(args: %w[--version]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /version #{Rscons::VERSION}/ @@ -1743,7 +1733,7 @@ EOF it "shows CLI help and exits with --help argument" do test_dir("simple") - result = run_rscons(rscons_args: %w[--help]) + result = run_rscons(args: %w[--help]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Usage:/ @@ -1759,21 +1749,21 @@ EOF it "prints an error and exits with an error status when the given Rsconscript cannot be read" do test_dir("simple") - result = run_rscons(rsconscript: "nonexistent") + result = run_rscons(args: %w[-f nonexistent]) expect(result.stderr).to match /Cannot read nonexistent/ expect(result.status).to_not eq 0 end - it "outputs an error for an unknown operation" do + it "outputs an error for an unknown task" do test_dir "simple" - result = run_rscons(op: "unknownop") - expect(result.stderr).to match /Unknown operation: unknownop/ + result = run_rscons(args: "unknownop") + expect(result.stderr).to match /Task 'unknownop' not found/ expect(result.status).to_not eq 0 end it "displays usage and error message without a backtrace for an invalid CLI option" do test_dir "simple" - result = run_rscons(rscons_args: %w[--xyz]) + result = run_rscons(args: %w[--xyz]) expect(result.stderr).to_not match /Traceback/ expect(result.stderr).to match /invalid option.*--xyz/ expect(result.stderr).to match /Usage:/ @@ -1782,9 +1772,9 @@ EOF it "displays usage and error message without a backtrace for an invalid CLI option to a valid subcommand" do test_dir "simple" - result = run_rscons(op: %w[configure --xyz]) + result = run_rscons(args: %w[configure --xyz]) expect(result.stderr).to_not match /Traceback/ - expect(result.stderr).to match /invalid option.*--xyz/ + expect(result.stderr).to match /Invalid task 'configure' argument.*--xyz/ expect(result.stderr).to match /Usage:/ expect(result.status).to_not eq 0 end @@ -1793,7 +1783,7 @@ EOF context "configure operation" do it "raises a method not found error for configure methods called outside a configure block" do test_dir "configure" - result = run_rscons(rsconscript: "scope.rb") + result = run_rscons(args: %w[-f scope.rb]) expect(result.stderr).to match /NoMethodError/ expect(result.status).to_not eq 0 end @@ -1801,13 +1791,13 @@ EOF it "automatically runs the configure operation if the project is not yet configured in the given build directory" do test_dir "configure" - result = run_rscons(rsconscript: "check_c_compiler.rb") + result = run_rscons(args: %w[-f check_c_compiler.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C compiler\.\.\./ expect(Dir.exist?("build/_configure")).to be_truthy - result = run_rscons(rsconscript: "check_c_compiler.rb", rscons_args: %w[--build=bb]) + result = run_rscons(args: %w[-f check_c_compiler.rb --build=bb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C compiler\.\.\./ @@ -1820,7 +1810,7 @@ EOF context desc do it "finds the first listed C compiler" do test_dir "configure" - result = run_rscons(rsconscript: rsconscript, op: "configure") + result = run_rscons(args: %W[-f #{rsconscript} configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C compiler\.\.\. gcc/ @@ -1829,7 +1819,7 @@ EOF it "finds the second listed C compiler" do test_dir "configure" create_exe "gcc", "exit 1" - result = run_rscons(rsconscript: rsconscript, op: "configure") + result = run_rscons(args: %W[-f #{rsconscript} configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C compiler\.\.\. clang/ @@ -1839,7 +1829,7 @@ EOF test_dir "configure" create_exe "gcc", "exit 1" create_exe "clang", "exit 1" - result = run_rscons(rsconscript: rsconscript, op: "configure") + result = run_rscons(args: %W[-f #{rsconscript} configure]) expect(result.stderr).to match /Configuration failed/ expect(result.status).to_not eq 0 expect(result.stdout).to match /Checking for C compiler\.\.\. not found/ @@ -1850,7 +1840,7 @@ EOF it "successfully tests a compiler with an unknown name" do test_dir "configure" create_exe "mycompiler", %[exec gcc "$@"] - result = run_rscons(rsconscript: "check_c_compiler_custom.rb", op: "configure") + result = run_rscons(args: %w[-f check_c_compiler_custom.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C compiler\.\.\. mycompiler/ @@ -1863,7 +1853,7 @@ EOF context desc do it "finds the first listed C++ compiler" do test_dir "configure" - result = run_rscons(rsconscript: rsconscript, op: "configure") + result = run_rscons(args: %W[-f #{rsconscript} configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C\+\+ compiler\.\.\. g\+\+/ @@ -1872,7 +1862,7 @@ EOF it "finds the second listed C++ compiler" do test_dir "configure" create_exe "g++", "exit 1" - result = run_rscons(rsconscript: rsconscript, op: "configure") + result = run_rscons(args: %W[-f #{rsconscript} configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C\+\+ compiler\.\.\. clang\+\+/ @@ -1882,7 +1872,7 @@ EOF test_dir "configure" create_exe "g++", "exit 1" create_exe "clang++", "exit 1" - result = run_rscons(rsconscript: rsconscript, op: "configure") + result = run_rscons(args: %W[-f #{rsconscript} configure]) expect(result.stderr).to match /Configuration failed/ expect(result.status).to_not eq 0 expect(result.stdout).to match /Checking for C\+\+ compiler\.\.\. not found/ @@ -1893,7 +1883,7 @@ EOF it "successfully tests a compiler with an unknown name" do test_dir "configure" create_exe "mycompiler", %[exec clang++ "$@"] - result = run_rscons(rsconscript: "check_cxx_compiler_custom.rb", op: "configure") + result = run_rscons(args: %w[-f check_cxx_compiler_custom.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C\+\+ compiler\.\.\. mycompiler/ @@ -1907,7 +1897,7 @@ EOF unless RUBY_PLATFORM =~ /mingw|msys/ it "finds the first listed D compiler" do test_dir "configure" - result = run_rscons(rsconscript: rsconscript, op: "configure") + result = run_rscons(args: %W[-f #{rsconscript} configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for D compiler\.\.\. gdc/ @@ -1917,7 +1907,7 @@ EOF it "finds the second listed D compiler" do test_dir "configure" create_exe "gdc", "exit 1" - result = run_rscons(rsconscript: rsconscript, op: "configure") + result = run_rscons(args: %W[-f #{rsconscript} configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for D compiler\.\.\. ldc2/ @@ -1927,7 +1917,7 @@ EOF test_dir "configure" create_exe "gdc", "exit 1" create_exe "ldc2", "exit 1" - result = run_rscons(rsconscript: rsconscript, op: "configure") + result = run_rscons(args: %W[-f #{rsconscript} configure]) expect(result.stderr).to match /Configuration failed/ expect(result.status).to_not eq 0 expect(result.stdout).to match /Checking for D compiler\.\.\. not found/ @@ -1939,7 +1929,7 @@ EOF it "successfully tests a compiler with an unknown name that uses gdc-compatible options" do test_dir "configure" create_exe "mycompiler", %[exec gdc "$@"] - result = run_rscons(rsconscript: "check_d_compiler_custom.rb", op: "configure") + result = run_rscons(args: %w[-f check_d_compiler_custom.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for D compiler\.\.\. mycompiler/ @@ -1949,7 +1939,7 @@ EOF it "successfully tests a compiler with an unknown name that uses ldc2-compatible options" do test_dir "configure" create_exe "mycompiler", %[exec ldc2 "$@"] - result = run_rscons(rsconscript: "check_d_compiler_custom.rb", op: "configure") + result = run_rscons(args: %w[-f check_d_compiler_custom.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for D compiler\.\.\. mycompiler/ @@ -1959,7 +1949,7 @@ EOF context "check_c_header" do it "succeeds when the requested header is found" do test_dir "configure" - result = run_rscons(rsconscript: "check_c_header_success.rb", op: "configure") + result = run_rscons(args: %w[-f check_c_header_success.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C header 'string\.h'... found/ @@ -1967,7 +1957,7 @@ EOF it "fails when the requested header is not found" do test_dir "configure" - result = run_rscons(rsconscript: "check_c_header_failure.rb", op: "configure") + result = run_rscons(args: %w[-f check_c_header_failure.rb configure]) expect(result.stderr).to match /Configuration failed/ expect(result.status).to_not eq 0 expect(result.stdout).to match /Checking for C header 'not___found\.h'... not found/ @@ -1975,7 +1965,7 @@ EOF it "succeeds when the requested header is not found but :fail is set to false" do test_dir "configure" - result = run_rscons(rsconscript: "check_c_header_no_fail.rb", op: "configure") + result = run_rscons(args: %w[-f check_c_header_no_fail.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C header 'not___found\.h'... not found/ @@ -1983,11 +1973,11 @@ EOF it "sets the specified define when the header is found" do test_dir "configure" - result = run_rscons(rsconscript: "check_c_header_success_set_define.rb", op: "configure") + result = run_rscons(args: %w[-f check_c_header_success_set_define.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C header 'string\.h'... found/ - result = run_rscons(rsconscript: "check_c_header_success_set_define.rb", op: "build") + result = run_rscons(args: %w[-f check_c_header_success_set_define.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /-DHAVE_STRING_H/ @@ -1995,11 +1985,11 @@ EOF it "does not set the specified define when the header is not found" do test_dir "configure" - result = run_rscons(rsconscript: "check_c_header_no_fail_set_define.rb", op: "configure") + result = run_rscons(args: %w[-f check_c_header_no_fail_set_define.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C header 'not___found\.h'... not found/ - result = run_rscons(rsconscript: "check_c_header_no_fail_set_define.rb", op: "build") + result = run_rscons(args: %w[-f check_c_header_no_fail_set_define.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to_not match /-DHAVE_/ @@ -2012,10 +2002,10 @@ EOF File.open("usr2/frobulous.h", "wb") do |fh| fh.puts("#define FOO 42") end - result = run_rscons(rsconscript: "check_c_header_cpppath.rb", op: "configure") + result = run_rscons(args: %w[-f check_c_header_cpppath.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 - result = run_rscons(rsconscript: "check_c_header_cpppath.rb", rscons_args: %w[-v]) + result = run_rscons(args: %w[-f check_c_header_cpppath.rb -v]) expect(result.stdout).to_not match %r{-I./usr1} expect(result.stdout).to match %r{-I./usr2} end @@ -2024,7 +2014,7 @@ EOF context "check_cxx_header" do it "succeeds when the requested header is found" do test_dir "configure" - result = run_rscons(rsconscript: "check_cxx_header_success.rb", op: "configure") + result = run_rscons(args: %w[-f check_cxx_header_success.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C\+\+ header 'string\.h'... found/ @@ -2032,7 +2022,7 @@ EOF it "fails when the requested header is not found" do test_dir "configure" - result = run_rscons(rsconscript: "check_cxx_header_failure.rb", op: "configure") + result = run_rscons(args: %w[-f check_cxx_header_failure.rb configure]) expect(result.stderr).to match /Configuration failed/ expect(result.status).to_not eq 0 expect(result.stdout).to match /Checking for C\+\+ header 'not___found\.h'... not found/ @@ -2040,7 +2030,7 @@ EOF it "succeeds when the requested header is not found but :fail is set to false" do test_dir "configure" - result = run_rscons(rsconscript: "check_cxx_header_no_fail.rb", op: "configure") + result = run_rscons(args: %w[-f check_cxx_header_no_fail.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for C\+\+ header 'not___found\.h'... not found/ @@ -2053,10 +2043,10 @@ EOF File.open("usr2/frobulous.h", "wb") do |fh| fh.puts("#define FOO 42") end - result = run_rscons(rsconscript: "check_cxx_header_cpppath.rb", op: "configure") + result = run_rscons(args: %w[-f check_cxx_header_cpppath.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 - result = run_rscons(rsconscript: "check_cxx_header_cpppath.rb", rscons_args: %w[-v]) + result = run_rscons(args: %w[-f check_cxx_header_cpppath.rb -v]) expect(result.stdout).to_not match %r{-I./usr1} expect(result.stdout).to match %r{-I./usr2} end @@ -2065,7 +2055,7 @@ EOF context "check_d_import" do it "succeeds when the requested import is found" do test_dir "configure" - result = run_rscons(rsconscript: "check_d_import_success.rb", op: "configure") + result = run_rscons(args: %w[-f check_d_import_success.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for D import 'std\.stdio'... found/ @@ -2073,7 +2063,7 @@ EOF it "fails when the requested import is not found" do test_dir "configure" - result = run_rscons(rsconscript: "check_d_import_failure.rb", op: "configure") + result = run_rscons(args: %w[-f check_d_import_failure.rb configure]) expect(result.stderr).to match /Configuration failed/ expect(result.status).to_not eq 0 expect(result.stdout).to match /Checking for D import 'not\.found'... not found/ @@ -2081,7 +2071,7 @@ EOF it "succeeds when the requested import is not found but :fail is set to false" do test_dir "configure" - result = run_rscons(rsconscript: "check_d_import_no_fail.rb", op: "configure") + result = run_rscons(args: %w[-f check_d_import_no_fail.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for D import 'not\.found'... not found/ @@ -2094,10 +2084,10 @@ EOF File.open("usr2/frobulous.d", "wb") do |fh| fh.puts("int foo = 42;") end - result = run_rscons(rsconscript: "check_d_import_d_import_path.rb", op: "configure") + result = run_rscons(args: %w[-f check_d_import_d_import_path.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 - result = run_rscons(rsconscript: "check_d_import_d_import_path.rb", rscons_args: %w[-v]) + result = run_rscons(args: %w[-f check_d_import_d_import_path.rb -v]) expect(result.stdout).to_not match %r{-I./usr1} expect(result.stdout).to match %r{-I./usr2} end @@ -2106,7 +2096,7 @@ EOF context "check_lib" do it "succeeds when the requested library is found" do test_dir "configure" - result = run_rscons(rsconscript: "check_lib_success.rb", op: "configure") + result = run_rscons(args: %w[-f check_lib_success.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for library 'm'... found/ @@ -2114,7 +2104,7 @@ EOF it "fails when the requested library is not found" do test_dir "configure" - result = run_rscons(rsconscript: "check_lib_failure.rb", op: "configure") + result = run_rscons(args: %w[-f check_lib_failure.rb configure]) expect(result.stderr).to match /Configuration failed/ expect(result.status).to_not eq 0 expect(result.stdout).to match /Checking for library 'mfoofoo'... not found/ @@ -2122,7 +2112,7 @@ EOF it "succeeds when the requested library is not found but :fail is set to false" do test_dir "configure" - result = run_rscons(rsconscript: "check_lib_no_fail.rb", op: "configure") + result = run_rscons(args: %w[-f check_lib_no_fail.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for library 'mfoofoo'... not found/ @@ -2130,7 +2120,7 @@ EOF it "links against the checked library by default" do test_dir "configure" - result = run_rscons(rsconscript: "check_lib_success.rb", op: "build") + result = run_rscons(args: %w[-f check_lib_success.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for library 'm'... found/ @@ -2139,7 +2129,7 @@ EOF it "does not link against the checked library by default if :use is specified" do test_dir "configure" - result = run_rscons(rsconscript: "check_lib_use.rb", op: "build") + result = run_rscons(args: %w[-f check_lib_use.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for library 'm'... found/ @@ -2149,7 +2139,7 @@ EOF it "does not link against the checked library if :use is set to false" do test_dir "configure" - result = run_rscons(rsconscript: "check_lib_use_false.rb", op: "build") + result = run_rscons(args: %w[-f check_lib_use_false.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for library 'm'... found/ @@ -2160,13 +2150,13 @@ EOF test_dir "configure" FileUtils.mkdir_p("usr1") FileUtils.mkdir_p("usr2") - result = run_rscons(rsconscript: "check_lib_libpath1.rb") + result = run_rscons(args: %w[-f check_lib_libpath1.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 - result = run_rscons(rsconscript: "check_lib_libpath2.rb", op: "configure") + result = run_rscons(args: %w[-f check_lib_libpath2.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 - result = run_rscons(rsconscript: "check_lib_libpath2.rb") + result = run_rscons(args: %w[-f check_lib_libpath2.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match %r{-L\./usr2} @@ -2177,7 +2167,7 @@ EOF context "check_program" do it "succeeds when the requested program is found" do test_dir "configure" - result = run_rscons(rsconscript: "check_program_success.rb", op: "configure") + result = run_rscons(args: %w[-f check_program_success.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for program 'find'... .*find/ @@ -2186,7 +2176,7 @@ EOF context "with non-existent PATH entries" do it "succeeds when the requested program is found" do test_dir "configure" - result = run_rscons(rsconscript: "check_program_success.rb", op: "configure", path: "/foo/bar") + result = run_rscons(args: %w[-f check_program_success.rb configure], path: "/foo/bar") expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for program 'find'... .*find/ @@ -2195,7 +2185,7 @@ EOF it "fails when the requested program is not found" do test_dir "configure" - result = run_rscons(rsconscript: "check_program_failure.rb", op: "configure") + result = run_rscons(args: %w[-f check_program_failure.rb configure]) expect(result.stderr).to match /Configuration failed/ expect(result.status).to_not eq 0 expect(result.stdout).to match /Checking for program 'program-that-is-not-found'... not found/ @@ -2203,7 +2193,7 @@ EOF it "succeeds when the requested program is not found but :fail is set to false" do test_dir "configure" - result = run_rscons(rsconscript: "check_program_no_fail.rb", op: "configure") + result = run_rscons(args: %w[-f check_program_no_fail.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for program 'program-that-is-not-found'... not found/ @@ -2215,11 +2205,11 @@ EOF it "stores flags and uses them during a build operation" do test_dir "configure" create_exe "pkg-config", "echo '-DMYPACKAGE'" - result = run_rscons(rsconscript: "check_cfg_package.rb", op: "configure") + result = run_rscons(args: %w[-f check_cfg_package.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for package 'mypackage'\.\.\. found/ - result = run_rscons(rsconscript: "check_cfg_package.rb", op: "build") + result = run_rscons(args: %w[-f check_cfg_package.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /gcc.*-o.*\.o.*-DMYPACKAGE/ @@ -2227,7 +2217,7 @@ EOF it "fails when the configure program given does not exist" do test_dir "configure" - result = run_rscons(rsconscript: "check_cfg.rb", op: "configure") + result = run_rscons(args: %w[-f check_cfg.rb configure]) expect(result.stderr).to match /Configuration failed/ expect(result.status).to_not eq 0 expect(result.stdout).to match /Checking 'my-config'\.\.\. not found/ @@ -2236,11 +2226,11 @@ EOF it "does not use the flags found by default if :use is specified" do test_dir "configure" create_exe "pkg-config", "echo '-DMYPACKAGE'" - result = run_rscons(rsconscript: "check_cfg_use.rb", op: "configure") + result = run_rscons(args: %w[-f check_cfg_use.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking for package 'mypackage'\.\.\. found/ - result = run_rscons(rsconscript: "check_cfg_use.rb", op: "build") + result = run_rscons(args: %w[-f check_cfg_use.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to_not match /gcc.*-o.*myconfigtest1.*-DMYPACKAGE/ @@ -2252,11 +2242,11 @@ EOF it "stores flags and uses them during a build operation" do test_dir "configure" create_exe "my-config", "echo '-DMYCONFIG -lm'" - result = run_rscons(rsconscript: "check_cfg.rb", op: "configure") + result = run_rscons(args: %w[-f check_cfg.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Checking 'my-config'\.\.\. found/ - result = run_rscons(rsconscript: "check_cfg.rb", op: "build") + result = run_rscons(args: %w[-f check_cfg.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /gcc.*-o.*\.o.*-DMYCONFIG/ @@ -2272,7 +2262,7 @@ EOF it "fails configuration with the correct error message" do test_dir "configure" create_exe "grep", "exit 4" - result = run_rscons(rsconscript: "custom_config_check.rb", op: "configure") + result = run_rscons(args: %w[-f custom_config_check.rb configure]) expect(result.stderr).to match /Configuration failed/ expect(result.stdout).to match /Checking 'grep' version\.\.\. error executing grep/ expect(result.status).to_not eq 0 @@ -2283,7 +2273,7 @@ EOF it "fails configuration with the correct error message" do test_dir "configure" create_exe "grep", "echo 'grep (GNU grep) 1.1'" - result = run_rscons(rsconscript: "custom_config_check.rb", op: "configure") + result = run_rscons(args: %w[-f custom_config_check.rb configure]) expect(result.stderr).to match /Configuration failed/ expect(result.stdout).to match /Checking 'grep' version\.\.\. too old!/ expect(result.status).to_not eq 0 @@ -2296,11 +2286,11 @@ EOF it "displays the correct message and does not fail configuration" do test_dir "configure" create_exe "grep", "echo 'grep (GNU grep) 2.1'" - result = run_rscons(rsconscript: "custom_config_check.rb", op: "configure") + result = run_rscons(args: %w[-f custom_config_check.rb configure]) expect(result.stderr).to eq "" expect(result.stdout).to match /Checking 'grep' version\.\.\. we'll work with it but you should upgrade/ expect(result.status).to eq 0 - result = run_rscons(rsconscript: "custom_config_check.rb", op: "build") + result = run_rscons(args: %w[-f custom_config_check.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match /GREP_WORKAROUND/ expect(result.status).to eq 0 @@ -2312,11 +2302,11 @@ EOF it "passes configuration with the correct message" do test_dir "configure" create_exe "grep", "echo 'grep (GNU grep) 3.0'" - result = run_rscons(rsconscript: "custom_config_check.rb", op: "configure") + result = run_rscons(args: %w[-f custom_config_check.rb configure]) expect(result.stderr).to eq "" expect(result.stdout).to match /Checking 'grep' version\.\.\. good!/ expect(result.status).to eq 0 - result = run_rscons(rsconscript: "custom_config_check.rb", op: "build") + result = run_rscons(args: %w[-f custom_config_check.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match /GREP_FULL/ expect(result.status).to eq 0 @@ -2325,7 +2315,7 @@ EOF it "allows passing standard input data to the executed command" do test_dir "configure" - result = run_rscons(rsconscript: "custom_config_check.rb", op: "configure") + result = run_rscons(args: %w[-f custom_config_check.rb configure]) expect(result.stderr).to eq "" expect(result.stdout).to match /Checking sed -E flag\.\.\. good/ expect(result.status).to eq 0 @@ -2336,7 +2326,7 @@ EOF context "on_fail option" do it "prints on_fail messages and calls on_fail procs on failure" do test_dir "configure" - result = run_rscons(rsconscript: "on_fail.rb", op: %w[configure]) + result = run_rscons(args: %w[-f on_fail.rb configure]) expect(result.status).to_not eq 0 expect(result.stdout).to match /Install the foo123 package/ expect(result.stdout).to match /Install the foo123cxx package/ @@ -2346,7 +2336,7 @@ EOF it "does everything" do test_dir "configure" create_exe "pkg-config", "echo '-DMYPACKAGE'" - result = run_rscons(rsconscript: "everything.rb", op: %w[configure --build=bb --prefix=/my/prefix]) + result = run_rscons(args: %w[-f everything.rb --build=bb configure --prefix=/my/prefix]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /Configuring configure test\.\.\./ @@ -2366,10 +2356,10 @@ EOF it "aggregates multiple set_define's" do test_dir "configure" - result = run_rscons(rsconscript: "multiple_set_define.rb", op: "configure") + result = run_rscons(args: %w[-f multiple_set_define.rb configure]) expect(result.stderr).to eq "" expect(result.status).to eq 0 - result = run_rscons(rsconscript: "multiple_set_define.rb", op: "build") + result = run_rscons(args: %w[-f multiple_set_define.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to match /gcc.*-o.*\.o.*-DHAVE_MATH_H\s.*-DHAVE_STDIO_H/ @@ -2377,34 +2367,27 @@ EOF it "exits with an error if the project is not configured and a build is requested and autoconf is false" do test_dir "configure" - result = run_rscons(rsconscript: "autoconf_false.rb") - expect(result.stderr).to match /Project must be configured first, and autoconf is disabled/ + result = run_rscons(args: %w[-f autoconf_false.rb]) + expect(result.stderr).to match /Project must be configured before creating an Environment/ expect(result.status).to_not eq 0 end it "exits with an error code and message if configuration fails during autoconf" do test_dir "configure" - result = run_rscons(rsconscript: "autoconf_fail.rb") + result = run_rscons(args: %w[-f autoconf_fail.rb]) expect(result.stdout).to match /Checking for C compiler\.\.\. not found/ expect(result.status).to_not eq 0 expect(result.stderr).to_not match /from\s/ expect(lines(result.stderr).last).to eq "Configuration failed" end - it "exits with an error if configuration has not been performed before attempting to create an environment" do - test_dir "configure" - result = run_rscons(rsconscript: "error_env_construction_before_configure.rb") - expect(result.stderr).to match /Project must be configured before creating an Environment/ - expect(result.status).to_not eq 0 - end - it "does not rebuild after building with auto-configuration" do test_dir "configure" - result = run_rscons(rsconscript: "autoconf_rebuild.rb") + result = run_rscons(args: %w[-f autoconf_rebuild.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(File.exists?("simple.exe")).to be_truthy - result = run_rscons(rsconscript: "autoconf_rebuild.rb") + result = run_rscons(args: %w[-f autoconf_rebuild.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(result.stdout).to eq "" @@ -2414,12 +2397,12 @@ EOF context "distclean" do it "removes built files and the build directory" do test_dir "simple" - result = run_rscons(rsconscript: "distclean.rb") + result = run_rscons(args: %w[-f distclean.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(File.exists?("simple.o")).to be_truthy expect(File.exists?("build")).to be_truthy - result = run_rscons(rsconscript: "distclean.rb", op: "distclean") + result = run_rscons(args: %w[-f distclean.rb distclean]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(File.exists?("simple.o")).to be_falsey @@ -2437,47 +2420,30 @@ EOF it "echoes commands by default with -v" do test_dir('simple') - result = run_rscons(rscons_args: %w[-v]) + result = run_rscons(args: %w[-v]) expect(result.stderr).to eq "" expect(result.stdout).to match /gcc.*-o.*simple/ end it "echoes commands by default with --verbose" do test_dir('simple') - result = run_rscons(rscons_args: %w[--verbose]) + result = run_rscons(args: %w[--verbose]) expect(result.stderr).to eq "" expect(result.stdout).to match /gcc.*-o.*simple/ end - - it "echoes commands by default with -v after build operation" do - test_dir('simple') - result = run_rscons(op: %w[build -v]) - expect(result.stderr).to eq "" - expect(result.stdout).to match /gcc.*-o.*simple/ - end - - it "prints operation start time" do - test_dir("simple") - result = run_rscons(rscons_args: %w[-v]) - expect(result.stderr).to eq "" - expect(result.stdout).to match /Starting 'configure' at/ - expect(result.stdout).to match /Starting 'build' at/ - expect(result.stdout).to match /'build' complete at/ - expect(result.stdout).to_not match /'configure' complete at/ - end end context "direct mode" do it "allows calling Program builder in direct mode and passes all sources to the C compiler" do test_dir("direct") - result = run_rscons(rsconscript: "c_program.rb") + result = run_rscons(args: %w[-f c_program.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match %r{Compiling/Linking} expect(File.exists?("test.exe")).to be_truthy expect(`./test.exe`).to match /three/ - result = run_rscons(rsconscript: "c_program.rb") + result = run_rscons(args: %w[-f c_program.rb]) expect(result.stdout).to eq "" three_h = File.read("three.h", mode: "rb") @@ -2485,21 +2451,21 @@ EOF fh.write(three_h) fh.puts("#define FOO 42") end - result = run_rscons(rsconscript: "c_program.rb") + result = run_rscons(args: %w[-f c_program.rb]) expect(result.stdout).to match %r{Compiling/Linking} end it "allows calling SharedLibrary builder in direct mode and passes all sources to the C compiler" do test_dir("direct") - result = run_rscons(rsconscript: "c_shared_library.rb") + result = run_rscons(args: %w[-f c_shared_library.rb]) expect(result.stderr).to eq "" expect(result.stdout).to match %r{Compiling/Linking} expect(File.exists?("test.exe")).to be_truthy ld_library_path_prefix = (RUBY_PLATFORM =~ /mingw|msys/ ? "" : "LD_LIBRARY_PATH=. ") expect(`#{ld_library_path_prefix}./test.exe`).to match /three/ - result = run_rscons(rsconscript: "c_shared_library.rb") + result = run_rscons(args: %w[-f c_shared_library.rb]) expect(result.stdout).to eq "" three_h = File.read("three.h", mode: "rb") @@ -2507,7 +2473,7 @@ EOF fh.write(three_h) fh.puts("#define FOO 42") end - result = run_rscons(rsconscript: "c_shared_library.rb") + result = run_rscons(args: %w[-f c_shared_library.rb]) expect(result.stdout).to match %r{Compiling/Linking} end end @@ -2516,7 +2482,7 @@ EOF it "invokes a configure operation if the project is not yet configured" do test_dir "typical" - result = run_rscons(rsconscript: "install.rb", op: %W[install]) + result = run_rscons(args: %w[-f install.rb install]) expect(result.stdout).to match /Configuring install_test/ end @@ -2524,9 +2490,9 @@ EOF test_dir "typical" Dir.mktmpdir do |prefix| - result = run_rscons(rsconscript: "install.rb", op: %W[configure --prefix=#{prefix}]) + result = run_rscons(args: %W[-f install.rb configure --prefix=#{prefix}]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "install.rb", op: %W[install]) + result = run_rscons(args: %w[-f install.rb install]) expect(result.stderr).to eq "" expect(result.stdout).to match /Compiling/ expect(result.stdout).to match /Linking/ @@ -2537,10 +2503,10 @@ EOF test_dir "typical" Dir.mktmpdir do |prefix| - result = run_rscons(rsconscript: "install.rb", op: %W[configure --prefix=#{prefix}]) + result = run_rscons(args: %W[-f install.rb configure --prefix=#{prefix}]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "install.rb", op: %W[install]) + result = run_rscons(args: %w[-f install.rb install]) expect(result.stderr).to eq "" expect(result.stdout).to match /Creating directory/ expect(result.stdout).to match /Install install.rb =>/ @@ -2555,7 +2521,7 @@ EOF expect(File.exists?("#{prefix}/mult/install.rb")).to be_truthy expect(File.exists?("#{prefix}/mult/copy.rb")).to be_truthy - result = run_rscons(rsconscript: "install.rb", op: %W[install]) + result = run_rscons(args: %w[-f install.rb install]) expect(result.stderr).to eq "" expect(result.stdout).to eq "" end @@ -2565,15 +2531,15 @@ EOF test_dir "typical" Dir.mktmpdir do |prefix| - result = run_rscons(rsconscript: "install.rb", op: %W[configure --prefix=#{prefix}]) + result = run_rscons(args: %W[-f install.rb configure --prefix=#{prefix}]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "install.rb", op: %W[build]) + result = run_rscons(args: %w[-f install.rb]) expect(result.stderr).to eq "" expect(result.stdout).to_not match /Install/ expect(Dir.entries(prefix)).to match_array %w[. ..] - result = run_rscons(rsconscript: "install.rb", op: %W[install]) + result = run_rscons(args: %w[-f install.rb install]) expect(result.stderr).to eq "" expect(result.stdout).to match /Install/ end @@ -2585,15 +2551,15 @@ EOF test_dir "typical" Dir.mktmpdir do |prefix| - result = run_rscons(rsconscript: "install.rb", op: %W[configure --prefix=#{prefix}]) + result = run_rscons(args: %W[-f install.rb configure --prefix=#{prefix}]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "install.rb", op: %W[install]) + result = run_rscons(args: %w[-f install.rb install]) expect(result.stderr).to eq "" expect(File.exists?("#{prefix}/bin/program.exe")).to be_truthy expect(File.exists?("build/e.1/src/one/one.c.o")).to be_truthy - result = run_rscons(rsconscript: "install.rb", op: %W[uninstall]) + result = run_rscons(args: %w[-f install.rb uninstall]) expect(result.stderr).to eq "" expect(result.stdout).to_not match /Removing/ expect(File.exists?("#{prefix}/bin/program.exe")).to be_falsey @@ -2606,13 +2572,13 @@ EOF test_dir "typical" Dir.mktmpdir do |prefix| - result = run_rscons(rsconscript: "install.rb", op: %W[configure --prefix=#{prefix}]) + result = run_rscons(args: %W[-f install.rb configure --prefix=#{prefix}]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "install.rb", op: %W[install]) + result = run_rscons(args: %w[-f install.rb install]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "install.rb", op: %W[uninstall -v]) + result = run_rscons(args: %w[-f install.rb -v uninstall]) expect(result.stderr).to eq "" expect(result.stdout).to match %r{Removing #{prefix}/bin/program.exe} expect(File.exists?("#{prefix}/bin/program.exe")).to be_falsey @@ -2624,13 +2590,13 @@ EOF test_dir "typical" Dir.mktmpdir do |prefix| - result = run_rscons(rsconscript: "install.rb", op: %W[configure --prefix=#{prefix}]) + result = run_rscons(args: %W[-f install.rb configure --prefix=#{prefix}]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "install.rb", op: %W[install]) + result = run_rscons(args: %w[-f install.rb install]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "install.rb", op: %W[uninstall -v]) + result = run_rscons(args: %w[-f install.rb -v uninstall]) expect(result.stderr).to eq "" expect(result.stdout).to match %r{Removing #{prefix}/bin/program.exe} expect(File.exists?("#{prefix}/bin/program.exe")).to be_falsey @@ -2638,7 +2604,7 @@ EOF FileUtils.mkdir_p("#{prefix}/bin") File.open("#{prefix}/bin/program.exe", "w") {|fh| fh.write("hi")} - result = run_rscons(rsconscript: "install.rb", op: %W[uninstall -v]) + result = run_rscons(args: %w[-f install.rb -v uninstall]) expect(result.stderr).to eq "" expect(result.stdout).to_not match /Removing/ end @@ -2649,7 +2615,7 @@ EOF it "does not include install targets in build progress when not doing an install" do test_dir "typical" - result = run_rscons(rsconscript: "install.rb") + result = run_rscons(args: %w[-f install.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{\[1/3\] Compiling}, @@ -2658,35 +2624,35 @@ EOF ]) end - it "does include install targets in build progress when doing an install" do + it "counts install task targets separately from build task targets" do test_dir "typical" Dir.mktmpdir do |prefix| - result = run_rscons(rsconscript: "install.rb", op: %W[configure --prefix=#{prefix}]) + result = run_rscons(args: %W[-f install.rb configure --prefix=#{prefix}]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "install.rb", op: %w[install]) + result = run_rscons(args: %w[-f install.rb install]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ - %r{\[1/9\] Compiling}, - %r{\[2/9\] Compiling}, - %r{\[\d/9\] Install}, + %r{\[1/3\] Compiling}, + %r{\[2/3\] Compiling}, + %r{\[\d/6\] Install}, ]) end end - it "includes build steps from all environments when showing build progress" do + it "separates build steps from each environment when showing build progress" do test_dir "typical" - result = run_rscons(rsconscript: "multiple_environments.rb") + result = run_rscons(args: %w[-f multiple_environments.rb]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ - %r{\[1/6\] Compiling}, - %r{\[2/6\] Compiling}, - %r{\[3/6\] Linking}, - %r{\[4/6\] Compiling}, - %r{\[5/6\] Compiling}, - %r{\[6/6\] Linking}, + %r{\[1/3\] Compiling}, + %r{\[2/3\] Compiling}, + %r{\[3/3\] Linking}, + %r{\[1/3\] Compiling}, + %r{\[2/3\] Compiling}, + %r{\[3/3\] Linking}, ]) end end @@ -2696,7 +2662,7 @@ EOF it "executes the subsidiary script from configure block" do test_dir "subsidiary" - result = run_rscons(op: %W[configure]) + result = run_rscons(args: %w[configure]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Entering directory '.*/sub'}, @@ -2715,9 +2681,9 @@ EOF it "executes the subsidiary script from build block" do test_dir "subsidiary" - result = run_rscons(op: %W[configure]) + result = run_rscons(args: %w[configure]) expect(result.stderr).to eq "" - result = run_rscons(op: %W[build]) + result = run_rscons expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{sub Rsconscript2 build}, @@ -2730,7 +2696,7 @@ EOF it "executes the subsidiary script from configure block" do test_dir "subsidiary" - result = run_rscons(rsconscript: "Rsconscript_dir", op: %W[configure]) + result = run_rscons(args: %w[-f Rsconscript_dir configure]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Entering directory '.*/sub'}, @@ -2749,9 +2715,9 @@ EOF it "executes the subsidiary script from build block" do test_dir "subsidiary" - result = run_rscons(rsconscript: "Rsconscript_dir", op: %W[configure]) + result = run_rscons(args: %w[-f Rsconscript_dir configure]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "Rsconscript_dir", op: %W[build]) + result = run_rscons(args: %w[-f Rsconscript_dir]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{sub Rsconscript2 build}, @@ -2769,7 +2735,7 @@ EOF puts "sub rscons" EOF FileUtils.chmod(0755, "sub/rscons") - result = run_rscons(op: %W[configure]) + result = run_rscons(args: %w[configure]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ %r{Entering directory '.*/sub'}, @@ -2789,9 +2755,9 @@ EOF it "does not print entering/leaving directory messages when the subsidiary script is in the same directory" do test_dir "subsidiary" - result = run_rscons(rsconscript: "Rsconscript_samedir", op: %W[configure]) + result = run_rscons(args: %w[-f Rsconscript_samedir configure]) expect(result.stderr).to eq "" - result = run_rscons(rsconscript: "Rsconscript_samedir", op: %W[build]) + result = run_rscons(args: %w[-f Rsconscript_samedir]) expect(result.stderr).to eq "" expect(result.stdout).to_not match(%{(Entering|Leaving) directory}) verify_lines(lines(result.stdout), [ @@ -2803,7 +2769,7 @@ EOF it "terminates execution when a subsidiary script fails" do test_dir "subsidiary" - result = run_rscons(rsconscript: "Rsconscript_fail", op: %W[configure]) + result = run_rscons(args: %w[-f Rsconscript_fail configure]) expect(result.stderr).to_not eq "" expect(result.status).to_not eq 0 expect(result.stdout).to_not match /top configure/ @@ -2812,7 +2778,7 @@ EOF it "does not pass RSCONS_BUILD_DIR to subsidiary scripts" do test_dir "subsidiary" passenv["RSCONS_BUILD_DIR"] = "buildit" - result = run_rscons(op: %W[configure]) + result = run_rscons(args: %w[configure]) expect(result.stderr).to eq "" expect(Dir.exist?("build")).to be_falsey expect(Dir.exist?("buildit")).to be_truthy @@ -2824,7 +2790,7 @@ EOF context "sh method" do it "executes the command given" do test_dir "sh" - result = run_rscons(rsconscript: "sh.rb") + result = run_rscons(args: %w[-f sh.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 verify_lines(lines(result.stdout), [ @@ -2835,7 +2801,7 @@ EOF it "prints the command when executing verbosely" do test_dir "sh" - result = run_rscons(rsconscript: "sh.rb", rscons_args: %w[-v]) + result = run_rscons(args: %w[-f sh.rb -v]) expect(result.stderr).to eq "" expect(result.status).to eq 0 verify_lines(lines(result.stdout), [ @@ -2848,7 +2814,7 @@ EOF it "terminates execution on failure" do test_dir "sh" - result = run_rscons(rsconscript: "sh_fail.rb") + result = run_rscons(args: %w[-f sh_fail.rb]) expect(result.stderr).to match /sh_fail\.rb:2:.*foobar42/ expect(result.status).to_not eq 0 expect(result.stdout).to_not match /continued/ @@ -2856,7 +2822,7 @@ EOF it "continues execution on failure when :continue option is set" do test_dir "sh" - result = run_rscons(rsconscript: "sh_fail_continue.rb") + result = run_rscons(args: %w[-f sh_fail_continue.rb]) expect(result.stderr).to match /sh_fail_continue\.rb:2:.*foobar42/ expect(result.status).to eq 0 expect(result.stdout).to match /continued/ @@ -2866,7 +2832,7 @@ EOF context "FileUtils methods" do it "defines FileUtils methods to be available in the build script" do test_dir "typical" - result = run_rscons(rsconscript: "fileutils_methods.rb") + result = run_rscons(args: %w[-f fileutils_methods.rb]) expect(result.stderr).to eq "" expect(result.status).to eq 0 expect(Dir.exist?("foobar")).to be_truthy @@ -2875,4 +2841,85 @@ EOF end end + it "executes the requested tasks in the requested order" do + test_dir "tasks" + result = run_rscons(args: %w[-f tasks.rb configure]) + result = run_rscons(args: %w[-f tasks.rb one three]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to eq "one\nthree\n" + result = run_rscons(args: %w[-f tasks.rb three one]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to eq "three\none\n" + end + + it "executes the task's dependencies before the requested task" do + test_dir "tasks" + result = run_rscons(args: %w[-f tasks.rb configure]) + result = run_rscons(args: %w[-f tasks.rb two]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to eq "one\nthree\ntwo\n" + end + + it "does not execute a task more than once" do + test_dir "tasks" + result = run_rscons(args: %w[-f tasks.rb configure]) + result = run_rscons(args: %w[-f tasks.rb one two three]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to eq "one\nthree\ntwo\n" + end + + it "passes task arguments" do + test_dir "tasks" + result = run_rscons(args: %w[-f tasks.rb configure]) + result = run_rscons(args: %w[-f tasks.rb four]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to eq %[four\nmyparam:"defaultvalue"\nmyp2:nil\n] + 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] + end + + it "allows accessing task arguments via Task#[]" do + test_dir "tasks" + result = run_rscons(args: %w[-f tasks.rb configure]) + result = run_rscons(args: %w[-f tasks.rb five]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match /four myparam value is defaultvalue/ + result = run_rscons(args: %w[-f tasks.rb four --myparam=v42 five]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to match /four myparam value is v42/ + end + + it "exits with an error when attempting to get a nonexistent parameter value" do + test_dir "tasks" + result = run_rscons(args: %w[-f tasks.rb configure]) + result = run_rscons(args: %w[-f tasks.rb six]) + expect(result.stderr).to match /Could not find parameter 'nope'/ + 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/ + end + end