From 02d902cb8e5e69b123fcdf170e5eeb9ca5605304 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 15 May 2020 12:11:30 +0200 Subject: Amalgamation cutoff support Now a project that disables amalgamation will not logically "see" an outer project even if it's physically inside its scope. --- libbuild2/scope.ixx | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) (limited to 'libbuild2/scope.ixx') diff --git a/libbuild2/scope.ixx b/libbuild2/scope.ixx index 9aecd48..a3a417f 100644 --- a/libbuild2/scope.ixx +++ b/libbuild2/scope.ixx @@ -5,9 +5,52 @@ namespace build2 { // scope // + inline bool scope:: + root () const + { + return root_ == this; + } + + inline bool scope:: + amalgamatable () const + { + return (root_extra == nullptr || + !root_extra->amalgamation || + *root_extra->amalgamation != nullptr); + } + + inline scope* scope:: + parent_scope () + { + // If this is a root scope and amalgamation is disabled, "jump" straight + // to the global scope. + // + return root () && !amalgamatable () ? &global_scope () : parent_; + } + + inline const scope* scope:: + parent_scope () const + { + return root () && !amalgamatable () ? &global_scope () : parent_; + } + + inline scope* scope:: + root_scope () + { + return root_; + } + + inline const scope* scope:: + root_scope () const + { + return root_; + } + inline scope* scope:: strong_scope () { + // We naturally assume strong_ is not set for non-amalgamatable projects. + // return root_ != nullptr ? root_->strong_ != nullptr ? root_->strong_ : root_ : nullptr; @@ -26,7 +69,9 @@ namespace build2 { scope* r (root_); if (r != nullptr) - for (; r->parent_->root_ != nullptr; r = r->parent_->root_) ; + for (; + r->amalgamatable () && r->parent_->root_ != nullptr; + r = r->parent_->root_) ; return r; } @@ -35,7 +80,9 @@ namespace build2 { const scope* r (root_); if (r != nullptr) - for (; r->parent_->root_ != nullptr; r = r->parent_->root_) ; + for (; + r->amalgamatable () && r->parent_->root_ != nullptr; + r = r->parent_->root_) ; return r; } @@ -44,9 +91,12 @@ namespace build2 { // Scan the parent root scope chain looking for this scope. // - for (const scope* pr (&r); (pr = pr->parent_->root_) != nullptr; ) + for (const scope* pr (&r); + pr->amalgamatable () && (pr = pr->parent_->root_) != nullptr; ) + { if (pr == this) return true; + } return false; } -- cgit v1.1