aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/script/run.hxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-05-07 22:30:17 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-05-17 17:48:32 +0300
commite5827facbfbfe90eae1b71c355a08bf61e2f6e1a (patch)
treebae45ffd2dedcf8dcf2f67fda91878d17d9233a4 /libbuild2/script/run.hxx
parentdb47f3b176421d4325c3439ae54a3cabf953ae7b (diff)
Factor out generic script parsing/executing functionality from build2::test::script namespace
Diffstat (limited to 'libbuild2/script/run.hxx')
-rw-r--r--libbuild2/script/run.hxx62
1 files changed, 62 insertions, 0 deletions
diff --git a/libbuild2/script/run.hxx b/libbuild2/script/run.hxx
new file mode 100644
index 0000000..3f73eed
--- /dev/null
+++ b/libbuild2/script/run.hxx
@@ -0,0 +1,62 @@
+// file : libbuild2/script/run.hxx -*- C++ -*-
+// license : MIT; see accompanying LICENSE file
+
+#ifndef LIBBUILD2_SCRIPT_RUN_HXX
+#define LIBBUILD2_SCRIPT_RUN_HXX
+
+#include <libbuild2/types.hxx>
+#include <libbuild2/utility.hxx>
+
+#include <libbuild2/script/script.hxx>
+
+namespace build2
+{
+ namespace script
+ {
+ // An exception that can be thrown by an expression running function to
+ // exit the script (for example, as a result of executing the exit builtin
+ // by the below run*() functions). The status indicates whether the
+ // execution should be considered to have succeeded or failed.
+ //
+ struct exit
+ {
+ bool status;
+
+ explicit
+ exit (bool s): status (s) {}
+ };
+
+ // Helpers.
+ //
+
+ // Command expression running functions.
+ //
+ // Index is the 1-base index of this command line in the command list.
+ // If it is 0 then it means there is only one command. This information
+ // can be used, for example, to derive file names.
+ //
+ // Location is the start position of this command line in the script. It
+ // can be used in diagnostics.
+ //
+ void
+ run (environment&, const command_expr&, size_t index, const location&);
+
+ bool
+ run_if (environment&, const command_expr&, size_t, const location&);
+
+ // Perform the registered special file cleanups in the direct order and
+ // then the regular cleanups in the reverse order.
+ //
+ void
+ clean (environment&, const location&);
+
+ // Print first 10 directory sub-entries to the diag record. The directory
+ // must exist. Is normally used while issuing diagnostics on non-empty
+ // directory removal failure.
+ //
+ void
+ print_dir (diag_record&, const dir_path&, const location&);
+ }
+}
+
+#endif // LIBBUILD2_SCRIPT_RUN_HXX