From 0442b876a57b8b24221702cc3d05e94744e8437c Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 12 Jan 2016 10:14:10 -0500 Subject: [PATCH] allow phony targets in conjunction with a build root --- lib/rscons/environment.rb | 6 ++++- spec/build_tests_spec.rb | 47 +++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 3f2f5b5..78deaf7 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -509,7 +509,11 @@ module Rscons # # @return [String] The expanded path. def expand_path(path) - path.sub(%r{^\^(?=[\\/])}, @build_root) + if Rscons.phony_target?(path) + path + else + path.sub(%r{^\^(?=[\\/])}, @build_root) + end end # Execute a command using the system shell. diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 4eb7204..98c9918 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -933,33 +933,36 @@ EOF end context "phony targets" do - it "allows specifying a Symbol as a target name and reruns the builder if the sources or command have changed" do - test_dir("simple") - env = Rscons::Environment.new do |env| - env.add_builder(:Checker) do |target, sources, cache, env, vars| - unless cache.up_to_date?(target, :Checker, sources, env) - puts "Checker #{sources.first}" if env.echo != :off - cache.register_build(target, :Checker, sources, env) + [false, true].each do |with_build_root| + it "allows specifying a Symbol as a target name and reruns the builder if the sources or command have changed" do + test_dir("simple") + env = Rscons::Environment.new do |env| + env.build_root = "bld" if with_build_root + env.add_builder(:Checker) do |target, sources, cache, env, vars| + unless cache.up_to_date?(target, :Checker, sources, env) + puts "Checker #{sources.first}" if env.echo != :off + cache.register_build(target, :Checker, sources, env) + end + target end - target + env.Program("simple.exe", "simple.c") + env.Checker(:checker, "simple.exe") end - env.Program("simple.exe", "simple.c") - env.Checker(:checker, "simple.exe") - end - expect(lines).to eq(["CC simple.o", "LD simple.exe", "Checker simple.exe"]) + expect(lines).to eq(["CC #{with_build_root ? 'bld/' : ''}simple.o", "LD simple.exe", "Checker simple.exe"]) - env.clone do |env| - env.Checker(:checker, "simple.exe") - end - expect(lines).to eq([]) + env.clone do |env| + env.Checker(:checker, "simple.exe") + end + expect(lines).to eq([]) - File.open("simple.exe", "w") do |fh| - fh.puts "Changed simple.exe" + File.open("simple.exe", "w") do |fh| + fh.puts "Changed simple.exe" + end + env.clone do |env| + env.Checker(:checker, "simple.exe") + end + expect(lines).to eq(["Checker simple.exe"]) end - env.clone do |env| - env.Checker(:checker, "simple.exe") - end - expect(lines).to eq(["Checker simple.exe"]) end end