aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/config/init.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-11-04 13:34:52 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-11-04 15:15:30 +0200
commitb39ce46b80ef5cccc592398e0a74ba8d02742ead (patch)
treea7ccf1a628ea8cf6a5804d4ad6c0b704fade5807 /libbuild2/config/init.cxx
parent41a31b0a61464fd506166887f621100364e67276 (diff)
Add $config.export() function
This is similar to the config.export variable functionality except it can be called from within buildfiles. Note that this function can only be used during configure unless the config module creation was forced for other meta-operations with config.module=true in bootstrap.build.
Diffstat (limited to 'libbuild2/config/init.cxx')
-rw-r--r--libbuild2/config/init.cxx31
1 files changed, 25 insertions, 6 deletions
diff --git a/libbuild2/config/init.cxx b/libbuild2/config/init.cxx
index 4e1890a..cda34fa 100644
--- a/libbuild2/config/init.cxx
+++ b/libbuild2/config/init.cxx
@@ -9,6 +9,7 @@
#include <libbuild2/lexer.hxx>
#include <libbuild2/scope.hxx>
#include <libbuild2/context.hxx>
+#include <libbuild2/function.hxx>
#include <libbuild2/filesystem.hxx> // exists()
#include <libbuild2/diagnostics.hxx>
@@ -23,15 +24,19 @@ namespace build2
{
namespace config
{
+ void
+ functions (function_map&); // functions.cxx
+
bool
boot (scope& rs, const location&, unique_ptr<module_base>& mod)
{
tracer trace ("config::boot");
+ context& ctx (rs.ctx);
+
l5 ([&]{trace << "for " << rs;});
- const string& mname (rs.ctx.current_mname);
- const string& oname (rs.ctx.current_oname);
+ auto& vp (rs.ctx.var_pool.rw (rs));
// While config.import (see below) could theoretically be specified in a
// buildfile, config.export is expected to always be specified as a
@@ -46,8 +51,17 @@ namespace build2
// forced with config.module (useful if we need to call $config.export()
// during other meta-operations).
//
- if (( mname == "configure" || mname == "create") ||
- (mname.empty () && (oname == "configure" || oname == "create")))
+ // Detecting the former (configuring/creating) is a bit tricky since the
+ // build2 core may not yet know if this is the case. But we know.
+ //
+ auto& c_m (vp.insert<bool> ("config.module", false /*ovr*/));
+
+ const string& mname (ctx.current_mname);
+ const string& oname (ctx.current_oname);
+
+ if (( mname == "configure" || mname == "create") ||
+ (mname.empty () && (oname == "configure" || oname == "create")) ||
+ cast_false<bool> (rs.vars[c_m]))
{
unique_ptr<module> m (new module);
@@ -59,6 +73,12 @@ namespace build2
mod = move (m);
}
+ // Register the config function family if this is the first instance of
+ // the config module.
+ //
+ if (!function_family::defined (ctx.functions, "config"))
+ functions (ctx.functions);
+
// Register meta-operations. Note that we don't register create_id
// since it will be pre-processed into configure.
//
@@ -85,8 +105,7 @@ namespace build2
return true;
}
- const dir_path& out_root (rs.out_path ());
- l5 ([&]{trace << "for " << out_root;});
+ l5 ([&]{trace << "for " << rs;});
assert (config_hints.empty ()); // We don't known any hints.