2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-13 00:12:11 +00:00

Try to preserve relative paths in sources.

Based on a patch from Ryan Gallagher.


[SVN r34062]
This commit is contained in:
Vladimir Prus
2006-05-23 14:21:58 +00:00
parent bed7507c64
commit aafe2d6065
4 changed files with 68 additions and 8 deletions

View File

@@ -105,6 +105,7 @@ class generator
import virtual-target ;
import "class" : new ;
import property ;
import path ;
EXPORT class@generator : indent increase-indent decrease-indent generators.dout ;
@@ -414,8 +415,20 @@ class generator
}
}
# Names of sources might include directory. We should strip it.
name = $(name:D=) ;
# See if we need to add directory to the target name.
local dir = [ $(sources[1]).name ] ;
dir = $(dir:D) ;
if $(dir) &&
# Never append '..' to target path.
! [ MATCH .*(\\.\\.).* : $(dir) ]
&&
! [ path.is-rooted $(dir) ]
{
# Relative path is always relative to the source
# directory. Retain it, so that users can have files
# with the same in two different subdirectories.
name = $(dir)/$(name) ;
}
}
# Assign an action for each target

View File

@@ -924,7 +924,17 @@ module project-rules
# prject. So, just make the name absolute.
for local p in $(paths)
{
result += [ path.root $(p) [ path.pwd ] ] ;
# If the path is below source location, use relative path.
# Otherwise, use full path just to avoid any ambiguities.
local rel = [ path.relative $(p) $(location) : no-error ] ;
if $(rel) = not-a-child
{
result += [ path.root $(p) [ path.pwd ] ] ;
}
else
{
result += $(rel) ;
}
}
}
else

View File

@@ -306,8 +306,9 @@ rule glob-in-parents ( dir : patterns + : upper-limit ? )
# Assuming 'child' is a subdirectory of 'parent', return the relative
# path from 'parent' to 'child'
#
rule relative ( child parent )
rule relative ( child parent : no-error ? )
{
local not-a-child ;
if $(parent) = "."
{
return $(child) ;
@@ -326,10 +327,26 @@ rule relative ( child parent )
}
else
{
errors.error $(child) is not a subdir of $(parent) ;
not-a-child = true ;
split1 = ;
}
}
return [ join $(split2) ] ;
if $(not-a-child)
{
if $(no-error)
{
return not-a-child ;
}
else
{
errors.error $(child) is not a subdir of $(parent) ;
}
}
else
{
return [ join $(split2) ] ;
}
}
}

View File

@@ -5,10 +5,30 @@
from BoostBuild import Tester
t = Tester()
t.write("project-root.jam", "import gcc ;")
t.write("Jamfile", "exe a : src/a.cpp ;")
# Test that relative path to source, 'src', is preserved.
t.write("Jamroot", "exe a : src/a.cpp ;")
t.write("src/a.cpp", "int main() { return 0; }\n")
t.run_build_system()
t.expect_addition("bin/$toolset/debug/src/a.obj")
# Test that the relative path to source is preserved
# when using 'glob'.
t.rm("bin")
t.write("Jamroot", "exe a : [ glob src/*.cpp ] ;")
t.run_build_system()
t.expect_addition("bin/$toolset/debug/src/a.obj")
# Test that relative path with ".." is *not* added to
# target path.
t.rm(".")
t.write("Jamroot", "")
t.write("a.cpp", "int main() { return 0; }\n")
t.write("build/Jamfile", "exe a : ../a.cpp ; ")
t.run_build_system(subdir="build")
t.expect_addition("build/bin/$toolset/debug/a.obj")
t.cleanup()