aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/build/script/parser.test.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-11-20 22:07:37 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-12-02 17:31:04 +0300
commit0ff39fd77b3127c7a250e7f817e34dfaecbcc208 (patch)
treeedb20351f3d44558201b5668823c191a8722d3a5 /libbuild2/build/script/parser.test.cxx
parent41a6f8b7d3036708f36ea1b5bd5b8d4289428fe5 (diff)
Add support for buildscript depdb preamble
Diffstat (limited to 'libbuild2/build/script/parser.test.cxx')
-rw-r--r--libbuild2/build/script/parser.test.cxx75
1 files changed, 55 insertions, 20 deletions
diff --git a/libbuild2/build/script/parser.test.cxx b/libbuild2/build/script/parser.test.cxx
index 7f2840d..4a3e8cc 100644
--- a/libbuild2/build/script/parser.test.cxx
+++ b/libbuild2/build/script/parser.test.cxx
@@ -71,20 +71,24 @@ namespace build2
// Usages:
//
// argv[0] [-l]
- // argv[0] -d
- // argv[0] -p
+ // argv[0] -b [-t]
+ // argv[0] -d [-t]
+ // argv[0] -q
// argv[0] -g [<diag-name>]
//
// In the first form read the script from stdin and trace the script
- // execution to stdout using the custom print runner.
+ // body execution to stdout using the custom print runner.
//
// In the second form read the script from stdin, parse it and dump the
- // resulting lines to stdout.
+ // script body lines to stdout.
//
- // In the third form read the script from stdin, parse it and print
+ // In the third form read the script from stdin, parse it and dump the
+ // depdb preamble lines to stdout.
+ //
+ // In the forth form read the script from stdin, parse it and print
// line tokens quoting information to stdout.
//
- // In the forth form read the script from stdin, parse it and print the
+ // In the fifth form read the script from stdin, parse it and print the
// low-verbosity script diagnostics name or custom low-verbosity
// diagnostics to stdout. If the script doesn't deduce any of them, then
// print the diagnostics and exit with non-zero code.
@@ -92,10 +96,17 @@ namespace build2
// -l
// Print the script line number for each executed expression.
//
+ // -b
+ // Dump the parsed script body to stdout.
+ //
// -d
- // Dump the parsed script to sdout.
+ // Dump the parsed script depdb preamble to stdout.
//
- // -p
+ // -t
+ // Print true if the body (-b) or depdb preamble (-d) references the
+ // temporary directory and false otherwise.
+ //
+ // -q
// Print the parsed script tokens quoting information to sdout. If a
// token is quoted follow its representation with its quoting
// information in the [<quoting>/<completeness>] form, where:
@@ -115,13 +126,15 @@ namespace build2
enum class mode
{
run,
- dump,
- print,
+ body,
+ depdb_preamble,
+ quoting,
diag
} m (mode::run);
bool print_line (false);
optional<string> diag_name;
+ bool temp_dir (false);
for (int i (1); i != argc; ++i)
{
@@ -129,10 +142,17 @@ namespace build2
if (a == "-l")
print_line = true;
+ else if (a == "-b")
+ m = mode::body;
else if (a == "-d")
- m = mode::dump;
- else if (a == "-p")
- m = mode::print;
+ m = mode::depdb_preamble;
+ else if (a == "-t")
+ {
+ assert (m == mode::body || m == mode::depdb_preamble);
+ temp_dir = true;
+ }
+ else if (a == "-q")
+ m = mode::quoting;
else if (a == "-g")
m = mode::diag;
else
@@ -179,12 +199,14 @@ namespace build2
tt.path (path ("driver"));
+ adhoc_actions acts {perform_update_id};
+
// Parse and run.
//
parser p (ctx);
path_name nm ("buildfile");
- script s (p.pre_parse (tt,
+ script s (p.pre_parse (tt, acts,
cin, nm,
11 /* line */,
(m != mode::diag
@@ -196,9 +218,9 @@ namespace build2
{
case mode::run:
{
- environment e (perform_update_id, tt, false /* temp_dir */);
+ environment e (perform_update_id, tt, s.body_temp_dir);
print_runner r (print_line);
- p.execute (ctx.global_scope, ctx.global_scope, e, s, r);
+ p.execute_body (ctx.global_scope, ctx.global_scope, e, s, r);
break;
}
case mode::diag:
@@ -221,14 +243,27 @@ namespace build2
break;
}
- case mode::dump:
+ case mode::body:
{
- dump (cout, "", s.lines);
+ if (!temp_dir)
+ dump (cout, "", s.body);
+ else
+ cout << (s.body_temp_dir ? "true" : "false") << endl;
+
+ break;
+ }
+ case mode::depdb_preamble:
+ {
+ if (!temp_dir)
+ dump (cout, "", s.depdb_preamble);
+ else
+ cout << (s.depdb_preamble_temp_dir ? "true" : "false") << endl;
+
break;
}
- case mode::print:
+ case mode::quoting:
{
- for (const line& l: s.lines)
+ for (const line& l: s.body)
{
for (const replay_token& rt: l.tokens)
{