aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/utility.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-11-04 09:37:30 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-11-04 15:14:42 +0200
commit41a31b0a61464fd506166887f621100364e67276 (patch)
tree2f2cfaad943ee956fb412ec7f1929a6b493f4aab /libbuild2/utility.hxx
parent3ca5421a788cb50004fe62f452c43132492778e1 (diff)
Add support for configuration exporting and importing
The new config.export variable specifies the alternative file to write the configuration to as part of the configure meta-operation. For example: $ b configure: proj/ config.export=proj-config.build The config.export value "applies" only to the projects on whose root scope it is specified or if it is a global override (the latter is a bit iffy but we allow it, for example, to dump everything to stdout). This means that in order to save a subproject's configuration we will have to use a scope-specific override (since the default will apply to the outermost amalgamation). For example: $ b configure: subproj/ subproj/config.export=.../subproj-config.build This could be somewhat unnatural but then it will be the amalgamation whose configuration we normally want to export. The new config.import variable specifies additional configuration files to be loaded after the project's default config.build, if any. For example: $ b create: cfg/,cc config.import=my-config.build Similar to config.export, the config.import value "applies" only to the project on whose root scope it is specified or if it is a global override. This allows the use of the standard override "positioning" machinery (i.e., where the override applies) to decide where the extra configuration files are loaded. The resulting semantics is quite natural and consistent with command line variable overrides, for example: $ b config.import=.../config.build # outermost amalgamation $ b ./config.import=.../config.build # this project $ b !config.import=.../config.build # every project Both config.export and config.import recognize the special `-` file name as an instruction to write/read to/from stdout/stdin, respectively. For example: $ b configure: src-prj/ config.export=- | b configure: dst-prj/ config.import=-
Diffstat (limited to 'libbuild2/utility.hxx')
-rw-r--r--libbuild2/utility.hxx13
1 files changed, 13 insertions, 0 deletions
diff --git a/libbuild2/utility.hxx b/libbuild2/utility.hxx
index 43b556e..415dc8b 100644
--- a/libbuild2/utility.hxx
+++ b/libbuild2/utility.hxx
@@ -88,6 +88,19 @@ namespace build2
using butl::eof;
+ // Open a file or, if the file name is `-`, stdin/stdout.
+ //
+ // Note that ofdstream::close() should be called explicitly if not stdout
+ // (but harmless to call even if it is). Also note that our overload of
+ // operator<<(path) always translats `-` to `<stdin>` so care must be taken
+ // when issuing diagnostics.
+ //
+ istream&
+ open_file_or_stdin (const path&, ifdstream&);
+
+ ostream&
+ open_file_or_stdout (const path&, ofdstream&);
+
// Diagnostics state (verbosity level, etc; see <libbuild2/diagnostics.hxx>).
//
// Note on naming of values (here and in the global state below) that come