diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2019-11-04 13:34:52 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2019-11-04 15:15:30 +0200 |
commit | b39ce46b80ef5cccc592398e0a74ba8d02742ead (patch) | |
tree | a7ccf1a628ea8cf6a5804d4ad6c0b704fade5807 /libbuild2/config/functions.cxx | |
parent | 41a31b0a61464fd506166887f621100364e67276 (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/functions.cxx')
-rw-r--r-- | libbuild2/config/functions.cxx | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/libbuild2/config/functions.cxx b/libbuild2/config/functions.cxx new file mode 100644 index 0000000..79447a4 --- /dev/null +++ b/libbuild2/config/functions.cxx @@ -0,0 +1,52 @@ +// file : libbuild2/config/functions.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <sstream> + +#include <libbuild2/scope.hxx> +#include <libbuild2/function.hxx> +#include <libbuild2/variable.hxx> + +#include <libbuild2/config/operation.hxx> + +using namespace std; + +namespace build2 +{ + namespace config + { + void + functions (function_map& m) + { + function_family f (m, "config"); + + // Return the configuration file contents as a string, similar to the + // config.export variable functionality. + // + // 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. + // + f[".export"] = [] (const scope* s) + { + if (s == nullptr) + fail << "config.export() called out of scope" << endf; + + s = s->root_scope (); + + if (s == nullptr) + fail << "config.export() called out of project" << endf; + + ostringstream os; + + // Empty project set should is ok as long as inherit is false. + // + project_set ps; + save_config (*s, os, "config.export()", false /* inherit */, ps); + + return os.str (); + }; + } + } +} |