Skip to content

Commit

Permalink
Add import-search project rule.
Browse files Browse the repository at this point in the history
  • Loading branch information
grafikrobot committed Oct 30, 2023
1 parent 2fc52a7 commit 967b726
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
3 changes: 3 additions & 0 deletions doc/src/history.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ other Jam files.
* *New*: Make parts of internals thread safe to support parallel built-ins.
Currently includes Jam values, hash tables, and filesystem.
-- _René Ferdinand Rivera Morell_
* *New*: Add `import-search` project rule to declare additional search paths
for `import` that refer to searched project locations.
-- _René Ferdinand Rivera Morell_
* Fix consistent use of `OPT_SEMAPHORE` and documentation of `JAM_SEMAPHORE`.
-- _Thomas Brown_

Expand Down
37 changes: 34 additions & 3 deletions src/build/project.jam
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ rule add-project-search ( root : search-paths + )
}


local rule search ( name )
rule search ( name )
{
if [ path.is-rooted $(name) ]
{
Expand All @@ -261,8 +261,9 @@ local rule search ( name )
}
# Do searching for various dir names and jamfiles based on the built
# basename <a>_<b>_<c>[.jam].
local base = [ path.basename $(name) ] ;
local root = [ path.parent $(name) ] ;
local base = [ path.basename $(name) ] ;
local sub = $(base) ;
while $(base)
{
# Check for a regular B2 project in the search path and subdir base.
Expand All @@ -275,6 +276,16 @@ local rule search ( name )
return $(dir) ;
}
}
# Check for a regular B2 project in the search path and subdir subpath.
for local dir in $(.search-path.$(root))
{
dir = [ path.join $(dir) $(sub) ] ;
local jamfile = [ path.glob $(dir) : $(JAMROOT) $(JAMFILE) ] ;
if $(jamfile)
{
return $(dir) ;
}
}
# Check for a <base>.jam to include.
for local dir in $(.search-path.$(root))
{
Expand All @@ -286,12 +297,14 @@ local rule search ( name )
}
if [ path.has-parent $(root) ]
{
sub = [ path.join [ path.basename $(root) ] $(sub) ] ;
base = [ path.basename $(root) ] $(base) ;
base = $(base:L:J=_) ;
root = [ path.parent $(root) ] ;
}
else
{
sub = ;
base = ;
root = ;
}
Expand Down Expand Up @@ -1548,8 +1561,26 @@ module project-rules
# Defines search paths for resolving global, i.e. rooted, project references.
rule project-search ( root : search-paths + )
{
import path ;
import project ;
project.add-project-search $(root) : $(search-paths) ;
}

# Adds the project, or subdirectory of the project, location to the search
# of importing modules.
rule import-search ( name )
{
import modules ;
import project ;
local dir = [ project.search $(name) ] ;
if $(dir)
{
modules.poke : BOOST_BUILD_PATH
: $(dir) [ modules.peek : BOOST_BUILD_PATH ] ;
}
else
{
import errors ;
errors.error Unable find project reference '$(name)'. ;
}
}
}

0 comments on commit 967b726

Please sign in to comment.