Skip to content

Commit

Permalink
Allow regular dirs for import-search rule.
Browse files Browse the repository at this point in the history
And document import-search rule.
  • Loading branch information
grafikrobot committed Nov 30, 2023
1 parent 967b726 commit 46be607
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
2 changes: 1 addition & 1 deletion doc/src/history.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ other Jam files.
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.
for `import` that refer to searched project locations, or other directories.
-- _René Ferdinand Rivera Morell_
* Fix consistent use of `OPT_SEMAPHORE` and documentation of `JAM_SEMAPHORE`.
-- _Thomas Brown_
Expand Down
19 changes: 19 additions & 0 deletions doc/src/reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ are not allowed.
[[bbv2.reference.rules.test-suite]]`test-suite`::
This rule is deprecated and equivalent to `alias`.

[[bbv2.reference.rules.import-search]]`import-search`::
+
====
[horizontal]
Jam:: `rule import-search ( reference )`
====
+
Adds the given `reference` path to the set of directories that an `import` will
search. The `reference` can be a plain directory or a known project path. If a
project path is given it will be searched for and resolved to include any
sub-project path in the reference. If a directory is given it will be rooted
relative to the current project location. Example project path usage:
+
----
import-search /boost/config/checks ;
import-search /boost/predef/tools/checks ;
----
+

:leveloffset: +1

include::../../src/engine/mod_jam_builtin.h[tag=reference]
Expand Down
33 changes: 28 additions & 5 deletions src/build/project.jam
Original file line number Diff line number Diff line change
Expand Up @@ -1567,20 +1567,43 @@ module project-rules

# Adds the project, or subdirectory of the project, location to the search
# of importing modules.
rule import-search ( name )
rule import-search ( reference )
{
import modules ;
import path ;
import project ;
local dir = [ project.search $(name) ] ;
local dir ;
if ! $(dir)
{
local project-dir = [ project.search $(reference) ] ;
if $(project-dir)
{
# Resolved it as a project reference.
dir = $(project-dir) ;
}
}
if ! $(dir)
{
local os-dir = [ path.root $(reference) [ path.pwd ] ] ;
if ! [ CHECK_IF_FILE [ path.native $(os-dir) ] ]
{
# It's not a file, i.e. it's a directory.
dir = $(os-dir) ;
}
}
if $(dir)
{
modules.poke : BOOST_BUILD_PATH
: $(dir) [ modules.peek : BOOST_BUILD_PATH ] ;
local b2-path = [ modules.peek : BOOST_BUILD_PATH ] ;
if ! $(dir) in $(b2-path)
{
modules.poke : BOOST_BUILD_PATH : $(dir) $(b2-path) ;
}
}
else
{
import errors ;
errors.error Unable find project reference '$(name)'. ;
errors.error Unable find project reference '$(reference)'. ;
return ;
}
}
}
3 changes: 2 additions & 1 deletion src/build/virtual-target.jam
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ class abstract-file-target : virtual-target
{
import errors : error : errors.error ;
errors.error <tag>@rulename is present but is not the only
<tag> feature. ;
<tag> feature. Tags present..
: $(tag) ;
}

self.name = [ indirect.call $(rule-name) $(specified-name)
Expand Down

0 comments on commit 46be607

Please sign in to comment.