diff options
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/context.hxx | 6 | ||||
-rw-r--r-- | libbuild2/file.cxx | 38 | ||||
-rw-r--r-- | libbuild2/target.txx | 5 | ||||
-rw-r--r-- | libbuild2/variable.cxx | 5 | ||||
-rw-r--r-- | libbuild2/variable.hxx | 5 |
5 files changed, 20 insertions, 39 deletions
diff --git a/libbuild2/context.hxx b/libbuild2/context.hxx index e4d4d4c..a8b6b01 100644 --- a/libbuild2/context.hxx +++ b/libbuild2/context.hxx @@ -363,10 +363,8 @@ namespace build2 // if not requested (but only in version 1). The exporter should also set // the returned version as the target-specific export.metadata variable. // - // The export.metadata value should start with the version optionally - // followed by the metadata variable prefix (for example, cli in - // cli.version). If the variable prefix is missing, it is assumed to be - // the target name as imported. + // The export.metadata value should start with the version followed by the + // metadata variable prefix (for example, cli in cli.version). // // The following metadata variable names have pre-defined meaning: // 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<names> (v)); + const names& ns (cast<names> (l)); // First verify the version. // @@ -2540,7 +2538,7 @@ namespace build2 // Note: does not change the passed name. // ver = value_traits<uint64_t>::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 <var-prefix>.name // variable. If its missing, set it to the metadata key (i.e., target diff --git a/libbuild2/target.txx b/libbuild2/target.txx index ef14cf5..777653a 100644 --- a/libbuild2/target.txx +++ b/libbuild2/target.txx @@ -188,9 +188,10 @@ namespace build2 { if (auto* ns = cast_null<names> (vars[ctx.var_export_metadata])) { - // Metadata variable prefix is in the second name. + // Metadata variable prefix must be in the second name. // - assert (ns->size () == 2 && (*ns)[1].simple ()); + if (ns->size () < 2 || !(*ns)[1].simple ()) + fail << "invalid metadata variable prefix in target " << *this; return cast_null<T> (vars[(*ns)[1].value + '.' + var]); } diff --git a/libbuild2/variable.cxx b/libbuild2/variable.cxx index 9009fdc..79d0018 100644 --- a/libbuild2/variable.cxx +++ b/libbuild2/variable.cxx @@ -483,11 +483,8 @@ namespace build2 // uint64_t value // uint64_t value_traits<uint64_t>:: - convert (name&& n, name* r) + convert (const name& n, const name* r) { - // Note: in some places we reply on this function not - // changing the passed name. - // if (r == nullptr && n.simple ()) { try diff --git a/libbuild2/variable.hxx b/libbuild2/variable.hxx index c1cfa84..08d4612 100644 --- a/libbuild2/variable.hxx +++ b/libbuild2/variable.hxx @@ -715,7 +715,10 @@ namespace build2 { static_assert (sizeof (uint64_t) <= value::size_, "insufficient space"); - static uint64_t convert (name&&, name*); + // Note: in some places we rely on the convert() function not changing + // the passed names thus we make them const. + // + static uint64_t convert (const name&, const name*); static void assign (value&, uint64_t); static void append (value&, uint64_t); // ADD. static name reverse (uint64_t x) {return name (to_string (x));} |