aboutsummaryrefslogtreecommitdiff
path: root/build/file.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-03-24 08:53:06 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-03-24 08:53:06 +0200
commita94dcda7f00b10cb22b5f2138b1c29bcfbe7de37 (patch)
treec4ca2c4b2ea08285774569283120233a03aa2cb3 /build/file.cxx
parenteaaa82bd9c1e24a83dcea3857f5fd75d0dfb6de5 (diff)
Make meta-operations control build loop; add disfigure skeleton
Diffstat (limited to 'build/file.cxx')
-rw-r--r--build/file.cxx68
1 files changed, 68 insertions, 0 deletions
diff --git a/build/file.cxx b/build/file.cxx
new file mode 100644
index 0000000..7bb8bb6
--- /dev/null
+++ b/build/file.cxx
@@ -0,0 +1,68 @@
+// file : build/file.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <build/file>
+
+#include <fstream>
+
+#include <build/scope>
+#include <build/parser>
+#include <build/filesystem>
+#include <build/diagnostics>
+
+using namespace std;
+
+namespace build
+{
+ void
+ source (const path& bf, scope& root, scope& base)
+ {
+ tracer trace ("source");
+
+ ifstream ifs (bf.string ());
+ if (!ifs.is_open ())
+ fail << "unable to open " << bf;
+
+ level4 ([&]{trace << "sourcing " << bf;});
+
+ ifs.exceptions (ifstream::failbit | ifstream::badbit);
+ parser p;
+
+ try
+ {
+ p.parse_buildfile (ifs, bf, root, base);
+ }
+ catch (const std::ios_base::failure&)
+ {
+ fail << "failed to read from " << bf;
+ }
+ }
+
+ void
+ source_once (const path& bf, scope& root, scope& base, scope& once)
+ {
+ tracer trace ("source_once");
+
+ if (!once.buildfiles.insert (bf).second)
+ {
+ level4 ([&]{trace << "skipping already sourced " << bf;});
+ return;
+ }
+
+ source (bf, root, base);
+ }
+
+ void
+ root_pre (scope& root)
+ {
+ tracer trace ("root_pre");
+
+ path bf (root.src_path () / path ("build/root.build"));
+
+ if (!file_exists (bf))
+ return;
+
+ source_once (bf, root, root);
+ }
+}