diff --git a/v2/build-system.jam b/v2/build-system.jam index f33155295..c0551767e 100755 --- a/v2/build-system.jam +++ b/v2/build-system.jam @@ -122,7 +122,10 @@ if --version in [ modules.peek : ARGV ] # We always load project in "." so that 'use-project' directives has # any chance of been seen. Otherwise, we won't be able to refer to # subprojects using target ids. -current-project = [ project.target [ project.load "." ] ] ; +if [ project.find "." : "." ] +{ + current-project = [ project.target [ project.load "." ] ] ; +} if ! [ feature.values ] { @@ -162,6 +165,50 @@ if "--clean" in [ modules.peek : ARGV ] local bjam-targets ; +# Given a target it, try to find and return corresponding target. +# This is only invoked when there's no Jamfile in "." +# This code somewhat duplicates code in project-target.find but we can't reuse +# that code without project-targets instance. +rule find-target ( target-id ) +{ + local split = [ MATCH (.*)//(.*) : $(target-id) ] ; + + local pm ; + if $(split) + { + pm = [ project.find $(split[1]) : "." ] ; + } + else + { + pm = [ project.find $(target-id) : "." ] ; + } + + local result ; + if $(pm) + { + result = [ project.target $(pm) ] ; + } + + if $(split) + { + result = [ $(result).find $(split[2]) ] ; + } + + return $(result) ; +} + + + +if ! $(current-project) +{ + if ! $(target-ids) + { + ECHO "error: no Jamfile in current directory found, and no target references specified." ; + EXIT ; + } +} + + for local id in $(target-ids) { if $(id) = clean @@ -170,7 +217,16 @@ for local id in $(target-ids) } else { - local t = [ $(current-project).find $(id) : no-error ] ; + local t ; + if $(current-project) + { + t = [ $(current-project).find $(id) : no-error ] ; + } + else + { + t = [ find-target $(id) ] ; + } + if ! $(t) { ECHO "notice: could not find main target " $(id) ; diff --git a/v2/build/project.jam b/v2/build/project.jam index b39e7714b..c463c1692 100644 --- a/v2/build/project.jam +++ b/v2/build/project.jam @@ -159,7 +159,7 @@ rule find ( name : current-location ) project-module = [ module-name $(location) ] ; if ! $(project-module) in $(.jamfile-modules) { - if [ find-jamfile $(location) : no-error ] + if [ path.glob $(location) : $(JAMROOT) $(JAMFILE) ] { project-module = [ load $(location) ] ; } diff --git a/v2/test/out_of_tree.py b/v2/test/out_of_tree.py new file mode 100644 index 000000000..647709870 --- /dev/null +++ b/v2/test/out_of_tree.py @@ -0,0 +1,46 @@ +#!/usr/bin/python + +# Copyright (C) FILL SOMETHING HERE 2005. +# 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) + +# Tests that we can build a project when the current directory is outside of +# that project tree, that is: +# bjam some_dir +# works. +from BoostBuild import Tester, List + +# Create a temporary working directory +t = Tester() + +# Create the needed files +t.write("p1/Jamroot", """ +exe hello : hello.cpp ; +""") +t.write("p1/hello.cpp", """ +int main() +{ + return 0; +} + +""") + +t.write("p2/Jamroot", """ +exe hello2 : hello.cpp ; +exe hello3 : hello.cpp ; +""") +t.write("p2/hello.cpp", """ +int main() +{ + return 0; +} + +""") + +t.run_build_system("p1 p2//hello3") + +t.expect_addition("p1/bin/$toolset/debug/hello.exe") +t.expect_addition("p2/bin/$toolset/debug/hello3.exe") + +t.cleanup() diff --git a/v2/test/test_all.py b/v2/test/test_all.py index 7df9aed9d..0eb83c83b 100644 --- a/v2/test/test_all.py +++ b/v2/test/test_all.py @@ -129,6 +129,7 @@ tests = [ "rebuilds", "wrong_project", "using", "source_locations", + "out_of_tree", ] if os.name == 'posix':