aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/scope.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/scope.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/scope.cxx')
-rw-r--r--libbuild2/scope.cxx52
1 files changed, 43 insertions, 9 deletions
diff --git a/libbuild2/scope.cxx b/libbuild2/scope.cxx
index 842b839..92fc12c 100644
--- a/libbuild2/scope.cxx
+++ b/libbuild2/scope.cxx
@@ -738,7 +738,7 @@ namespace build2
auto r (find_target_type (n, loc));
if (r.first == nullptr)
- fail (loc) << "unknown target type " << n.type;
+ fail (loc) << "unknown target type " << n.type << " in " << n;
bool src (n.pair); // If out-qualified, then it is from src.
if (src)
@@ -784,20 +784,54 @@ namespace build2
if (n == (ns[0].pair ? 2 : 1))
{
name dummy;
- target_key r (find_target_key (ns[0], n == 1 ? dummy : ns[1], loc));
-
- return target_key {
- r.type,
- r.dir,
- n == 1 ? &empty_dir_path : r.out,
- r.name,
- move (r.ext)};
+ return find_target_key (ns[0], n == 1 ? dummy : ns[1], loc);
}
}
fail (loc) << "invalid target name: " << ns << endf;
}
+ pair<const target_type&, optional<string>> scope::
+ find_prerequisite_type (name& n, name& o, const location& loc) const
+ {
+ auto r (find_target_type (n, loc));
+
+ if (r.first == nullptr)
+ fail (loc) << "unknown target type " << n.type << " in " << n;
+
+ if (n.pair) // If out-qualified, then it is from src.
+ {
+ assert (n.pair == '@');
+
+ if (!o.directory ())
+ fail (loc) << "expected directory after '@'";
+ }
+
+ if (!n.dir.empty ())
+ n.dir.normalize (false, true); // Current dir collapses to an empty one.
+
+ if (!o.dir.empty ())
+ o.dir.normalize (false, true); // Ditto.
+
+ return pair<const target_type&, optional<string>> (
+ *r.first, move (r.second));
+ }
+
+ prerequisite_key scope::
+ find_prerequisite_key (names& ns, const location& loc) const
+ {
+ if (size_t n = ns.size ())
+ {
+ if (n == (ns[0].pair ? 2 : 1))
+ {
+ name dummy;
+ return find_prerequisite_key (ns[0], n == 1 ? dummy : ns[1], loc);
+ }
+ }
+
+ fail (loc) << "invalid prerequisite name: " << ns << endf;
+ }
+
static target*
derived_tt_factory (context& c,
const target_type& t, dir_path d, dir_path o, string n)