aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/module.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-04-27 09:49:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-04-27 10:03:50 +0200
commit9e5750ae2e3f837f80860aaab6b01e4d556213ed (patch)
treed3b2e551e444c47b6ce0289969e78360161b6685 /libbuild2/module.cxx
parent028e10ba787a7dbb46e3fcba6f88f496b76cebc5 (diff)
Rework tool importation along with cli module
Specifically, now config.<tool> (like config.cli) is handled by the import machinery (it is like a shorter alias for config.import.<tool>.<tool>.exe that we already had). And the cli module now uses that instead of custom logic. This also adds support for uniform tool metadata extraction that is handled by the import machinery. As a result, a tool that follows the "build2 way" can be imported with metadata by the buildfile and/or corresponding module without any tool-specific code or brittleness associated with parsing --version or similar outputs. See the cli tool/module for details. Finally, two new flavors of the import directive are now supported: import! triggers immediate importation skipping any rule-specific logic while import? is optional import (analogous to using?). Note that optional import is always immediate. There is also the import-specific metadata attribute which can be specified for these two import flavors in order to trigger metadata importation. For example: import? [metadata] cli = cli%exe{cli} if ($cli != [null]) info "cli version $($cli:cli.version)"
Diffstat (limited to 'libbuild2/module.cxx')
-rw-r--r--libbuild2/module.cxx46
1 files changed, 37 insertions, 9 deletions
diff --git a/libbuild2/module.cxx b/libbuild2/module.cxx
index 28d2468..3abb102 100644
--- a/libbuild2/module.cxx
+++ b/libbuild2/module.cxx
@@ -147,18 +147,32 @@ namespace build2
// (remember, if it's top-level, then it must be in an isolated
// configuration).
//
- pair<name, dir_path> ir (
+ pair<name, optional<dir_path>> ir (
import_search (bs,
name (proj, dir_path (), "libs", "build2-" + mod),
- loc,
- nested /* subprojects */));
+ opt,
+ nullopt /* metadata */,
+ nested /* subprojects */,
+ loc));
- if (!ir.second.empty ())
+ if (ir.first.empty ())
{
+ assert (opt);
+ return nullptr;
+ }
+
+ if (ir.second)
+ {
+ // What if a module is specified with config.import.<mod>.<lib>.libs?
+ // Note that this could still be a project-qualified target.
+ //
+ if (ir.second->empty ())
+ fail (loc) << "direct module target importation not yet supported";
+
// We found the module as a target in a project. Now we need to update
// the target (which will also give us the shared library path).
//
- l5 ([&]{trace << "found " << ir.first << " in " << ir.second;});
+ l5 ([&]{trace << "found " << ir.first << " in " << *ir.second;});
// Create the build context if necessary.
//
@@ -215,7 +229,8 @@ namespace build2
// Load the imported project in the module context.
//
- pair<names, const scope&> lr (import_load (ctx, move (ir), loc));
+ pair<names, const scope&> lr (
+ import_load (ctx, move (ir), false /* metadata */, loc));
l5 ([&]{trace << "loaded " << lr.first;});
@@ -638,7 +653,7 @@ namespace build2
// Note that it would have been nice to keep these inline but we need the
// definition of scope for the variable lookup.
//
- bool
+ const shared_ptr<module>*
load_module (scope& rs,
scope& bs,
const string& name,
@@ -646,8 +661,18 @@ namespace build2
bool opt,
const variable_map& hints)
{
- return cast_false<bool> (bs[name + ".loaded"]) ||
- init_module (rs, bs, name, loc, opt, hints);
+ if (cast_false<bool> (bs[name + ".loaded"]))
+ {
+ if (cast_false<bool> (bs[name + ".configured"]))
+ return &rs.root_extra->modules.find (name)->second.module;
+ }
+ else
+ {
+ if (module_state* ms = init_module (rs, bs, name, loc, opt, hints))
+ return &ms->module;
+ }
+
+ return nullptr;
}
const shared_ptr<module>&
@@ -657,6 +682,9 @@ namespace build2
const location& loc,
const variable_map& hints)
{
+ //@@ TODO: shouldn't we also check for configured? What if the previous
+ // attempt to load it was optional?
+
return cast_false<bool> (bs[name + ".loaded"])
? rs.root_extra->modules.find (name)->second.module
: init_module (rs, bs, name, loc, false /* optional */, hints)->module;