From 532e2085deeddd3e94cfbee1ded1e5917aff2b59 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 24 Aug 2015 10:21:59 +0200 Subject: Add support for reversing project qualification to string value --- build/variable.cxx | 27 +++++++++++++++++++++- .../variable/representation/build/bootstrap.build | 4 ++++ tests/variable/representation/buildfile | 18 +++++++++++++++ tests/variable/representation/driver.cxx | 10 ++++++++ tests/variable/representation/test.out | 6 +++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/variable/representation/build/bootstrap.build create mode 100644 tests/variable/representation/buildfile create mode 100644 tests/variable/representation/driver.cxx create mode 100644 tests/variable/representation/test.out diff --git a/build/variable.cxx b/build/variable.cxx index d215b02..03c910d 100644 --- a/build/variable.cxx +++ b/build/variable.cxx @@ -144,6 +144,15 @@ namespace build bool value_traits:: assign (name& n) { + // The below code is quite convoluted because we don't want to + // modify the name until we know it good (if it is not, then it + // will most likely be printed by the caller in diagnostics). + + // Suspend project qualification. + // + const string* p (n.proj); + n.proj = nullptr; + // Convert directory to string. // if (n.directory ()) @@ -158,7 +167,23 @@ namespace build n.value += '/'; } - return n.simple (); + if (!n.simple ()) + { + n.proj = p; // Restore. + return false; + } + + // Convert project qualification to its string representation. + // + if (p != nullptr) + { + string s (*p); + s += '%'; + s += n.value; + s.swap (n.value); + } + + return true; } static bool diff --git a/tests/variable/representation/build/bootstrap.build b/tests/variable/representation/build/bootstrap.build new file mode 100644 index 0000000..6a48e2e --- /dev/null +++ b/tests/variable/representation/build/bootstrap.build @@ -0,0 +1,4 @@ +project = variable-representation +amalgamation = # Disabled. +using config +using test diff --git a/tests/variable/representation/buildfile b/tests/variable/representation/buildfile new file mode 100644 index 0000000..22913d5 --- /dev/null +++ b/tests/variable/representation/buildfile @@ -0,0 +1,18 @@ +# Test reversibility of variable representation. +# +val = -L/ +val += -L/foo/ +#val += dir{-L/} + +val += foo%bar +val += foo% +val += %bar +val += foo%{bar} +#val += foo%file{x} + +using cxx +cxx.ext = cxx + +exe{driver}: cxx{driver} +exe{driver}: test.output = test.out +exe{driver}: test.options = $val diff --git a/tests/variable/representation/driver.cxx b/tests/variable/representation/driver.cxx new file mode 100644 index 0000000..ecff9e2 --- /dev/null +++ b/tests/variable/representation/driver.cxx @@ -0,0 +1,10 @@ +#include + +using namespace std; + +int +main (int argc, const char* argv[]) +{ + for (int i (1); i < argc; ++i) + cout << "'" << argv[i] << "'" << endl; +} diff --git a/tests/variable/representation/test.out b/tests/variable/representation/test.out new file mode 100644 index 0000000..af12c6f --- /dev/null +++ b/tests/variable/representation/test.out @@ -0,0 +1,6 @@ +'-L/' +'-L/foo/' +'foo%bar' +'foo%' +'%bar' +'foo%bar' -- cgit v1.1