aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-07-23 16:09:40 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-07-23 16:09:40 +0200
commitb6671c9a5840077911cb23f5434c4a7309069e2f (patch)
treef4720c0ff1ad255a6e4a7e5f9da0b9eb982a5e6f
parent063b1a3c038ace6e1d9f8c49c04bf82dd9034828 (diff)
Sanitize project name when forming config.import.<proj> variable
Specifically, '-', '+', and '.' are replaced with '_' to form a "canonical" variable name.
-rw-r--r--build2/file.cxx28
1 files changed, 23 insertions, 5 deletions
diff --git a/build2/file.cxx b/build2/file.cxx
index 3cb6980..1367b8c 100644
--- a/build2/file.cxx
+++ b/build2/file.cxx
@@ -1082,6 +1082,24 @@ namespace build2
return rs;
}
+ // Convert project name to import variable name.
+ //
+ static inline string
+ import_name (const string& p)
+ {
+ // For simplicity let's assume project name is a package name and only
+ // sanitize characters that we don't like from what's valid there.
+ //
+ auto sanitize = [] (char c)
+ {
+ return (c == '-' || c == '+' || c == '.') ? '_' : c;
+ };
+
+ string r;
+ transform (p.begin (), p.end (), back_inserter (r), sanitize);
+ return r;
+ }
+
names
import (scope& ibase, name target, const location& loc)
{
@@ -1119,7 +1137,7 @@ namespace build2
for (;;) // Break-out loop.
{
- string n ("config.import." + proj);
+ string n ("config.import." + import_name (proj));
// config.import.<proj>
//
@@ -1404,7 +1422,7 @@ namespace build2
tracer trace ("import");
assert (pk.proj);
- const string& p (*pk.proj);
+ const string& proj (*pk.proj);
// Target type-specific search.
//
@@ -1470,12 +1488,12 @@ namespace build2
diag_record dr;
dr << fail << "unable to import target " << pk;
- if (p.empty ())
+ if (proj.empty ())
dr << info << "consider adding its installation location" <<
info << "or explicitly specify its project name";
else
- dr << info << "use config.import." << p << " command line variable to "
- << "specifying its project out_root";
+ dr << info << "use config.import." << import_name (proj)
+ << " command line variable to specifying its project out_root";
dr << endf;
}