diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-07-20 10:29:14 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-07-20 10:29:14 +0200 |
commit | 446d4f91b38bcf2f12f645389e10b443c02c2a00 (patch) | |
tree | d06987010a9f08f05dc58718b8b5eaf740ec0445 | |
parent | c6c8d0be6fd99b2d8ac32c23d1a4141cdbdcd107 (diff) |
Adjust conditional dependency declaration warning logic
Now instead of ignoring imported stuff (which turned out to be racy), we only
consider conditions up to the include boundary. The thinking here is that an
included (but not sourced) buildfile is a standalone entity (e.g., imported
project but also could be just a side-included buildfile).
Note that unfortunately we will still be issuing warnings in imported projects
since there is no straightforward way to know what is being distributed and
what is not while parsing.
-rw-r--r-- | libbuild2/parser.cxx | 18 | ||||
-rw-r--r-- | libbuild2/parser.hxx | 14 |
2 files changed, 19 insertions, 13 deletions
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index 84b6366..fd7c10e 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -247,7 +247,6 @@ namespace build2 { pre_parse_ = false; attributes_.clear (); - imported_ = false; condition_ = nullopt; default_target_ = nullptr; peeked_ = false; @@ -2372,9 +2371,7 @@ namespace build2 // Diagnose conditional prerequisites. Note that we want to diagnose this // even if pns is empty (think empty variable expansion; the literal "no - // prerequisites" case is handled elsewhere). We also want to omit this - // check for imported buildfiles (export stub can reasonably wrap loading - // of a buildfile in a condition). + // prerequisites" case is handled elsewhere). // // @@ TMP For now we only do it during the dist meta-operation. In the // future we should tighten this to any meta-operation provided @@ -2385,7 +2382,6 @@ namespace build2 // rewrite (cli.cxx{} is not always registered). // if (condition_ && - !imported_ && ctx->current_mif != nullptr && ctx->current_mif->id == dist_id) { @@ -2918,6 +2914,18 @@ namespace build2 continue; } + // Clear/restore if/switch location. + // + // We do it here but not in parse_source since the included buildfile is + // in a sense expected to be a standalone entity (think a file included + // from an export stub). + // + auto g = make_guard ([this, old = condition_] () mutable + { + condition_ = old; + }); + condition_ = nullopt; + try { ifdstream ifs (p); diff --git a/libbuild2/parser.hxx b/libbuild2/parser.hxx index 61ecd5b..5f762f7 100644 --- a/libbuild2/parser.hxx +++ b/libbuild2/parser.hxx @@ -91,12 +91,6 @@ namespace build2 parse_export_stub (istream& is, const path_name& name, scope& rs, scope& bs) { - auto g = make_guard ([this, old = imported_] () mutable - { - imported_ = old; - }); - imported_ = true; - parse_buildfile (is, name, &rs, bs); return move (export_value); } @@ -912,8 +906,12 @@ namespace build2 small_vector<attributes, 2> attributes_; - bool imported_ = false; // True if loaded via export stub. - optional<location> condition_; // Innermost if/switch (but not in recipe). + // Innermost if/switch (but excluding recipes). + // + // Note also that this is cleared/restored when crossing the include + // (but not source) boundary. + // + optional<location> condition_; target* default_target_ = nullptr; |