From b82ba002326f1c541876acc7efec650bac7f6403 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 12 Mar 2019 14:07:11 +0200 Subject: Diagnose out of project inclusion --- build2/parser.cxx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/build2/parser.cxx b/build2/parser.cxx index ef6691d7..3acff378 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -1293,8 +1293,11 @@ namespace build2 const dir_path* opb (pbase_); switch_scope (out_base); - // Use the new scope's src_base to get absolute buildfile path - // if it is relative. + if (root_ == nullptr) + fail (l) << "out of project include from " << out_base; + + // Use the new scope's src_base to get absolute buildfile path if it is + // relative. // if (p.relative ()) p = scope_->src_path () / p.leaf (); @@ -5152,12 +5155,18 @@ namespace build2 auto p (build2::switch_scope (*root_, d)); scope_ = &p.first; - pbase_ = scope_->src_path_; + pbase_ = scope_->src_path_ != nullptr ? scope_->src_path_ : &d; - if (p.second != nullptr && p.second != root_) + if (p.second != root_) { root_ = p.second; - l5 ([&]{trace << "switching to root scope " << root_->out_path ();}); + l5 ([&] + { + if (root_ != nullptr) + trace << "switching to root scope " << root_->out_path (); + else + trace << "switching to out of project scope"; + }); } } -- cgit