diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2019-11-04 15:11:01 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2019-11-04 15:16:13 +0200 |
commit | 56b860217eb00827ba15fc975f71008080af9b65 (patch) | |
tree | 882f39a7c228923363162eb17b6f1ac2db38adb4 /libbuild2 | |
parent | b39ce46b80ef5cccc592398e0a74ba8d02742ead (diff) |
Add support for ~host special configuration name in config.import
This is the "default host configuration" that corresponds to how the build
system itself was built. For example:
$ b create: tools/,cc config.import=~host
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/buildfile | 25 | ||||
-rw-r--r-- | libbuild2/config/host-config.cxx.in | 13 | ||||
-rw-r--r-- | libbuild2/config/init.cxx | 42 |
3 files changed, 72 insertions, 8 deletions
diff --git a/libbuild2/buildfile b/libbuild2/buildfile index 865bb91..325d54a 100644 --- a/libbuild2/buildfile +++ b/libbuild2/buildfile @@ -32,10 +32,29 @@ lib{build2}: cxx{utility-uninstalled}: for_install = false # NOTE: remember to update import_modules() in libbuild2/modules.cxx if adding # a new such module. # -for m: config dist install test - libul{build2}: $m/{hxx ixx txx cxx}{** -**-options -**.test...} +libul{build2}: config/{hxx ixx txx cxx}{** -host-config -**.test...} \ + config/cxx{host-config} -libul{build2}: test/script/{hxx ixx cxx}{builtin-options} +# This will of course blow up spectacularly if we are cross-compiling. But +# let's wait and enjoy the fireworks (and get a sense of why would someone +# need to cross-compile a build system). +# +newline = ' +' +config/cxx{host-config}: config/in{host-config} +{ + # Remove comment lines which could be confused by some lesser compilers with + # preprocessor directives. + # + host_config = $regex.replace($config.export(), "#.*$newline", '') +} + +libul{build2}: dist/{hxx ixx txx cxx}{** -**.test...} + +libul{build2}: install/{hxx ixx txx cxx}{** -**.test...} + +libul{build2}: test/{hxx ixx txx cxx}{** -**-options -**.test...} \ + test/script/{hxx ixx cxx}{builtin-options} libul{build2}: $int_libs diff --git a/libbuild2/config/host-config.cxx.in b/libbuild2/config/host-config.cxx.in new file mode 100644 index 0000000..46cd912 --- /dev/null +++ b/libbuild2/config/host-config.cxx.in @@ -0,0 +1,13 @@ +// file : libbuild2/config/host-config.cxx.in -*- C++ -*- +// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +namespace build2 +{ + namespace config + { + // This is a raw string literal, in case you are unfamiliar. + // + extern const char host_config[] = R"###($host_config$)###"; + } +} diff --git a/libbuild2/config/init.cxx b/libbuild2/config/init.cxx index cda34fa..2d4ed20 100644 --- a/libbuild2/config/init.cxx +++ b/libbuild2/config/init.cxx @@ -4,6 +4,8 @@ #include <libbuild2/config/init.hxx> +#include <sstream> + #include <libbuild2/file.hxx> #include <libbuild2/rule.hxx> #include <libbuild2/lexer.hxx> @@ -88,6 +90,10 @@ namespace build2 return true; // Initialize first (load config.build). } +#ifndef BUILD2_BOOTSTRAP + extern const char host_config[]; // host-config.cxx.in +#endif + bool init (scope& rs, scope&, @@ -124,7 +130,9 @@ namespace build2 // config.import (we don't need to worry about disfigure since we will // never be init'ed). // - auto load_config = [&rs, &c_v] (const path& f, const location& l) + auto load_config = [&rs, &c_v] (istream& is, + const path& f, + const location& l) { // Check the config version. We assume that old versions cannot // understand new configs and new versions are incompatible with old @@ -141,8 +149,7 @@ namespace build2 // that we won't have the config.version variable entered in the scope // but that is harmless (we could do it manually if necessary). // - ifdstream ifs; - lexer lex (open_file_or_stdin (f, ifs), f); + lexer lex (is, f); // Assume missing version is 0. // @@ -160,11 +167,17 @@ namespace build2 source (rs, rs, lex); }; + auto load_config_file = [&load_config] (const path& f, const location& l) + { + ifdstream ifs; + load_config (open_file_or_stdin (f, ifs), f, l); + }; + { path f (config_file (rs)); if (exists (f)) - load_config (f, l); + load_config_file (f, l); } if (lookup l = rs[c_i]) @@ -182,7 +195,26 @@ namespace build2 if (l.belongs (rs) || l.belongs (rs.ctx.global_scope)) { for (const path& f: cast<paths> (l)) - load_config (f, location (&f)); + { + location l (&f); + + const string& s (f.string ()); + + if (s[0] != '~') + load_config_file (f, l); + else if (s == "~host") + { +#ifdef BUILD2_BOOTSTRAP + assert (false); +#else + istringstream is (host_config); + load_config (is, f, l); +#endif + } + else + fail << "unknown special configuration name '" << s << "' in " + << "config.import"; + } } } |