From c8775bf46f337e2dca4d161251eb89595aef4051 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 17 Nov 2018 23:39:15 +0300 Subject: Add support for builds manifest value --- tests/build-class-expr/driver.cxx | 101 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 tests/build-class-expr/driver.cxx (limited to 'tests/build-class-expr/driver.cxx') diff --git a/tests/build-class-expr/driver.cxx b/tests/build-class-expr/driver.cxx new file mode 100644 index 0000000..343c3b5 --- /dev/null +++ b/tests/build-class-expr/driver.cxx @@ -0,0 +1,101 @@ +// file : tests/build-class-expr/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include +#include + +#include // eof(), operator<<(ostream, exception) +#include + +#include + +// Usages: +// +// argv[0] -p +// argv[0] [] +// +// Parse stdin lines as build configuration class expressions and print them +// or evaluate. +// +// In the first form print expressions to stdout, one per line. +// +// In the second form sequentially match the configuration classes passed as +// arguments against the expressions, updating the match result. If the first +// expression has an underlying class set specified, then transform the +// combined expression, making the underlying class set a starting set for the +// original expression and a restricting set, simultaneously. +// +// On error print the exception description to stderr and exit with the two +// status. Otherwise, if the combined expression doesn't match then exit with +// the one status. Otherwise, exit with zero status. +// +int +main (int argc, char* argv[]) +{ + using namespace std; + using namespace butl; + using namespace bpkg; + + using butl::optional; + + bool print (argc != 1 && argv[1] == string ("-p")); + + assert (!print || argc == 2); + + cin.exceptions (ios::badbit); + + strings cs; + + if (print) + cout.exceptions (ios::failbit | ios::badbit); + else + { + for (int i (1); i != argc; ++i) + cs.push_back (argv[i]); + } + + try + { + string s; + bool r (false); + optional underlying_cls; + + while (!eof (getline (cin, s))) + { + build_class_expr expr (s, "" /* comment */); + + if (print) + cout << expr << endl; + else + { + if (!underlying_cls) + { + underlying_cls = move (expr.underlying_classes); + + if (!underlying_cls->empty ()) + { + build_class_expr expr (*underlying_cls, '+', "" /* comment */); + expr.match (cs, r); + } + } + + expr.match (cs, r); + } + } + + if (underlying_cls && !underlying_cls->empty ()) + { + build_class_expr expr (*underlying_cls, '&', "" /* comment */); + expr.match (cs, r); + } + + return print || r ? 0 : 1; + } + catch (const exception& e) + { + cerr << e << endl; + return 2; + } +} -- cgit v1.1