From f63c0548281015ca1f7d71079c0880e3634063fb Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 29 Sep 2021 08:55:34 +0200 Subject: Add notion of bundle amalgamation scope --- build2/b.cxx | 1 + libbuild2/install/init.cxx | 1 + libbuild2/install/utility.cxx | 2 ++ libbuild2/scope.hxx | 9 +++++++++ libbuild2/scope.ixx | 40 ++++++++++++++++++++++++++++++++++++++++ libbuild2/target.hxx | 6 ++++++ 6 files changed, 59 insertions(+) diff --git a/build2/b.cxx b/build2/b.cxx index 10d4cc5..91d59a5 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -1566,6 +1566,7 @@ main (int argc, char* argv[]) if (const dir_path* a = *rs.root_extra->amalgamation) { trace << " amalgamation: " << *a; + trace << " bundle scope: " << *rs.bundle_scope (); trace << " strong scope: " << *rs.strong_scope (); trace << " weak scope: " << *rs.weak_scope (); } diff --git a/libbuild2/install/init.cxx b/libbuild2/install/init.cxx index 50c0a05..25dc845 100644 --- a/libbuild2/install/init.cxx +++ b/libbuild2/install/init.cxx @@ -421,6 +421,7 @@ namespace build2 // of this scope. Valid values are: // // project -- project scope + // bundle -- bundle amalgamation // strong -- strong amalgamation // weak -- weak amalgamation // global -- all projects (default) diff --git a/libbuild2/install/utility.cxx b/libbuild2/install/utility.cxx index 12215f8..17b1365 100644 --- a/libbuild2/install/utility.cxx +++ b/libbuild2/install/utility.cxx @@ -18,6 +18,8 @@ namespace build2 { if (*s == "project") return &t.root_scope (); + else if (*s == "bundle") + return &t.bundle_scope (); else if (*s == "strong") return &t.strong_scope (); else if (*s == "weak") diff --git a/libbuild2/scope.hxx b/libbuild2/scope.hxx index 97c7be5..f82db72 100644 --- a/libbuild2/scope.hxx +++ b/libbuild2/scope.hxx @@ -69,6 +69,15 @@ namespace build2 const scope* root_scope () const; // Root scope of the outermost "strong" (source-based) amalgamation of + // this scope that has a project name or NULL if this scope is not (yet) + // in any (known) project. If there is no bundle amalgamation, then this + // function returns the root scope of the project (in other words, in this + // case a project is treated as its own bundle, even if it's unnamed). + // + scope* bundle_scope (); + const scope* bundle_scope () const; + + // Root scope of the outermost "strong" (source-based) amalgamation of // this scope or NULL if this scope is not (yet) in any (known) project. // If there is no strong amalgamation, then this function returns the root // scope of the project (in other words, in this case a project is treated diff --git a/libbuild2/scope.ixx b/libbuild2/scope.ixx index 01d239b..c8214f6 100644 --- a/libbuild2/scope.ixx +++ b/libbuild2/scope.ixx @@ -65,6 +65,46 @@ namespace build2 } inline scope* scope:: + bundle_scope () + { + if (auto r = root_) + { + for (auto s (r), a (strong_scope ()); s != a; ) + { + s = s->parent_scope ()->root_scope (); + + if (s->root_extra != nullptr && + s->root_extra->project && + *s->root_extra->project != nullptr && + !(*s->root_extra->project)->empty ()) + r = s; // Last named. + } + + return r; + } + } + + inline const scope* scope:: + bundle_scope () const + { + if (const auto* r = root_) + { + for (auto s (r), a (strong_scope ()); s != a; ) + { + s = s->parent_scope ()->root_scope (); + + if (s->root_extra != nullptr && + s->root_extra->project && + *s->root_extra->project != nullptr && + !(*s->root_extra->project)->empty ()) + r = s; // Last named. + } + + return r; + } + } + + inline scope* scope:: weak_scope () { scope* r (root_); diff --git a/libbuild2/target.hxx b/libbuild2/target.hxx index 5f0165e..1c10621 100644 --- a/libbuild2/target.hxx +++ b/libbuild2/target.hxx @@ -337,6 +337,12 @@ namespace build2 const scope& root_scope () const; + // Root scope of a bundle amalgamation that contains this target. The + // same notes as to root_scope() apply. + // + const scope& + bundle_scope () const {return *root_scope ().bundle_scope ();} + // Root scope of a strong amalgamation that contains this target. // The same notes as to root_scope() apply. // -- cgit v1.1