aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/make-parser.test.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-11-11 13:20:30 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-11-23 13:07:58 +0200
commit939beb11a5ccf58d7fe79a809a1b592c5c9143c0 (patch)
tree2aff4e52f277ecac62ce1cb8bf302ffd0884666a /libbuild2/make-parser.test.cxx
parent189a1c2a8fad0716e0bc4132e21f664c80d7574b (diff)
Add support for dynamic dependencies in ad hoc Buildscript recipes
Specifically, add the new `depdb dyndep` builtin that can be used to extract dynamic dependencies from a program run or a file. For example: obje{hello.o}: cxx{hello} {{ s = $path($<[0]) depdb dyndep $cxx.poptions $cc.poptions --what=header --default-prereq-type=h -- $cxx.path $cxx.poptions $cc.poptions $cxx.mode -M -MG $s diag c++ ($<[0]) o = $path($>) $cxx.path $cxx.poptions $cc.poptions $cc.coptions $cxx.coptions $cxx.mode -o $o -c $s }} Currently only the `make` dependency format is supported.
Diffstat (limited to 'libbuild2/make-parser.test.cxx')
-rw-r--r--libbuild2/make-parser.test.cxx90
1 files changed, 90 insertions, 0 deletions
diff --git a/libbuild2/make-parser.test.cxx b/libbuild2/make-parser.test.cxx
new file mode 100644
index 0000000..189407a
--- /dev/null
+++ b/libbuild2/make-parser.test.cxx
@@ -0,0 +1,90 @@
+// file : libbuild2/make-parser.test.cxx -*- C++ -*-
+// license : MIT; see accompanying LICENSE file
+
+#include <iostream>
+
+#include <libbuild2/types.hxx>
+#include <libbuild2/utility.hxx>
+
+#include <libbuild2/make-parser.hxx>
+#include <libbuild2/diagnostics.hxx>
+
+#undef NDEBUG
+#include <cassert>
+
+using namespace std;
+
+namespace build2
+{
+ int
+ main (int, char* argv[])
+ {
+ bool strict (false);
+
+ // Fake build system driver, default verbosity.
+ //
+ init_diag (1);
+ init (nullptr, argv[0]);
+
+ path_name in ("<stdin>");
+
+ try
+ {
+ cin.exceptions (istream::badbit);
+
+ using make_state = make_parser;
+ using make_type = make_parser::type;
+
+ make_parser make;
+
+ location ll (in, 1);
+ for (string l; !eof (getline (cin, l)); ++ll.line)
+ {
+ if (make.state == make_state::end)
+ {
+ cout << endl;
+ make.state = make_state::begin;
+ }
+
+ // Skip leading blank lines to reduce output noise.
+ //
+ if (make.state == make_state::begin && l.empty ())
+ continue;
+
+ size_t pos (0);
+ do
+ {
+ pair<make_type, string> r (make.next (l, pos, ll, strict));
+
+ cout << (r.first == make_type::target ? 'T' : 'P');
+
+ if (!r.second.empty ())
+ cout << ' ' << r.second;
+
+ cout << endl;
+ }
+ while (pos != l.size ());
+ }
+
+ if (make.state != make_state::end && make.state != make_state::begin)
+ fail (ll) << "incomplete make dependency declaration";
+ }
+ catch (const io_error& e)
+ {
+ cerr << "unable to read stdin: " << e << endl;
+ return 1;
+ }
+ catch (const failed&)
+ {
+ return 1;
+ }
+
+ return 0;
+ }
+}
+
+int
+main (int argc, char* argv[])
+{
+ return build2::main (argc, argv);
+}