From 8a0ebb2b607c92b8c1bdab7e525da2b711b31565 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 15 Jan 2024 08:49:57 +0200 Subject: Automatically alias unknown target types of imported targets --- libbuild2/parser.cxx | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'libbuild2/parser.cxx') 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 ()) : nullopt, - opt, - meta, - loc).first); + import_result ir ( + import (*scope_, + move (n), + ph2 ? ph2 : bf ? optional (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 ()) { -- cgit v1.1