diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2021-04-22 14:59:42 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2021-04-22 14:59:42 +0200 |
commit | 7a96e3b0a4bb573bb26ca8ff93b97900bdb486b3 (patch) | |
tree | 1006d034e6fd8f4fe6859571d34f6271158af2be | |
parent | 40863a594372ede117533d5c0970a96d60e34371 (diff) |
Add <version> install directory substitution in addition to <project>
-rw-r--r-- | doc/manual.cli | 6 | ||||
-rw-r--r-- | libbuild2/install/init.cxx | 25 |
2 files changed, 23 insertions, 8 deletions
diff --git a/doc/manual.cli b/doc/manual.cli index 3ee3016..b12fa84 100644 --- a/doc/manual.cli +++ b/doc/manual.cli @@ -5901,9 +5901,9 @@ man share/man/ install.man man<N> man/man<N>/ install.man<N> \ -The \c{<project>} and \c{<private>} substitutions in these -\c{config.install.*} values are replaced with the project name and private -subdirectory, respectively. If either is empty, then the corresponding +The \c{<project>}, \c{<version>}, and \c{<private>} substitutions in these +\c{config.install.*} values are replaced with the project name, version, and +private subdirectory, respectively. If either is empty, then the corresponding directory component is ignored. The optional private installation subdirectory (\c{<private>}) mechanism can diff --git a/libbuild2/install/init.cxx b/libbuild2/install/init.cxx index 74e9301..14045e1 100644 --- a/libbuild2/install/init.cxx +++ b/libbuild2/install/init.cxx @@ -52,16 +52,31 @@ namespace build2 // Note: watch out for the small std::function optimization. // - auto subst = [prv, &rs] (const string& var, string& r) + struct data { - if (var == "project") + const dir_path* prv; + const dir_path& val; + const variable& var; + } d {prv, val, var}; + + auto subst = [&d, &rs] (const string& n, string& r) + { + if (n == "project") { r += project (rs).string (); } - else if (var == "private") + else if (n == "version") + { + if (const auto* v = cast_null<string> (rs.vars[rs.ctx.var_version])) + r += *v; + else + fail << "no version variable in project " << project (rs) << + info << "required in " << d.var << " value '" << d.val << "'"; + } + else if (n == "private") { - if (prv != nullptr && !prv->empty ()) - r += prv->string (); + if (d.prv != nullptr && !d.prv->empty ()) + r += d.prv->string (); } else return false; |