From 53ba7dad417d19d9e02a156b1d58552be938f8a6 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 22 Aug 2018 16:32:05 -0400 Subject: [PATCH] allow passing a VarSet into cache methods - close #47 --- build_tests/simple/cache_varset.rb | 20 ++++++++++++++++++++ lib/rscons/varset.rb | 7 +++++++ spec/build_tests_spec.rb | 12 ++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 build_tests/simple/cache_varset.rb diff --git a/build_tests/simple/cache_varset.rb b/build_tests/simple/cache_varset.rb new file mode 100644 index 0000000..f3d448b --- /dev/null +++ b/build_tests/simple/cache_varset.rb @@ -0,0 +1,20 @@ +class TestBuilder < Rscons::Builder + def run(options) + target, sources, cache, env = options.values_at(:target, :sources, :cache, :env) + command = Rscons::VarSet.new("A" => "a", "B" => "b") + unless cache.up_to_date?(target, command, sources, env) + File.open(target, "w") do |fh| + fh.puts("hi") + end + msg = "#{self.class.name} #{target}" + env.print_builder_run_message(msg, msg) + cache.register_build(target, command, sources, env) + end + target + end +end + +Rscons::Environment.new do |env| + env.add_builder(TestBuilder.new) + env.TestBuilder("foo") +end diff --git a/lib/rscons/varset.rb b/lib/rscons/varset.rb index 2787fec..95ababd 100644 --- a/lib/rscons/varset.rb +++ b/lib/rscons/varset.rb @@ -143,6 +143,13 @@ module Rscons end end + # Return a String representing the VarSet. + # + # @return [String] Representation of the VarSet. + def inspect + to_h.inspect + end + # Return an array containing the values associated with the given keys. # # @param keys [Array] diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 31a771b..0b87add 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1261,6 +1261,18 @@ EOF "LD simple.exe", ] end + + it "allows a VarSet to be passed in as the command parameter" do + test_dir("simple") + result = run_test(rsconsfile: "cache_varset.rb") + expect(result.stderr).to eq "" + expect(lines(result.stdout)).to eq [ + "TestBuilder foo", + ] + result = run_test(rsconsfile: "cache_varset.rb") + expect(result.stderr).to eq "" + expect(result.stdout).to eq "" + end end context "Object builder" do