From 1adbf7b710d52958f6c0168ccb492252c1f19d4a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 13 Mar 2020 08:48:43 +0200 Subject: Cleanup and make config/utility.?xx part of build system core --- libbuild2/config/utility.cxx | 180 ++----------------------------------------- 1 file changed, 7 insertions(+), 173 deletions(-) (limited to 'libbuild2/config/utility.cxx') diff --git a/libbuild2/config/utility.cxx b/libbuild2/config/utility.cxx index a39d3e0..b9fc513 100644 --- a/libbuild2/config/utility.cxx +++ b/libbuild2/config/utility.cxx @@ -3,17 +3,17 @@ #include -#include -#include -#include -#include - -#include - using namespace std; namespace build2 { + void (*config_save_variable) (scope&, const variable&, uint64_t); + void (*config_save_module) (scope&, const char*, int); + const string& (*config_preprocess_create) (context&, + values&, + vector_view&, + bool, + const location&); namespace config { pair @@ -126,171 +126,5 @@ namespace build2 else return false; } - - void - save_variable (scope& rs, const variable& var, uint64_t flags) - { - if (module* m = rs.find_module (module::name)) - m->save_variable (var, flags); - } - - void - save_module (scope& rs, const char* name, int prio) - { - if (module* m = rs.find_module (module::name)) - m->save_module (name, prio); - } - - void - create_project (const dir_path& d, - const build2::optional& amal, - const strings& bmod, - const string& rpre, - const strings& rmod, - const string& rpos, - bool config, - bool buildfile, - const char* who, - uint16_t verbosity) - { - string hdr ("# Generated by " + string (who) + ". Edit if you know" - " what you are doing.\n" - "#"); - - // If the directory exists, verify it's empty. Otherwise, create it. - // - if (exists (d)) - { - if (!empty (d)) - fail << "directory " << d << " exists and is not empty"; - } - else - mkdir_p (d, verbosity); - - // Create the build/ subdirectory. - // - // Note that for now we use the standard build file/directory scheme. - // - mkdir (d / std_build_dir, verbosity); - - // Write build/bootstrap.build. - // - { - path f (d / std_bootstrap_file); - - if (verb >= verbosity) - text << (verb >= 2 ? "cat >" : "save ") << f; - - try - { - ofdstream ofs (f); - - ofs << hdr << endl - << "project =" << endl; - - if (amal) - { - ofs << "amalgamation ="; - - if (!amal->empty ()) - { - ofs << ' '; - to_stream (ofs, *amal, true /* representation */); - } - - ofs << endl; - } - - ofs << endl; - - if (config) - ofs << "using config" << endl; - - for (const string& m: bmod) - { - if (!config || m != "config") - ofs << "using " << m << endl; - } - - ofs.close (); - } - catch (const io_error& e) - { - fail << "unable to write to " << f << ": " << e; - } - } - - // Write build/root.build. - // - { - path f (d / std_root_file); - - if (verb >= verbosity) - text << (verb >= 2 ? "cat >" : "save ") << f; - - try - { - ofdstream ofs (f); - - ofs << hdr << endl; - - if (!rpre.empty ()) - ofs << rpre << endl - << endl; - - for (const string& cm: rmod) - { - // If the module name start with '?', then use optional load. - // - bool opt (cm.front () == '?'); - string m (cm, opt ? 1 : 0); - - // Append .config unless the module name ends with '.', in which - // case strip it. - // - if (m.back () == '.') - m.pop_back (); - else - m += ".config"; - - ofs << "using" << (opt ? "?" : "") << " " << m << endl; - } - - if (!rpos.empty ()) - ofs << endl - << rpre << endl; - - ofs.close (); - } - catch (const io_error& e) - { - fail << "unable to write to " << f << ": " << e; - } - } - - // Write root buildfile. - // - if (buildfile) - { - path f (d / std_buildfile_file); - - if (verb >= verbosity) - text << (verb >= 2 ? "cat >" : "save ") << f; - - try - { - ofdstream ofs (f); - - ofs << hdr << endl - << "./: {*/ -build/}" << endl; - - ofs.close (); - } - catch (const io_error& e) - { - fail << "unable to write to " << f << ": " << e; - } - } - } } } -- cgit v1.1