diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-01-23 10:53:33 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-01-23 10:53:33 +0200 |
commit | 1c7d67d9895c2bdbef13541b154ea17d25b8d515 (patch) | |
tree | ac06cf710a0104c51fdb4c4c47db3e245ac2c793 /build2/prerequisite | |
parent | 91495e646c688eade6b46f21bb40e3da8b8d6f1a (diff) |
Go back to storing scope instead of target in prerequisite
Turns out this was semantically the right way to do it.
Diffstat (limited to 'build2/prerequisite')
-rw-r--r-- | build2/prerequisite | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/build2/prerequisite b/build2/prerequisite index f951e0a..abfb2c1 100644 --- a/build2/prerequisite +++ b/build2/prerequisite @@ -48,20 +48,28 @@ namespace build2 class prerequisite { public: - typedef build2::target target_type; - typedef build2::target_type target_type_type; + using scope_type = build2::scope; + using target_type = build2::target; + using target_type_type = build2::target_type; // Note that unlike targets, for prerequisites an empty out directory // means undetermined rather than being definitely in the out tree. // + // It might seem natural to keep the reference to the owner target instead + // of to the scope. But that's not the semantics that we have, consider: + // + // foo/obj{x}: bar/cxx{y} + // + // bar/ here is relative to the scope, not to foo/. Plus, bar/ can resolve + // to either src or out. + // const optional<string> proj; const target_type_type& type; const dir_path dir; // Normalized absolute or relative (to scope). const dir_path out; // Empty, normalized absolute, or relative. const string name; const optional<string> ext; // Absent if unspecified. - - target_type& owner; // Target to which this prerequisite belongs. + scope_type& scope; target_type* target; // NULL if not yet resolved. Note that this // should always be the "primary target", not @@ -74,36 +82,39 @@ namespace build2 dir_path o, string n, optional<string> e, - target_type& w) + scope_type& s) : proj (move (p)), type (t), dir (move (d)), out (move (o)), name (move (n)), ext (move (e)), - owner (w), + scope (s), target (nullptr) {} - // Make a copy for a new owner target. Note that both owner targets should - // be in the same scope. - // - prerequisite (const prerequisite&, target_type& owner); - // Make a prerequisite from a target. // - prerequisite (target_type&, target_type& owner); - - prerequisite (const prerequisite&) = delete; - prerequisite (prerequisite&&) = default; - - prerequisite& operator= (const prerequisite&) = delete; - prerequisite& operator= (prerequisite&&) = default; + explicit + prerequisite (target_type&); // Note that the returned key "tracks" the prerequisite; that is, any // updates to the prerequisite's members will be reflected in the key. // prerequisite_key - key () const; + key () const + { + return prerequisite_key {proj, {&type, &dir, &out, &name, ext}, &scope}; + } + + // Return true if this prerequisite instance (physically) belongs to the + // target's prerequisite list. Note that this test only works if you use + // references to the container elements and the container hasn't been + // resized since such a reference was obtained. Normally this function is + // used when iterating over a combined prerequisites range to detect if + // the prerequisite came from the group (see group_prerequisites). + // + bool + belongs (const target_type&) const; // Prerequisite (target) type. // |