do not prepend build_root to source files that are already inside build_root

This commit is contained in:
Josh Holtrop 2013-12-31 10:15:19 -05:00
parent 8976d7dea2
commit 1868193b54
2 changed files with 32 additions and 2 deletions

View File

@ -13,7 +13,10 @@ module Rscons
attr_accessor :echo
# String or +nil+
attr_accessor :build_root
attr_reader :build_root
def build_root=(build_root)
@build_root = build_root.gsub('\\', '/')
end
# Create an Environment object.
# @param options [Hash]
@ -106,7 +109,7 @@ module Rscons
end
end
if @build_root and not found_match
unless source_fname.absolute_path?
unless source_fname.absolute_path? or build_fname.start_with?("#{@build_root}/")
build_fname = "#{@build_root}/#{build_fname}"
end
end

View File

@ -61,6 +61,18 @@ module Rscons
env.get_build_fname("src\\dir\\other.d", ".a").should == "src/dir/other.a"
env.get_build_fname("source.cc", ".o").should == "source.o"
end
context "with a build_root" do
it "uses the build_root unless the path is absolute" do
env = Environment.new
env.build_root = "build/proj"
env.get_build_fname("src/dir/file.c", ".o").should == "build/proj/src/dir/file.o"
env.get_build_fname("/some/lib.c", ".a").should == "/some/lib.a"
env.get_build_fname("C:\\abspath\\mod.cc", ".o").should == "C:/abspath/mod.o"
env.get_build_fname("build\\proj\\generated.c", ".o").should == "build/proj/generated.o"
env.get_build_fname("build/proj.XX", ".yy").should == "build/proj/build/proj.yy"
end
end
end
context "with build directories" do
@ -73,6 +85,21 @@ module Rscons
env.get_build_fname("libs/otherlib/otherlib.cc", ".o").should == "build/libs/otherlib/otherlib.o"
env.get_build_fname("other_directory/o.d", ".a").should == "other_directory/o.a"
end
context "with a build_root" do
it "uses the build_root unless a build directory matches or the path is absolute" do
env = Environment.new
env.build_dir("src", "bld")
env.build_dir(%r{^libs/([^/]+)}, 'build/libs/\1')
env.build_root = "bldit"
env.get_build_fname("src/input.cc", ".o").should == "bld/input.o"
env.get_build_fname("libs/lib1/some/file.c", ".o").should == "build/libs/lib1/some/file.o"
env.get_build_fname("libs/otherlib/otherlib.cc", ".o").should == "build/libs/otherlib/otherlib.o"
env.get_build_fname("other_directory/o.d", ".a").should == "bldit/other_directory/o.a"
env.get_build_fname("bldit/some/mod.d", ".a").should == "bldit/some/mod.a"
end
end
end
end