diff options
Diffstat (limited to 'libbuild2/scope.ixx')
-rw-r--r-- | libbuild2/scope.ixx | 87 |
1 files changed, 83 insertions, 4 deletions
diff --git a/libbuild2/scope.ixx b/libbuild2/scope.ixx index 01d239b..5975c76 100644 --- a/libbuild2/scope.ixx +++ b/libbuild2/scope.ixx @@ -65,6 +65,50 @@ 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; + } + + return nullptr; + } + + 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; + } + + return nullptr; + } + + inline scope* scope:: weak_scope () { scope* r (root_); @@ -102,9 +146,11 @@ namespace build2 } inline target_key scope:: - find_target_key (name& n, name& o, const location& loc) const + find_target_key (name& n, name& o, + const location& loc, + const target_type* tt) const { - auto p (find_target_type (n, o, loc)); + auto p (find_target_type (n, o, loc, tt)); return target_key { &p.first, &n.dir, @@ -114,9 +160,11 @@ namespace build2 } inline prerequisite_key scope:: - find_prerequisite_key (name& n, name& o, const location& loc) const + find_prerequisite_key (name& n, name& o, + const location& loc, + const target_type* tt) const { - auto p (find_prerequisite_type (n, o, loc)); + auto p (find_prerequisite_type (n, o, loc, tt)); return prerequisite_key { n.proj, { @@ -129,6 +177,37 @@ namespace build2 this}; } + template <typename T> + inline void scope:: + insert_rule (meta_operation_id mid, operation_id oid, + string name, + const rule& r) + { + if (mid != 0) + rules.insert<T> (mid, oid, move (name), r); + else + { + auto& ms (root_scope ()->root_extra->meta_operations); + + for (size_t i (1), n (ms.size ()); i != n; ++i) + { + if (ms[i] != nullptr) + { + // Skip a few well-known meta-operations that cannot possibly + // trigger a rule match. + // + mid = static_cast<meta_operation_id> (i); + + if (mid != noop_id && + mid != info_id && + mid != create_id && + mid != disfigure_id) + rules.insert<T> (mid, oid, name, r); + } + } + } + } + inline dir_path src_out (const dir_path& out, const scope& r) { |