aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-05-16 10:10:59 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-05-16 10:10:59 +0200
commite04fc00e978bb242f2aa6f0d1a6c4075048c9e09 (patch)
tree93f8d9c23cd25e473122fb78e75800f73370a9d3
parenta933cdeb0c674409bbd52757bcef314fd8bddb46 (diff)
Enter export stub targets with correct out
-rw-r--r--libbuild2/file.cxx2
-rw-r--r--libbuild2/parser.cxx48
-rw-r--r--libbuild2/parser.hxx20
3 files changed, 46 insertions, 24 deletions
diff --git a/libbuild2/file.cxx b/libbuild2/file.cxx
index 99eab96..c22fff9 100644
--- a/libbuild2/file.cxx
+++ b/libbuild2/file.cxx
@@ -2732,7 +2732,7 @@ namespace build2
});
parser p (ctx);
- v = p.parse_export_stub (ifs, path_name (es), gs, ts);
+ v = p.parse_export_stub (ifs, path_name (es), *root, gs, ts);
}
// If there were no export directive executed in an export stub,
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx
index 3e8b30a..750eda2 100644
--- a/libbuild2/parser.cxx
+++ b/libbuild2/parser.cxx
@@ -270,10 +270,11 @@ namespace build2
scope* root,
scope& base,
target* tgt,
- prerequisite* prq)
+ prerequisite* prq,
+ bool enter)
{
lexer l (is, in);
- parse_buildfile (l, root, base, tgt, prq);
+ parse_buildfile (l, root, base, tgt, prq, enter);
}
void parser::
@@ -281,7 +282,8 @@ namespace build2
scope* root,
scope& base,
target* tgt,
- prerequisite* prq)
+ prerequisite* prq,
+ bool enter)
{
path_ = &l.name ();
lexer_ = &l;
@@ -300,8 +302,8 @@ namespace build2
? auto_project_env (*root_)
: auto_project_env ());
- if (path_->path != nullptr)
- enter_buildfile (*path_->path); // Note: needs scope_.
+ if (enter && path_->path != nullptr)
+ enter_buildfile (*path_->path);
token t;
type tt;
@@ -321,6 +323,25 @@ namespace build2
fail (t) << "unexpected " << t;
}
+ names parser::
+ parse_export_stub (istream& is, const path_name& name,
+ const scope& rs, scope& gs, scope& ts)
+ {
+ // Enter the export stub manually with correct out.
+ //
+ if (name.path != nullptr)
+ {
+ dir_path out (!rs.out_eq_src ()
+ ? out_src (name.path->directory (), rs)
+ : dir_path ());
+
+ enter_buildfile (*name.path, move (out));
+ }
+
+ parse_buildfile (is, name, &gs, ts, nullptr, nullptr, false /* enter */);
+ return move (export_value);
+ }
+
token parser::
parse_variable (lexer& l, scope& s, const variable& var, type kind)
{
@@ -8644,7 +8665,7 @@ namespace build2
}
void parser::
- enter_buildfile (const path& p)
+ enter_buildfile (const path& p, optional<dir_path> out)
{
tracer trace ("parser::enter_buildfile", &path_);
@@ -8652,17 +8673,20 @@ namespace build2
// Figure out if we need out.
//
- dir_path out;
- if (scope_->src_path_ != nullptr &&
- scope_->src_path () != scope_->out_path () &&
- d.sub (scope_->src_path ()))
+ dir_path o;
+ if (out)
+ o = move (*out);
+ else if (root_ != nullptr &&
+ root_->src_path_ != nullptr &&
+ !root_->out_eq_src () &&
+ d.sub (*root_->src_path_))
{
- out = out_src (d, *root_);
+ o = out_src (d, *root_);
}
ctx->targets.insert<buildfile> (
move (d),
- move (out),
+ move (o),
p.leaf ().base ().string (),
p.extension (), // Always specified.
trace);
diff --git a/libbuild2/parser.hxx b/libbuild2/parser.hxx
index b3a5395..eea8507 100644
--- a/libbuild2/parser.hxx
+++ b/libbuild2/parser.hxx
@@ -69,14 +69,20 @@ namespace build2
scope* root,
scope& base,
target* = nullptr,
- prerequisite* = nullptr);
+ prerequisite* = nullptr,
+ bool enter_buildfile = true);
void
parse_buildfile (lexer&,
scope* root,
scope& base,
target* = nullptr,
- prerequisite* = nullptr);
+ prerequisite* = nullptr,
+ bool enter_buildfile = true);
+
+ names
+ parse_export_stub (istream& is, const path_name& name,
+ const scope& rs, scope& gs, scope& ts);
buildspec
parse_buildspec (istream&, const path_name&);
@@ -87,14 +93,6 @@ namespace build2
pair<value, token>
parse_variable_value (lexer&, scope&, const dir_path*, const variable&);
- names
- parse_export_stub (istream& is, const path_name& name,
- scope& rs, scope& bs)
- {
- parse_buildfile (is, name, &rs, bs);
- return move (export_value);
- }
-
// Parse an evaluation context (`(...)`).
//
value
@@ -620,7 +618,7 @@ namespace build2
// Enter buildfile as a target.
//
void
- enter_buildfile (const path&);
+ enter_buildfile (const path&, optional<dir_path> out = nullopt);
// Lexer.
//