aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbuild2/build/script/parser.hxx3
-rw-r--r--libbuild2/build/script/runner.cxx8
-rw-r--r--libbuild2/build/script/script.cxx9
-rw-r--r--libbuild2/build/script/script.hxx3
-rw-r--r--libbuild2/parser.cxx13
-rw-r--r--libbuild2/rule.cxx38
-rw-r--r--libbuild2/rule.hxx8
-rw-r--r--libbuild2/script/run.cxx50
8 files changed, 74 insertions, 58 deletions
diff --git a/libbuild2/build/script/parser.hxx b/libbuild2/build/script/parser.hxx
index c88898b..40f4c62 100644
--- a/libbuild2/build/script/parser.hxx
+++ b/libbuild2/build/script/parser.hxx
@@ -30,6 +30,9 @@ namespace build2
public:
parser (context& c): build2::script::parser (c) {}
+ // Note that the returned script object references the passed path
+ // name.
+ //
script
pre_parse (istream&, const path_name&, uint64_t line);
diff --git a/libbuild2/build/script/runner.cxx b/libbuild2/build/script/runner.cxx
index f52d1c0..94f1394 100644
--- a/libbuild2/build/script/runner.cxx
+++ b/libbuild2/build/script/runner.cxx
@@ -29,8 +29,8 @@ namespace build2
size_t li,
const location& ll)
{
- if (verb >= 3)
- text << ": " << expr;
+ if (verb >= 2)
+ text << expr;
build2::script::run (env, expr, li, ll);
}
@@ -40,8 +40,8 @@ namespace build2
const command_expr& expr,
size_t li, const location& ll)
{
- if (verb >= 3)
- text << ": ?" << expr;
+ if (verb >= 2)
+ text << expr;
return build2::script::run_if (env, expr, li, ll);
}
diff --git a/libbuild2/build/script/script.cxx b/libbuild2/build/script/script.cxx
index eb5b78c..5dbd24c 100644
--- a/libbuild2/build/script/script.cxx
+++ b/libbuild2/build/script/script.cxx
@@ -33,12 +33,15 @@ namespace build2
// Set the $> variable.
//
{
- value& v (assign (var_pool.insert<path> (">")));
+ //@@ TODO
+ //
+ value& v (assign (var_pool.insert<string> (">")));
if (auto* t = pt.is_a<path_target> ())
- v = t->path ();
+ v = t->path ().string ();
else
- fail << "target " << pt << " is not path-based";
+ //fail << "target " << pt << " is not path-based";
+ v = pt.name; //@@ TMP
}
}
diff --git a/libbuild2/build/script/script.hxx b/libbuild2/build/script/script.hxx
index 6beb5a4..dfd725b 100644
--- a/libbuild2/build/script/script.hxx
+++ b/libbuild2/build/script/script.hxx
@@ -37,6 +37,9 @@ namespace build2
location end_loc;
};
+ //@@ Does environment need script? Can't we just pass it to parser along
+ // with environment.
+ //
class environment: public build2::script::environment
{
public:
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx
index f2cdbfd..93da22a 100644
--- a/libbuild2/parser.cxx
+++ b/libbuild2/parser.cxx
@@ -1128,17 +1128,12 @@ namespace build2
if (!lang)
{
- using build::script::parser;
- using build::script::script;
+ auto* asr (new adhoc_script_rule (move (diag), loc, st.value.size ()));
+ ar.reset (asr);
- parser p (ctx);
istringstream is (move (t.value));
- script s (p.pre_parse (is, path_name (loc.file), loc.line + 1));
-
- ar.reset (new adhoc_script_rule (move (s),
- move (diag),
- loc,
- st.value.size ()));
+ build::script::parser p (ctx);
+ asr->script = p.pre_parse (is, asr->loc.file, loc.line + 1);
}
else if (*lang == "c++")
{
diff --git a/libbuild2/rule.cxx b/libbuild2/rule.cxx
index 849ae82..8b5017d 100644
--- a/libbuild2/rule.cxx
+++ b/libbuild2/rule.cxx
@@ -12,6 +12,9 @@
#include <libbuild2/filesystem.hxx>
#include <libbuild2/diagnostics.hxx>
+#include <libbuild2/build/script/parser.hxx>
+#include <libbuild2/build/script/runner.hxx>
+
using namespace std;
using namespace butl;
@@ -464,6 +467,8 @@ namespace build2
{
tracer trace ("adhoc_rule::perform_update_file");
+ context& ctx (xt.ctx);
+
const file& t (xt.as<file> ());
const path& tp (t.path ());
@@ -542,11 +547,11 @@ namespace build2
text << (diag ? diag->c_str () : "adhoc") << ' ' << t;
}
- if (!t.ctx.dry_run)
+ if (!ctx.dry_run)
{
// @@ TODO
//
- touch (t.ctx, tp, true, verb_never);
+ touch (ctx, tp, true, verb_never);
dd.check_mtime (tp);
}
@@ -559,25 +564,34 @@ namespace build2
{
tracer trace ("adhoc_rule::default_action");
+ context& ctx (t.ctx);
+
execute_prerequisites (a, t);
- if (verb >= 2)
- {
- //@@ TODO
-
- //print_process (args);
- }
- else if (verb)
+ if (verb == 1)
{
// @@ TODO: as above
text << (diag ? diag->c_str () : "adhoc") << ' ' << t;
}
- if (!t.ctx.dry_run)
+ if (!ctx.dry_run || verb >= 2)
{
- // @@ TODO
- //
+ build::script::parser p (ctx);
+ build::script::environment e (script, t);
+
+ if (!ctx.dry_run)
+ {
+ build::script::default_runner r;
+ p.execute (e, r);
+ }
+ else
+ {
+ //@@ TODO:
+ //
+ //build::script::print_runner r;
+ //p.execute (e, r);
+ }
}
return target_state::changed;
diff --git a/libbuild2/rule.hxx b/libbuild2/rule.hxx
index 8799b83..a3d54e7 100644
--- a/libbuild2/rule.hxx
+++ b/libbuild2/rule.hxx
@@ -184,14 +184,12 @@ namespace build2
using script_type = build::script::script;
- adhoc_script_rule (script_type&& s,
- optional<string> d,
- const location& l, size_t b)
- : adhoc_rule (l, b), script (move (s)), diag (move (d)) {}
+ adhoc_script_rule (optional<string> d, const location& l, size_t b)
+ : adhoc_rule (l, b), diag (move (d)) {}
public:
- const script_type script;
const optional<string> diag; // Command name for low-verbosity diag.
+ script_type script;
};
// Ad hoc C++ rule.
diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx
index 00330a5..a1cd733 100644
--- a/libbuild2/script/run.cxx
+++ b/libbuild2/script/run.cxx
@@ -439,34 +439,34 @@ namespace build2
// the program output doesn't match.
//
auto save_regex = [&op, &rl, &rd, &ll, &line] () -> path
- {
- path rp (op + ".regex");
+ {
+ path rp (op + ".regex");
- // Encode here-document regex global flags if present as a file
- // name suffix. For example if icase and idot flags are specified
- // the name will look like:
- //
- // stdout.regex-di
- //
- if (rd.type == redirect_type::here_doc_regex && !rl.flags.empty ())
- rp += '-' + rl.flags;
+ // Encode here-document regex global flags if present as a file
+ // name suffix. For example if icase and idot flags are specified
+ // the name will look like:
+ //
+ // stdout.regex-di
+ //
+ if (rd.type == redirect_type::here_doc_regex && !rl.flags.empty ())
+ rp += '-' + rl.flags;
- // Note that if would be more efficient to directly write chunks
- // to file rather than to compose a string first. Hower we don't
- // bother (about performance) for the sake of the code as we
- // already failed.
- //
- string s;
- for (auto b (rl.lines.cbegin ()), i (b), e (rl.lines.cend ());
- i != e; ++i)
- {
- if (i != b) s += '\n';
- s += line (*i);
- }
+ // Note that if would be more efficient to directly write chunks
+ // to file rather than to compose a string first. Hower we don't
+ // bother (about performance) for the sake of the code as we
+ // already failed.
+ //
+ string s;
+ for (auto b (rl.lines.cbegin ()), i (b), e (rl.lines.cend ());
+ i != e; ++i)
+ {
+ if (i != b) s += '\n';
+ s += line (*i);
+ }
- save (rp, s, ll);
- return rp;
- };
+ save (rp, s, ll);
+ return rp;
+ };
// Finally create regex line string.
//