diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-01-26 13:00:34 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-01-26 13:00:34 +0200 |
commit | 9b238b9b81a04554edbd6bc35d12aac0433cd511 (patch) | |
tree | 4873066ede5b9c1efcdc970603a4695bbcfb7e2b /libbuild2 | |
parent | 614ac547aabbf9c6168e3ad42dad6ee022de2080 (diff) |
Make bash module install into bin/<project>.bash/ to avoid clashes
Also, expect the first component in the import path to be full project
name even in case it has the .bash extension.
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/bash/init.cxx | 5 | ||||
-rw-r--r-- | libbuild2/bash/rule.cxx | 51 | ||||
-rw-r--r-- | libbuild2/bash/utility.hxx | 20 | ||||
-rw-r--r-- | libbuild2/install/rule.cxx | 1 |
4 files changed, 57 insertions, 20 deletions
diff --git a/libbuild2/bash/init.cxx b/libbuild2/bash/init.cxx index cf5307f..a1effa1 100644 --- a/libbuild2/bash/init.cxx +++ b/libbuild2/bash/init.cxx @@ -48,14 +48,13 @@ namespace build2 { using namespace install; - // Install into bin/<project>/ by default stripping the .bash - // extension from <project> if present. + // Install bash{} into bin/<project>.bash/ by default. // const project_name& p (project (rs)); if (!p.empty ()) { - install_path<bash> (bs, dir_path ("bin") /= project_base (p)); + install_path<bash> (bs, dir_path ("bin") /= modules_install_dir (p)); install_mode<bash> (bs, "644"); } } diff --git a/libbuild2/bash/rule.cxx b/libbuild2/bash/rule.cxx index f2c1eae..5ba298c 100644 --- a/libbuild2/bash/rule.cxx +++ b/libbuild2/bash/rule.cxx @@ -126,7 +126,7 @@ namespace build2 // apply). // string ext (p.ext ? *p.ext : "bash"); - path ip (dir_path (project_base (*p.proj)) / p.dir / p.name); + path ip (dir_path (modules_install_dir (*p.proj)) / p.dir / p.name); if (!ext.empty ()) { @@ -217,21 +217,45 @@ namespace build2 const target& t, const string& n) const { - // Derive (relative) import path from the import name. + // Derive (relative) import path from the import name. And derive import + // installed path from that by adding the .bash extension to the first + // component. // - path ip; + path ip, iip; + project_name pn; try { ip = path (n); - if (ip.empty () || ip.absolute ()) + if (ip.empty () || ip.simple () || ip.absolute ()) throw invalid_path (n); if (ip.extension_cstring () == nullptr) ip += ".bash"; ip.normalize (); + + auto b (ip.begin ()), e (ip.end ()); + + try + { + pn = project_name (*b); + } + catch (const invalid_argument& e) + { + fail (l) << "invalid import path '" << n << "': " << e.what (); + } + + char s (b++.separator ()); + + iip = path (modules_install_dir (pn) + s) / path (b, e); + + // Strip the .bash extension from the project name in this path to + // be able to compare it to paths inside the project (see below). + // + if (pn.extension () == "bash") + ip = path (pn.base ("bash") + s) / path (b, e); } catch (const invalid_path&) { @@ -261,19 +285,19 @@ namespace build2 // // But we still do a simple match first since it can quickly weed // out candidates that cannot possibly match. - // - if (!pp.sup (ip)) - continue; - // See if this is import-installed target (refer to search() for - // details). + // See if this is import-installed target (refer to search() above + // for details). // if (size_t n = pt.data) { + if (!pp.sup (iip)) + continue; + // Both are normalized so we can compare the "tails". // const string& ps (pp.string ()); - const string& is (ip.string ()); + const string& is (iip.string ()); if (path::traits_type::compare ( ps.c_str () + ps.size () - n, n, @@ -288,6 +312,9 @@ namespace build2 if (const scope* rs = b->base_scope ().root_scope ()) { + if (!pp.sup (ip) || project (*rs) != pn) + continue; + const dir_path& d (pp.sub (rs->src_path ()) ? rs->src_path () : rs->out_path ()); @@ -366,7 +393,7 @@ namespace build2 "source \"$(dirname" " \"$(readlink -f" " \"${BASH_SOURCE[0]}\")\")/" - + ip.string () + "\""; + + iip.string () + "\""; } else { @@ -387,7 +414,7 @@ namespace build2 return "source \"$(dirname" " \"${BASH_SOURCE[0]}\")/" - + o + ip.string () + "\""; + + o + iip.string () + "\""; } } else diff --git a/libbuild2/bash/utility.hxx b/libbuild2/bash/utility.hxx index 087fc38..e5e4377 100644 --- a/libbuild2/bash/utility.hxx +++ b/libbuild2/bash/utility.hxx @@ -11,14 +11,26 @@ namespace build2 { namespace bash { - // Strip the .bash extension from the project name. + // Return the bash{} modules installation directory under bin/. // - // Note that the result may not be a valid project name. + // Note that we used to install into bin/<project>/ but that has a good + // chance of clashing with the project's executable. Adding the .bash + // extension feels like a good idea since in our model the executables + // should not use the .bash extension (only modules) and therefore are + // unlikely to clash with this name. + // + // One drawback of this approach is that in case of a project like + // libbutl.bash we now have different module directories inside the + // project (libbutl/) and when installed (libbutl.bash/). Also, the + // installation directory will be shared with the libbutl project but + // that's probably ok (and we had the same issue before). // inline string - project_base (const project_name& pn) + modules_install_dir (const project_name& pn) { - return pn.base ("bash"); + // Strip the .bash extension if present not to duplicate it. + // + return pn.base ("bash") + ".bash"; } } } diff --git a/libbuild2/install/rule.cxx b/libbuild2/install/rule.cxx index d4c70c0..b8d716d 100644 --- a/libbuild2/install/rule.cxx +++ b/libbuild2/install/rule.cxx @@ -1323,7 +1323,6 @@ namespace build2 } } - // Finally handle installable prerequisites. // r |= reverse_execute_prerequisites (a, t); |