aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/scope.ixx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-05-15 12:11:30 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-05-27 08:28:34 +0200
commit02d902cb8e5e69b123fcdf170e5eeb9ca5605304 (patch)
tree29ed61127744a3fc1554bee96230342cae8f5972 /libbuild2/scope.ixx
parentba1fb800d20e7757cd8523a0793f63cff137c7cf (diff)
Amalgamation cutoff support
Now a project that disables amalgamation will not logically "see" an outer project even if it's physically inside its scope.
Diffstat (limited to 'libbuild2/scope.ixx')
-rw-r--r--libbuild2/scope.ixx56
1 files changed, 53 insertions, 3 deletions
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;
}