aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-03-31 06:29:05 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-03-31 06:29:05 +0200
commit618c44ec5e85f7d07540234a0de9fac6e2913243 (patch)
treeb31ca500abc9f13755ceafdd7ff1d2b3398040e9
parentb1715878d50aa8a3c3e2404f3ded120329994aba (diff)
Save config.build
-rw-r--r--build/config/module.cxx4
-rw-r--r--build/config/operation.cxx54
-rw-r--r--build/variable12
3 files changed, 68 insertions, 2 deletions
diff --git a/build/config/module.cxx b/build/config/module.cxx
index 41c2526..59fbb1f 100644
--- a/build/config/module.cxx
+++ b/build/config/module.cxx
@@ -6,6 +6,7 @@
#include <build/path>
#include <build/scope>
+#include <build/filesystem>
#include <build/diagnostics>
#include <build/config/operation>
@@ -20,9 +21,8 @@ namespace build
trigger (scope&, const path& p)
{
tracer trace ("config::trigger");
-
level4 ([&]{trace << "intercepted sourcing of " << p;});
- return false;
+ return file_exists (p);
}
void
diff --git a/build/config/operation.cxx b/build/config/operation.cxx
index df4682e..baafc97 100644
--- a/build/config/operation.cxx
+++ b/build/config/operation.cxx
@@ -65,6 +65,56 @@ namespace build
}
static void
+ save_config (const path& out_root)
+ {
+ path f (out_root / config_file);
+
+ if (verb >= 1)
+ text << "config::save_config " << f.string ();
+ else
+ text << "save " << f;
+
+ try
+ {
+ ofstream ofs (f.string ());
+ if (!ofs.is_open ())
+ fail << "unable to open " << f;
+
+ ofs.exceptions (ofstream::failbit | ofstream::badbit);
+
+ // Save all the variables in the config. namespace that are set
+ // on the project's root scope.
+ //
+ scope& r (scopes.find (out_root));
+
+ /*
+ r.variables["config"] = "default interactive";
+ r.variables["config.cxx"] = "g++-4.9";
+ r.variables["config.cxx.options"] = "-O3 -g";
+ */
+
+ for (auto p (r.variables.find_namespace ("config"));
+ p.first != p.second;
+ ++p.first)
+ {
+ const variable& var (p.first->first);
+ const value& val (*p.first->second);
+
+ //@@ TODO: assuming list
+ //
+ const list_value& lv (dynamic_cast<const list_value&> (val));
+
+ ofs << var.name << " = " << lv.data << endl;
+ text << var.name << " = " << lv.data;
+ }
+ }
+ catch (const ios_base::failure&)
+ {
+ fail << "failed to write to " << f;
+ }
+ }
+
+ static void
configure_execute (action a, const action_targets& ts)
{
tracer trace ("configure_execute");
@@ -98,6 +148,10 @@ namespace build
//
if (out_root != src_root)
save_src_root (out_root, src_root);
+
+ // Save config.build.
+ //
+ save_config (out_root);
}
else
{
diff --git a/build/variable b/build/variable
index 901f5c8..dfdcaff 100644
--- a/build/variable
+++ b/build/variable
@@ -217,6 +217,18 @@ namespace build
return value_proxy (&base::operator[] (v), &scope_);
}
+ std::pair<iterator, iterator>
+ find_namespace (const std::string& ns)
+ {
+ return find_prefix (variable_pool.find (ns));
+ }
+
+ std::pair<const_iterator, const_iterator>
+ find_namespace (const std::string& ns) const
+ {
+ return find_prefix (variable_pool.find (ns));
+ }
+
explicit
variable_map (scope& s): scope_ (s) {}