support command-line variables - close #51

This commit is contained in:
Josh Holtrop 2018-08-23 14:58:08 -04:00
parent d081a4695f
commit 284312a21c
4 changed files with 22 additions and 10 deletions

View File

@ -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")

View File

@ -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

View File

@ -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}"

View File

@ -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