diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-04-27 09:49:45 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-04-27 10:03:50 +0200 |
commit | 9e5750ae2e3f837f80860aaab6b01e4d556213ed (patch) | |
tree | d3b2e551e444c47b6ce0289969e78360161b6685 /libbuild2/file.ixx | |
parent | 028e10ba787a7dbb46e3fcba6f88f496b76cebc5 (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/file.ixx')
-rw-r--r-- | libbuild2/file.ixx | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/libbuild2/file.ixx b/libbuild2/file.ixx index e940eb3..7c09d3d 100644 --- a/libbuild2/file.ixx +++ b/libbuild2/file.ixx @@ -11,20 +11,76 @@ namespace build2 return source_once (root, base, bf, base); } + inline pair<name, optional<dir_path>> + import_search (scope& base, + name tgt, + bool opt, const optional<string>& md, bool sp, + const location& loc, const char* w) + { + bool dummy (false); + return import_search (dummy, base, move (tgt), opt, md, sp, loc, w); + } + LIBBUILD2_SYMEXPORT const target* - import (context&, const prerequisite_key&, bool existing); + import (context&, + const prerequisite_key&, + bool optional_, + const optional<string>& metadata, // False or metadata key. + bool existing, + const location&); inline const target& import (context& ctx, const prerequisite_key& pk) { assert (ctx.phase == run_phase::match); - return *import (ctx, pk, false); + + // @@ We no longer have location. This is especially bad for the empty + // project case (i.e., where do I need to specify the project name)? + // Looks like the only way to do this is to keep location in name and + // then in prerequisite. Perhaps one day... + // + return *import (ctx, pk, false, nullopt, false, location ()); + } + + inline pair<const target*, import_kind> + import_direct (scope& base, + name tgt, + bool ph2, bool opt, bool md, + const location& loc, const char* w) + { + bool dummy (false); + return import_direct (dummy, base, move (tgt), ph2, opt, md, loc, w); + } + + template <typename T> + inline pair<const T*, import_kind> + import_direct (scope& base, + name tgt, + bool ph2, bool opt, bool md, + const location& loc, const char* w) + { + auto r (import_direct (base, move (tgt), ph2, opt, md, loc, w)); + return make_pair (r.first != nullptr ? &r.first->as<const T> () : nullptr, + r.second); + } + + template <typename T> + inline pair<const T*, import_kind> + import_direct (bool& nv, + scope& base, + name tgt, + bool ph2, bool opt, bool md, + const location& loc, const char* w) + { + auto r (import_direct (nv, base, move (tgt), ph2, opt, md, loc, w)); + return make_pair (r.first != nullptr ? &r.first->as<const T> () : nullptr, + r.second); } inline const target* import_existing (context& ctx, const prerequisite_key& pk) { assert (ctx.phase == run_phase::match || ctx.phase == run_phase::execute); - return import (ctx, pk, true); + return import (ctx, pk, false, nullopt, true, location ()); } } |