From e58957d6491a08ec212958457c29a14eec787279 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 11 Mar 2016 16:24:37 +0200 Subject: Implement --config-{guess,sub} options --- build2/utility.txx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 build2/utility.txx (limited to 'build2/utility.txx') 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 + 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; + } +} -- cgit v1.1