aboutsummaryrefslogtreecommitdiff
path: root/build2/file.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-04-05 07:26:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-04-05 07:26:09 +0200
commit46a95c974de475070d0eedb07212e5c5282b66bd (patch)
tree687d232cb775f0840c50a9c64bf96d3a16e6f4f3 /build2/file.cxx
parent5c369faa461ec4416d2d4b231a5b36963a7315ce (diff)
Implement --buildfile option, overrides default buildfile, supports '-'
Diffstat (limited to 'build2/file.cxx')
-rw-r--r--build2/file.cxx19
1 files changed, 14 insertions, 5 deletions
diff --git a/build2/file.cxx b/build2/file.cxx
index 10461c4..b735cab 100644
--- a/build2/file.cxx
+++ b/build2/file.cxx
@@ -5,6 +5,7 @@
#include <build2/file>
#include <fstream>
+#include <iostream> // cin
#include <butl/filesystem>
@@ -80,16 +81,24 @@ namespace build2
try
{
- ifstream ifs (bf.string ());
- if (!ifs.is_open ())
- fail << "unable to open " << bf;
+ bool sin (bf.string () == "-");
- ifs.exceptions (ifstream::failbit | ifstream::badbit);
+ ifstream ifs;
+ if (!sin)
+ {
+ ifs.open (bf.string ());
+
+ if (!ifs.is_open ())
+ fail << "unable to open " << bf;
+ }
+
+ istream& is (sin ? std::cin : ifs);
+ is.exceptions (ifstream::failbit | ifstream::badbit);
l5 ([&]{trace << "sourcing " << bf;});
parser p (boot);
- p.parse_buildfile (ifs, bf, root, base);
+ p.parse_buildfile (is, bf, root, base);
}
catch (const ifstream::failure&)
{