aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-06-09 07:40:54 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-06-09 07:40:54 +0200
commitb8cffb11a45add241e4b8420ba96e116efccfbd9 (patch)
tree70bc6987e60c7415b351111517a4bc7eea74f93c /libbuild2
parentdd1cb295722a049fe21c8d0311cb1823ccb0e508 (diff)
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.
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/context.hxx6
-rw-r--r--libbuild2/file.cxx38
-rw-r--r--libbuild2/target.txx5
-rw-r--r--libbuild2/variable.cxx5
-rw-r--r--libbuild2/variable.hxx5
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));}