diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-06-05 06:36:30 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-06-05 06:36:30 +0200 |
commit | 9ec2bdd87659438b4aa021a10c4a4977ef77118e (patch) | |
tree | 12580b4d0b82bce80047b067c3bb221b49be7449 /libbuild2/buildspec.cxx | |
parent | d280946474568925016359be742b59fd6c000c52 (diff) |
Add ability to specify ad hoc recipe actions
We are reusing the buildspec syntax for that.
Diffstat (limited to 'libbuild2/buildspec.cxx')
-rw-r--r-- | libbuild2/buildspec.cxx | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/libbuild2/buildspec.cxx b/libbuild2/buildspec.cxx new file mode 100644 index 0000000..bd580ca --- /dev/null +++ b/libbuild2/buildspec.cxx @@ -0,0 +1,109 @@ +// file : libbuild2/buildspec.cxx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +#include <libbuild2/buildspec.hxx> + +#include <libbuild2/diagnostics.hxx> + +using namespace std; + +namespace build2 +{ + ostream& + operator<< (ostream& os, const targetspec& s) + { + if (!s.src_base.empty ()) + { + // Avoid printing './' in './@...', similar to what we do for the + // {target,prerequisite}_key. + // + if (stream_verb (os).path < 1) + { + const string& r (diag_relative (s.src_base, false)); + + if (!r.empty ()) + os << r << '@'; + } + else + os << s.src_base << '@'; + } + + os << s.name; + return os; + } + + ostream& + operator<< (ostream& os, const opspec& s) + { + bool hn (!s.name.empty ()); + bool ht (!s.empty ()); + + os << (hn ? "\"" : "") << s.name << (hn ? "\"" : ""); + + if (hn && ht) + os << '('; + + for (auto b (s.begin ()), i (b); i != s.end (); ++i) + os << (i != b ? " " : "") << *i; + + for (const value& v: s.params) + { + os << ", "; + + if (v) + { + names storage; + os << reverse (v, storage); + } + else + os << "[null]"; + } + + if (hn && ht) + os << ')'; + + return os; + } + + ostream& + operator<< (ostream& os, const metaopspec& s) + { + bool hn (!s.name.empty ()); + bool ho (!s.empty ()); + + os << (hn ? "\'" : "") << s.name << (hn ? "\'" : ""); + + if (hn && ho) + os << '('; + + for (auto b (s.begin ()), i (b); i != s.end (); ++i) + os << (i != b ? " " : "") << *i; + + for (const value& v: s.params) + { + os << ", "; + + if (v) + { + names storage; + os << reverse (v, storage); + } + else + os << "[null]"; + } + + if (hn && ho) + os << ')'; + + return os; + } + + ostream& + operator<< (ostream& os, const buildspec& s) + { + for (auto b (s.begin ()), i (b); i != s.end (); ++i) + os << (i != b ? " " : "") << *i; + + return os; + } +} |