From 5139b4e0f76076f3fb40b30e99a461fe0947d73e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 19 May 2022 12:39:35 +0200 Subject: Add config.config.unload variable to omit loading config.build Note that the configuration is still loaded from config.config.load if specified. Note also that similar to config.config.load, only values specified on this project's root scope and global scope are considered. --- libbuild2/config/init.cxx | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/config/init.cxx b/libbuild2/config/init.cxx index 774ffb8..73c9d37 100644 --- a/libbuild2/config/init.cxx +++ b/libbuild2/config/init.cxx @@ -243,12 +243,23 @@ namespace build2 auto& c_v (vp.insert ("config.version", false /*ovr*/, v_p)); auto& c_l (vp.insert ("config.config.load", true /* ovr */)); + // Omit loading the configuration from the config.build file (it is + // still loaded from config.config.load if specified). Similar to + // config.config.load, only values specified on this project's root + // scope and global scope are considered. + // + // Note that this variable is not saved in config.build and is expected + // to always be specified as a command line override. + // + auto& c_u (vp.insert ("config.config.unload", true /*ovr*/)); + // Configuration variables to disfigure. // // The exact semantics is to ignore these variables when loading // config.build (and any files specified in config.config.load), letting // them to take on the default values (more precisely, the current - // implementation undefined them after loading config.build). + // implementation undefined them after loading config.build). See also + // config.config.unload. // // Note that this variable is not saved in config.build and is expected // to always be specified as a command line override. @@ -352,9 +363,10 @@ namespace build2 save_null_omitted | save_empty_omitted | save_base, &save_environment); - // Load config.build if one exists followed by extra files specified in - // config.config.load (we don't need to worry about disfigure since we - // will never be init'ed). + // Load config.build if one exists (and unless config.config.unload is + // specified) followed by extra files specified in config.config.load + // (we don't need to worry about disfigure since we will never be + // init'ed). // auto load_config = [&rs, &c_v] (istream& is, const path_name& in, @@ -403,11 +415,26 @@ namespace build2 load_config (open_file_or_stdin (fn, ifs), fn, l); }; + // Load config.build unless requested not to. + // { - path f (config_file (rs)); + // The same semantics as in config.config.load below. + // + bool u; + { + lookup l (rs[c_u]); + u = (l && + (l.belongs (rs) || l.belongs (ctx.global_scope)) && + cast_false (l)); + } - if (exists (f)) - load_config_file (f, l); + if (!u) + { + path f (config_file (rs)); + + if (exists (f)) + load_config_file (f, l); + } } if (lookup l = rs[c_l]) -- cgit v1.1