aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/file.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/file.cxx')
-rw-r--r--libbuild2/file.cxx65
1 files changed, 47 insertions, 18 deletions
diff --git a/libbuild2/file.cxx b/libbuild2/file.cxx
index 0bcb198..571980e 100644
--- a/libbuild2/file.cxx
+++ b/libbuild2/file.cxx
@@ -17,7 +17,8 @@
#include <libbuild2/lexer.hxx>
#include <libbuild2/parser.hxx>
-#include <libbuild2/config/utility.hxx> // lookup_config()
+#include <libbuild2/config/module.hxx> // config::module::version
+#include <libbuild2/config/utility.hxx> // config::lookup_config()
using namespace std;
using namespace butl;
@@ -310,13 +311,13 @@ namespace build2
}
scope_map::iterator
- create_root (scope& s, const dir_path& out_root, const dir_path& src_root)
+ create_root (context& ctx,
+ const dir_path& out_root,
+ const dir_path& src_root)
{
- auto i (s.ctx.scopes.rw (s).insert (out_root, true /* root */));
+ auto i (ctx.scopes.rw ().insert (out_root, true /* root */));
scope& rs (i->second);
- context& ctx (rs.ctx);
-
// Set out_path. Note that src_path is set in setup_root() below.
//
if (rs.out_path_ != &i->first)
@@ -1208,7 +1209,7 @@ namespace build2
// probably be tried first since that src_root was explicitly configured
// by the user. After that, #2 followed by #1 seems reasonable.
//
- scope& rs (create_root (root, out_root, dir_path ())->second);
+ scope& rs (create_root (ctx, out_root, dir_path ())->second);
bool bstrapped (bootstrapped (rs));
@@ -1275,7 +1276,7 @@ namespace build2
// The same logic to src_root as in create_bootstrap_outer().
//
- scope& rs (create_root (root, out_root, dir_path ())->second);
+ scope& rs (create_root (ctx, out_root, dir_path ())->second);
optional<bool> altn;
if (!bootstrapped (rs))
@@ -1466,17 +1467,16 @@ namespace build2
}
scope&
- load_project (scope& s,
+ load_project (context& ctx,
const dir_path& out_root,
const dir_path& src_root,
bool forwarded,
bool load)
{
+ assert (ctx.phase == run_phase::load);
assert (!forwarded || out_root != src_root);
- context& ctx (s.ctx);
-
- auto i (create_root (s, out_root, src_root));
+ auto i (create_root (ctx, out_root, src_root));
scope& rs (i->second);
if (!bootstrapped (rs))
@@ -2065,13 +2065,11 @@ namespace build2
fwd = (src_root != out_root);
}
- scope& gs (ctx.global_scope.rw ());
-
for (const scope* proot (nullptr); ; proot = root)
{
bool top (proot == nullptr);
- root = &create_root (gs, out_root, src_root)->second;
+ root = &create_root (ctx, out_root, src_root)->second;
bool bstrapped (bootstrapped (*root));
@@ -2153,6 +2151,8 @@ namespace build2
//
load_root (*root);
+ scope& gs (ctx.global_scope.rw ());
+
// Use a temporary scope so that the export stub doesn't mess anything up.
//
temp_scope ts (gs);
@@ -2555,11 +2555,14 @@ namespace build2
const string& rpre,
const strings& rmod,
const string& rpos,
- const optional<string>& config,
+ const optional<string>& config_mod,
+ const optional<string>& config_file,
bool buildfile,
const char* who,
uint16_t verbosity)
{
+ assert (!config_file || (config_mod && *config_mod == "config"));
+
string hdr ("# Generated by " + string (who) + ". Edit if you know"
" what you are doing.\n"
"#");
@@ -2610,12 +2613,12 @@ namespace build2
ofs << endl;
- if (config)
- ofs << "using " << *config << endl;
+ if (config_mod)
+ ofs << "using " << *config_mod << endl;
for (const string& m: bmod)
{
- if (!config || m != *config)
+ if (!config_mod || m != *config_mod)
ofs << "using " << m << endl;
}
@@ -2675,6 +2678,32 @@ namespace build2
}
}
+ // Write build/config.build.
+ //
+ if (config_file)
+ {
+ path f (d / std_build_dir / "config.build"); // std_config_file
+
+ if (verb >= verbosity)
+ text << (verb >= 2 ? "cat >" : "save ") << f;
+
+ try
+ {
+ ofdstream ofs (f);
+
+ ofs << hdr << endl
+ << "config.version = " << config::module::version << endl
+ << endl
+ << *config_file << endl;
+
+ ofs.close ();
+ }
+ catch (const io_error& e)
+ {
+ fail << "unable to write to " << f << ": " << e;
+ }
+ }
+
// Write root buildfile.
//
if (buildfile)