From f912a6c1090875b16792da4848c47759a38f1ef4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 29 Apr 2017 08:58:07 +0200 Subject: Fix bug in default target logic --- build2/parser.cxx | 50 +++++++++++++++++++++++++++++++------------------- build2/target.cxx | 46 ++++++++++++++++++++++++---------------------- 2 files changed, 55 insertions(+), 41 deletions(-) (limited to 'build2') diff --git a/build2/parser.cxx b/build2/parser.cxx index 47eca4b..d84ebfa 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -4055,34 +4055,46 @@ namespace build2 // target via an alias. If there are no targets in this buildfile, // then we don't do anything. // - if (default_target_ == nullptr || // No targets in this buildfile. - targets.find (dir::static_type, // Explicit current dir target. - scope_->out_path (), - dir_path (), // Out tree target. - string (), - nullopt, - trace) != nullptr) + if (default_target_ == nullptr) // No targets in this buildfile. return; target& dt (*default_target_); - l5 ([&]{trace (t) << "creating current directory alias for " << dt;}); - - // While this target is not explicitly mentioned in the buildfile, we say - // that we behave as if it were. Thus not implied. - // - target& ct ( - targets.insert (dir::static_type, + target* ct ( + const_cast ( // Ok (serial execution). + targets.find (dir::static_type, // Explicit current dir target. scope_->out_path (), - dir_path (), + dir_path (), // Out tree target. string (), nullopt, - false, - trace).first); + trace))); + + if (ct == nullptr) + { + l5 ([&]{trace (t) << "creating current directory alias for " << dt;}); + // While this target is not explicitly mentioned in the buildfile, we + // say that we behave as if it were. Thus not implied. + // + ct = &targets.insert (dir::static_type, + scope_->out_path (), + dir_path (), + string (), + nullopt, + false, + trace).first; + // Fall through. + } + else if (ct->implied) + { + ct->implied = false; + // Fall through. + } + else + return; // Existing and not implied. - ct.prerequisites_state_.store (2, memory_order_relaxed); - ct.prerequisites_.emplace_back (prerequisite (dt)); + ct->prerequisites_state_.store (2, memory_order_relaxed); + ct->prerequisites_.emplace_back (prerequisite (dt)); } void parser:: diff --git a/build2/target.cxx b/build2/target.cxx index 1922570..f7500f7 100644 --- a/build2/target.cxx +++ b/build2/target.cxx @@ -819,31 +819,33 @@ namespace build2 t = search_existing_target (pk); if (t != nullptr && !t->implied) - return t; - - // Ok, no luck, switch the scope. - // - pair sp ( - switch_scope (*s.rw ().root_scope (), out_base)); - - if (sp.second != nullptr) // Ignore scopes out of any project. + retest = true; + else { - scope& base (sp.first); - scope& root (*sp.second); + // Ok, no luck, switch the scope. + // + pair sp ( + switch_scope (*s.rw ().root_scope (), out_base)); - const dir_path& src_base (base.src_path ()); - - path bf (src_base / "buildfile"); - - if (exists (bf)) - { - l5 ([&]{trace << "loading buildfile " << bf << " for " << pk;}); - retest = source_once (root, base, bf, root); - } - else if (exists (src_base)) + if (sp.second != nullptr) // Ignore scopes out of any project. { - t = dir::search_implied (base, pk, trace); - retest = (t != nullptr); + scope& base (sp.first); + scope& root (*sp.second); + + const dir_path& src_base (base.src_path ()); + + path bf (src_base / "buildfile"); + + if (exists (bf)) + { + l5 ([&]{trace << "loading buildfile " << bf << " for " << pk;}); + retest = source_once (root, base, bf, root); + } + else if (exists (src_base)) + { + t = dir::search_implied (base, pk, trace); + retest = (t != nullptr); + } } } } -- cgit v1.1