Boost logo

Boost-Build :

From: Jurko Gospodnetić (jurko.gospodnetic_at_[hidden])
Date: 2008-07-20 15:03:35


   Hi Steven.

> Steven Watanabe wrote:
>> Projects can also be identified by the directory containing the
>> Jamfile. Oops,
>> that won't work correctly with my patch either.
>>
>> project : requirements <library>relative/path/to/another/project//a ;
>>
>> The path needs to be made absolute in translate-dependencies.
>> I'll add this to the test case, too.
>
> Ok. I've added this to the regression test and updated the patch.
> I still need to add tests for the different variation of native paths and
> paths using all forward slashes. Any other missing tests?

   Hmmm... how about starting the build from a different folder, e.g.
from a sub-project's folder?

   I'm attaching back your patch with some additional (mostly cosmetic)
tweaks I made while reading through the code. Feel free to accept or
discard any of the changes.

   I'm running the Boost library tests on Windows now (msvc-9.0express
toolset) and the good news is that now it correctly started running the
tests while with the previous patch it would brake due to Boost Build
not being able to find some targets.

   Best regards,
     Jurko Gospodnetić

Index: tools/build/v2/build/project.jam
===================================================================
--- tools/build/v2/build/project.jam (revision 47611)
+++ tools/build/v2/build/project.jam (working copy)
@@ -633,9 +633,15 @@
             self.build-dir = [ path.root
                 [ path.make $(specification) ] $(self.location) ] ;
         }
- else if ! $(attribute) in "id" "default-build" "location"
- "source-location" "parent" "projects-to-build" "project-root"
+ else if $(attribute) = "id"
         {
+ id = [ path.root $(specification) / ] ;
+ project.register-id $(id) : $(self.project-module) ;
+ self.id = $(id) ;
+ }
+ else if ! $(attribute) in "default-build" "location" "parent"
+ "projects-to-build" "project-root" "source-location"
+ {
             errors.error "Invalid project attribute '$(attribute)' specified"
                 "for project at '$(self.location)'" ;
         }
@@ -873,8 +879,6 @@
         local attributes = [ project.attributes $(__name__) ] ;
         if $(id)
         {
- id = [ path.root $(id) / ] ;
- project.register-id $(id) : $(__name__) ;
            $(attributes).set id : $(id) ;
         }
 
@@ -906,6 +910,9 @@
             # or wrong consequences.
             if $(location) && $(location) = [ $(attributes).get project-root ]
             {
+ # Re-read the project id, since it might have been changed in
+ # the project's attributes.
+ id = [ $(attributes).get id ] ;
                 # This is Jamroot.
                 if $(id)
                 {
Index: tools/build/v2/build/property-set.jam
===================================================================
--- tools/build/v2/build/property-set.jam (revision 47611)
+++ tools/build/v2/build/property-set.jam (working copy)
@@ -384,6 +384,10 @@
         : $(location) ] ;
     specification = [ property.translate-indirect $(specification)
         : $(jamfile-module) ] ;
+ local project-id = [ project.attribute $(jamfile-module) id ] ;
+ project-id ?= [ path.root $(location) [ path.pwd ] ] ;
+ specification = [ property.translate-dependencies
+ $(specification) : $(project-id) : $(location) ] ;
     specification =
         [ property.expand-subfeatures-in-conditions $(specification) ] ;
     specification = [ property.make $(specification) ] ;
Index: tools/build/v2/build/property.jam
===================================================================
--- tools/build/v2/build/property.jam (revision 47611)
+++ tools/build/v2/build/property.jam (working copy)
@@ -513,6 +513,45 @@
 }
 
 
+# Binds all dependency properties in a list relative to the given project.
+# Targets with absolute paths and targets which have a project specified will
+# have the path to the project adjusted.
+#
+rule translate-dependencies ( specification * : project-id : location )
+{
+ local result ;
+ for local p in $(specification)
+ {
+ local split = [ split-conditional $(p) ] ;
+ local condition = "" ;
+ if $(split)
+ {
+ condition = $(split[1]): ;
+ p = $(split[2]) ;
+ }
+ if dependency in [ feature.attributes $(p:G) ]
+ {
+ local split-target = [ regex.match (.*)//(.*) : $(p:G=) ] ;
+ if $(split-target)
+ {
+ local rooted = [ path.root [ path.make $(split-target[1]) ]
+ [ path.root $(location) [ path.pwd ] ] ] ;
+ result += $(condition)$(p:G)$(rooted)//$(split-target[2]) ;
+ }
+ else
+ {
+ result += $(condition)$(p:G)$(project-id)//$(p:G=) ;
+ }
+ }
+ else
+ {
+ result += $(condition)$(p) ;
+ }
+ }
+ return $(result) ;
+}
+
+
 # Class maintaining a property set -> string mapping.
 #
 class property-map
Index: tools/build/v2/test/inherited_dependency.py
===================================================================
--- tools/build/v2/test/inherited_dependency.py (revision 0)
+++ tools/build/v2/test/inherited_dependency.py (revision 0)
@@ -0,0 +1,166 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2008 Steven Watanabe
+#
+# Distributed under the Boost Software License, Version 1.0. (See
+# accompanying file LICENSE_1_0.txt) or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+from BoostBuild import Tester
+
+tester = Tester()
+
+
+###############################################################################
+#
+# Test without giving the project an explicit id.
+#
+###############################################################################
+
+tester.write("Jamroot", """
+ lib test : test.cpp ;
+ project : requirements <library>test ;
+ build-project a ;
+""")
+
+tester.write("test.cpp", """
+ #ifdef _WIN32
+ __declspec(dllexport)
+ #endif
+ void foo() {}
+""")
+
+tester.write("a/test1.cpp", """
+ int main() {}
+""")
+
+tester.write("a/Jamfile", """
+ exe test1 : test1.cpp ;
+""")
+
+tester.run_build_system()
+
+tester.expect_addition("bin/$toolset/debug/test.obj")
+tester.expect_addition("a/bin/$toolset/debug/test1.exe")
+
+tester.rm("bin")
+tester.rm("a/bin")
+
+
+###############################################################################
+#
+# This time, do give the project an id.
+#
+###############################################################################
+
+tester.write("Jamroot", """
+ lib test : test.cpp ;
+ project test_project : requirements <library>test ;
+ build-project a ;
+""")
+
+tester.run_build_system()
+
+tester.expect_addition("bin/$toolset/debug/test.obj")
+tester.expect_addition("a/bin/$toolset/debug/test1.exe")
+
+tester.rm("bin")
+tester.rm("a/bin")
+
+
+###############################################################################
+#
+# Now, give the project an id in its attributes.
+#
+###############################################################################
+
+tester.write("Jamroot", """
+ lib test : test.cpp ;
+ project : id test_project : requirements <library>test ;
+ build-project a ;
+""")
+
+tester.run_build_system()
+
+tester.expect_addition("bin/$toolset/debug/test.obj")
+tester.expect_addition("a/bin/$toolset/debug/test1.exe")
+
+tester.rm("bin")
+tester.rm("a/bin")
+
+
+###############################################################################
+#
+# Give the project an id in both ways at once.
+#
+###############################################################################
+
+tester.write("Jamroot", """
+ lib test : test.cpp ;
+ project test_project1 : id test_project : requirements <library>test ;
+ build-project a ;
+""")
+
+tester.run_build_system()
+
+tester.expect_addition("bin/$toolset/debug/test.obj")
+tester.expect_addition("a/bin/$toolset/debug/test1.exe")
+
+tester.rm("bin")
+tester.rm("a/bin")
+
+
+###############################################################################
+#
+# Test an absolute path.
+#
+###############################################################################
+
+tester.write("Jamroot", """
+ path-constant here : . ;
+ project test : requirements <source>$(here)/a/test1.cpp ;
+ exe test : test.cpp ;
+""")
+
+tester.run_build_system()
+tester.expect_addition("bin/$toolset/debug/test.exe")
+
+tester.rm("bin")
+tester.rm("a/bin")
+
+
+###############################################################################
+#
+# Make sure that we do not inherit the <source> from the parent as that would
+# would make test3 be a source to itself. Also test dependency properties (e.g.
+# <source>) whose targets are specified using a relative path.
+#
+###############################################################################
+
+tester.write("b/Jamroot", """
+ obj test3 : test3.cpp ;
+""")
+
+tester.write("b/test3.cpp", """
+ void bar() {}
+""")
+
+tester.write("Jamroot", """
+ project test : requirements <source>b//test3 ;
+ build-project a ;
+""")
+
+tester.write("a/Jamfile", """
+ exe test : test1.cpp ;
+""")
+
+tester.write("a/test1.cpp", """
+ void bar();
+ int main() { bar(); }
+""")
+
+tester.run_build_system()
+tester.expect_addition("b/bin/$toolset/debug/test3.obj")
+tester.expect_addition("a/bin/$toolset/debug/test.exe")
+
+tester.cleanup()

Property changes on: tools\build\v2\test\inherited_dependency.py
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/x-python
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Index: tools/build/v2/test/test_all.py
===================================================================
--- tools/build/v2/test/test_all.py (revision 47611)
+++ tools/build/v2/test/test_all.py (working copy)
@@ -169,7 +169,8 @@
           "free_features_request",
           "file_name_handling",
           "sort_rule",
- "ordered_include"
+ "ordered_include",
+ "inherited_dependency"
           ]
 
 if os.name == 'posix':


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk