aboutsummaryrefslogtreecommitdiff
path: root/build2/utility.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-03-11 16:24:37 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-03-11 16:24:37 +0200
commite58957d6491a08ec212958457c29a14eec787279 (patch)
treeef8d6f76436d9d404a1f91f4b4f80921e967095f /build2/utility.txx
parenta5592d2ddbce898766dd103ae9a4fe6887ab5209 (diff)
Implement --config-{guess,sub} options
Diffstat (limited to 'build2/utility.txx')
-rw-r--r--build2/utility.txx36
1 files changed, 36 insertions, 0 deletions
diff --git a/build2/utility.txx b/build2/utility.txx
new file mode 100644
index 0000000..7848296
--- /dev/null
+++ b/build2/utility.txx
@@ -0,0 +1,36 @@
+// file : build2/utility.txx -*- C++ -*-
+// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+namespace build2
+{
+ template <typename T>
+ T
+ run (const char* const* args, T (*f) (string&), bool err, sha256* checksum)
+ {
+ process pr (start_run (args, err));
+ ifdstream is (pr.in_ofd);
+
+ T r;
+
+ string l; // Last line of output.
+ while (is.peek () != ifdstream::traits_type::eof () && // Keep last line.
+ getline (is, l))
+ {
+ trim (l);
+
+ if (checksum != nullptr)
+ checksum->append (l);
+
+ if (r.empty ())
+ r = f (l);
+ }
+
+ is.close (); // Don't block.
+
+ if (!finish_run (args, err, pr, l))
+ r = T ();
+
+ return r;
+ }
+}