2626#include " version.h"
2727
2828ManifestParser::ManifestParser (State* state, FileReader* file_reader,
29- DupeEdgeAction dupe_edge_action )
29+ ManifestParserOptions options )
3030 : state_(state), file_reader_(file_reader),
31- dupe_edge_action_(dupe_edge_action ), quiet_(false ) {
31+ options_(options ), quiet_(false ) {
3232 env_ = &state->bindings_ ;
3333}
3434
@@ -346,7 +346,7 @@ bool ManifestParser::ParseEdge(string* err) {
346346 if (!CanonicalizePath (&path, &slash_bits, &path_err))
347347 return lexer_.Error (path_err, err);
348348 if (!state_->AddOut (edge, path, slash_bits)) {
349- if (dupe_edge_action_ == kDupeEdgeActionError ) {
349+ if (options_. dupe_edge_action_ == kDupeEdgeActionError ) {
350350 lexer_.Error (" multiple rules generate " + path + " [-w dupbuild=err]" ,
351351 err);
352352 return false ;
@@ -383,6 +383,25 @@ bool ManifestParser::ParseEdge(string* err) {
383383 edge->implicit_deps_ = implicit;
384384 edge->order_only_deps_ = order_only;
385385
386+ if (options_.phony_cycle_action_ == kPhonyCycleActionWarn &&
387+ edge->maybe_phonycycle_diagnostic ()) {
388+ // CMake 2.8.12.x and 3.0.x incorrectly write phony build statements
389+ // that reference themselves. Ninja used to tolerate these in the
390+ // build graph but that has since been fixed. Filter them out to
391+ // support users of those old CMake versions.
392+ Node* out = edge->outputs_ [0 ];
393+ vector<Node*>::iterator new_end =
394+ remove (edge->inputs_ .begin (), edge->inputs_ .end (), out);
395+ if (new_end != edge->inputs_ .end ()) {
396+ edge->inputs_ .erase (new_end, edge->inputs_ .end ());
397+ if (!quiet_) {
398+ Warning (" phony target '%s' names itself as an input; "
399+ " ignoring [-w phonycycle=warn]" ,
400+ out->path ().c_str ());
401+ }
402+ }
403+ }
404+
386405 // Multiple outputs aren't (yet?) supported with depslog.
387406 string deps_type = edge->GetBinding (" deps" );
388407 if (!deps_type.empty () && edge->outputs_ .size () > 1 ) {
@@ -400,7 +419,7 @@ bool ManifestParser::ParseFileInclude(bool new_scope, string* err) {
400419 return false ;
401420 string path = eval.Evaluate (env_);
402421
403- ManifestParser subparser (state_, file_reader_, dupe_edge_action_ );
422+ ManifestParser subparser (state_, file_reader_, options_ );
404423 if (new_scope) {
405424 subparser.env_ = new BindingEnv (env_);
406425 } else {
0 commit comments