diff --git a/build_tests/simple/cache_debugging.rb b/build_tests/simple/cache_debugging.rb index 84330e9..cd6a00e 100644 --- a/build_tests/simple/cache_debugging.rb +++ b/build_tests/simple/cache_debugging.rb @@ -2,17 +2,17 @@ class DebugBuilder < Rscons::Builder def run(options) target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars) command = %W[gcc -c -o #{target} #{sources.first}] - if ENV["command_change"] + if Rscons.vars["command_change"] command += %w[-Wall] end - if ENV["new_dep"] + if Rscons.vars["new_dep"] sources += ["extra"] end - if ENV["strict_deps1"] + if Rscons.vars["strict_deps1"] sources += ["extra"] strict_deps = true end - if ENV["strict_deps2"] + if Rscons.vars["strict_deps2"] sources = ["extra"] + sources strict_deps = true end @@ -27,7 +27,7 @@ end Rscons::Environment.new do |env| env.add_builder(DebugBuilder.new) - if ENV["new_user_dep"] + if Rscons.vars["new_user_dep"] env.depends("foo.o", "new_dep") end env.DebugBuilder("foo.o", "simple.c") diff --git a/lib/rscons.rb b/lib/rscons.rb index 294b3fb..5691fc1 100644 --- a/lib/rscons.rb +++ b/lib/rscons.rb @@ -55,6 +55,11 @@ module Rscons # Whether to output ANSI color escape sequences. attr_accessor :do_ansi_color + # @since 1.16.0 + # @return [VarSet] + # Access any variables set on the rscons command-line. + attr_reader :vars + # Remove all generated files. # # @return [void] @@ -232,6 +237,7 @@ module Rscons end @n_threads = determine_n_threads + @vars = VarSet.new end diff --git a/lib/rscons/cli.rb b/lib/rscons/cli.rb index 1d5f5d5..bcdbb73 100644 --- a/lib/rscons/cli.rb +++ b/lib/rscons/cli.rb @@ -60,6 +60,12 @@ module Rscons end.parse!(argv) + argv.each do |arg| + if arg =~ /^([^=]+)=(.*)$/ + Rscons.vars[$1] = $2 + end + end + if rsconsfile unless File.exists?(rsconsfile) $stderr.puts "Cannot read #{rsconsfile}" diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 10e3a2a..f2f6489 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1300,28 +1300,28 @@ EOF it "prints a message when the command has changed" do test_dir("simple") result = run_test(rsconsfile: "cache_debugging.rb") - result = run_test(rsconsfile: "cache_debugging.rb", ruby_setup_code: %[ENV["command_change"] = "yes"]) + result = run_test(rsconsfile: "cache_debugging.rb", rscons_args: %w[command_change=yes]) 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_test(rsconsfile: "cache_debugging.rb", ruby_setup_code: %[ENV["strict_deps1"] = "yes"]) - result = run_test(rsconsfile: "cache_debugging.rb", ruby_setup_code: %[ENV["strict_deps2"] = "yes"]) + result = run_test(rsconsfile: "cache_debugging.rb", rscons_args: %w[strict_deps1=yes]) + result = run_test(rsconsfile: "cache_debugging.rb", rscons_args: %w[strict_deps2=yes]) 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_test(rsconsfile: "cache_debugging.rb") - result = run_test(rsconsfile: "cache_debugging.rb", ruby_setup_code: %[ENV["new_dep"] = "yes"]) + result = run_test(rsconsfile: "cache_debugging.rb", rscons_args: %w[new_dep=yes]) 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_test(rsconsfile: "cache_debugging.rb") - result = run_test(rsconsfile: "cache_debugging.rb", ruby_setup_code: %[ENV["new_user_dep"] = "yes"]) + result = run_test(rsconsfile: "cache_debugging.rb", rscons_args: %w[new_user_dep=yes]) expect(result.stdout).to match /Target foo\.o needs rebuilding because the set of user-specified dependency files has changed/ end