aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/parser.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2024-01-15 08:49:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2024-01-15 08:53:30 +0200
commit8a0ebb2b607c92b8c1bdab7e525da2b711b31565 (patch)
tree4556f7d33dd9fe22fe299b5466b3cb6a930ddfe1 /libbuild2/parser.cxx
parent05ee8c20d83c2f108aa71a65e19b7adff8ff9aa0 (diff)
Automatically alias unknown target types of imported targets
Diffstat (limited to 'libbuild2/parser.cxx')
-rw-r--r--libbuild2/parser.cxx33
1 files changed, 26 insertions, 7 deletions
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx
index baf404a..ebfb698 100644
--- a/libbuild2/parser.cxx
+++ b/libbuild2/parser.cxx
@@ -4226,12 +4226,15 @@ namespace build2
// import() will check the name, if required.
//
- names r (import (*scope_,
- move (n),
- ph2 ? ph2 : bf ? optional<string> (string ()) : nullopt,
- opt,
- meta,
- loc).first);
+ import_result<scope> ir (
+ import (*scope_,
+ move (n),
+ ph2 ? ph2 : bf ? optional<string> (string ()) : nullopt,
+ opt,
+ meta,
+ loc));
+
+ names& r (ir.name);
if (val != nullptr)
{
@@ -4242,6 +4245,19 @@ namespace build2
}
else
{
+ // Import (more precisely, alias) the target type into this project
+ // if not known.
+ //
+ // Note that if the result is ignored (val is NULL), then it's fair
+ // to assume this is not necessary.
+ //
+ if (const scope* iroot = ir.target)
+ {
+ const name& n (r.front ());
+ if (n.typed ())
+ import_target_type (*root_, *iroot, n.type, loc);
+ }
+
if (atype == type::assign) val->assign (move (r), var);
else if (atype == type::prepend) val->prepend (move (r), var);
else val->append (move (r), var);
@@ -4518,7 +4534,8 @@ namespace build2
<< "group-related attribute";
if (!root_->derive_target_type (move (n), *bt, fs).second)
- fail (nl) << "target type " << n << " already defined in this project";
+ fail (nl) << "target type " << n << " already defined in project "
+ << *root_;
next (t, tt); // Get newline.
}
@@ -4565,6 +4582,8 @@ namespace build2
// If we got here, then tn->dir is the scope and tn->value is the target
// type.
//
+ // NOTE: see similar code in import_target_type().
+ //
const target_type* tt (nullptr);
if (const scope* rs = ctx->scopes.find_out (tn->dir).root_scope ())
{