From b8cffb11a45add241e4b8420ba96e116efccfbd9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 9 Jun 2020 07:40:54 +0200 Subject: Make metadata variable prefix mandatory While we could automatically set it if the target is imported, there is nothing we can do if the target is used in the same project. So to avoid confusion we make it mandatory. --- libbuild2/file.cxx | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) (limited to 'libbuild2/file.cxx') diff --git a/libbuild2/file.cxx b/libbuild2/file.cxx index 4c7e6d9..e376ab9 100644 --- a/libbuild2/file.cxx +++ b/libbuild2/file.cxx @@ -2522,15 +2522,13 @@ namespace build2 if (meta) { - // The export.metadata value should start with the version optionally - // followed by the metadata variable prefix. If the variable prefix is - // missing, set it to the metadata key (i.e., target name as imported) - // by default. + // The export.metadata value should start with the version followed by + // the metadata variable prefix. // - value& v (t.assign (*ctx.var_export_metadata)); - if (v && !v.empty ()) + lookup l (t.vars[ctx.var_export_metadata]); + if (l && !l->empty ()) { - names& ns (cast (v)); + const names& ns (cast (l)); // First verify the version. // @@ -2540,7 +2538,7 @@ namespace build2 // Note: does not change the passed name. // ver = value_traits::convert ( - move (ns[0]), ns[0].pair ? &ns[1] : nullptr); + ns[0], ns[0].pair ? &ns[1] : nullptr); } catch (const invalid_argument& e) { @@ -2552,27 +2550,11 @@ namespace build2 fail (loc) << "unexpected metadata version " << ver << " in imported target " << t; - // Next see if we have the metadata variable prefix. + // Next verify the metadata variable prefix. // - switch (ns.size ()) - { - case 1: - { - ns.push_back (name (*meta)); - break; - } - case 2: - { - if (ns[1].simple ()) - break; - } - // Fall through. - default: - { - fail (loc) << "invalid metadata variable prefix in imported " - << "target " << t; - } - } + if (ns.size () != 2 || !ns[1].simple ()) + fail (loc) << "invalid metadata variable prefix in imported " + << "target " << t; // See if we have the stable program name in the .name // variable. If its missing, set it to the metadata key (i.e., target -- cgit v1.1