From 96908ec43ed27d9f34da27b6a94a6db357465056 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 14 May 2020 14:18:50 +0300 Subject: Add build script --- libbuild2/build/script/parser.test.cxx | 145 +++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 libbuild2/build/script/parser.test.cxx (limited to 'libbuild2/build/script/parser.test.cxx') diff --git a/libbuild2/build/script/parser.test.cxx b/libbuild2/build/script/parser.test.cxx new file mode 100644 index 0000000..2763464 --- /dev/null +++ b/libbuild2/build/script/parser.test.cxx @@ -0,0 +1,145 @@ +// file : libbuild2/build/script/parser.test.cxx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +using namespace std; + +namespace build2 +{ + namespace build + { + namespace script + { + class print_runner: public runner + { + public: + print_runner (bool line): line_ (line) {} + + virtual void + enter (environment&, const location&) override {} + + virtual void + run (environment&, + const command_expr& e, + size_t i, + const location&) override + { + cout << e; + + if (line_) + cout << " # " << i; + + cout << endl; + } + + virtual bool + run_if (environment&, + const command_expr& e, + size_t i, + const location&) override + { + cout << "? " << e; + + if (line_) + cout << " # " << i; + + cout << endl; + + return e.back ().pipe.back ().program.string () == "true"; + } + + virtual void + leave (environment&, const location&) override {} + + private: + bool line_; + }; + + // Usage: argv[0] [-l] + // + int + main (int argc, char* argv[]) + { + tracer trace ("main"); + + // Fake build system driver, default verbosity. + // + init_diag (1); + init (nullptr, argv[0]); + + // Serial execution. + // + scheduler sched (1); + global_mutexes mutexes (1); + context ctx (sched, mutexes); + + bool line (false); + + for (int i (1); i != argc; ++i) + { + string a (argv[i]); + + if (a == "-l") + line = true; + else + assert (false); + } + + try + { + cin.exceptions (istream::failbit | istream::badbit); + + // Enter mock target. Use fixed name and path so that we can use + // them in expected results. Strictly speaking target path should + // be absolute. However, the buildscript implementation doesn't + // really care. + // + file& tt ( + ctx.targets.insert (work, + dir_path (), + "driver", + string (), + trace)); + + tt.path (path ("driver")); + + // Parse and run. + // + path_name nm ("buildfile"); + + script s; + parser p (ctx); + p.pre_parse (cin, nm, 11 /* line */, s); + + environment e (s, tt); + print_runner r (line); + p.execute (e, r); + } + catch (const failed&) + { + return 1; + } + + return 0; + } + } + } +} + +int +main (int argc, char* argv[]) +{ + return build2::build::script::main (argc, argv); +} -- cgit v1.1