From f31661d392c1332ceb0edcbc9fd35f4cb49bb50d Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 11 Jan 2023 16:35:57 +0100 Subject: Support using custom build-dir during bootstrap. --- src/bootstrap.cc | 8 +++++++- src/configure.cc | 30 ++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/bootstrap.cc b/src/bootstrap.cc index c58c399..d473689 100644 --- a/src/bootstrap.cc +++ b/src/bootstrap.cc @@ -42,6 +42,12 @@ const std::string& getConfiguration(const std::string& key, return s; } + if(key == cfg::builddir && std::getenv("BUILDDIR")) + { + static std::string s = std::getenv("BUILDDIR"); + return s; + } + return defaultValue; } @@ -56,7 +62,7 @@ int main(int argc, char* argv[]) Settings settings{}; - settings.builddir = getConfiguration(cfg::builddir, "build"); + settings.builddir = getConfiguration(cfg::builddir, settings.builddir); settings.parallel_processes = std::max(1u, std::thread::hardware_concurrency() * 2 - 1); settings.verbose = 0; diff --git a/src/configure.cc b/src/configure.cc index 50a7c32..25403f7 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -32,6 +32,7 @@ namespace ctor { std::optional includedir; std::optional libdir; +std::optional builddir; std::map conf_values; } @@ -47,6 +48,11 @@ bool hasConfiguration(const std::string& key) return true; } + if(key == cfg::builddir && ctor::builddir) + { + return true; + } + if(ctor::conf_values.find(key) != ctor::conf_values.end()) { return true; @@ -69,6 +75,11 @@ const std::string& getConfiguration(const std::string& key, return *ctor::libdir; } + if(key == cfg::builddir && ctor::builddir) + { + return *ctor::builddir; + } + if(ctor::conf_values.find(key) != ctor::conf_values.end()) { return ctor::conf_values[key]; @@ -160,11 +171,10 @@ public: // helper constant for the visitor template inline constexpr bool always_false_v = false; -int regenerateCache(const Settings& default_settings, +int regenerateCache(Settings& settings, const std::vector& args, const std::map& env) { - Settings settings{default_settings}; Args vargs(args); dg::Options opt; @@ -180,12 +190,14 @@ int regenerateCache(const Settings& default_settings, std::string ld_prog = "ld"; std::string ctor_includedir; std::string ctor_libdir; + std::string builddir; opt.add("build-dir", required_argument, 'b', "Set output directory for build files (default: '" + settings.builddir + "').", [&]() { settings.builddir = optarg; + builddir = optarg; return 0; }); @@ -396,6 +408,10 @@ int regenerateCache(const Settings& default_settings, { ctor::conf_values[cfg::ctor_libdir] = ctor_libdir; } + if(!builddir.empty()) + { + ctor::conf_values[cfg::builddir] = builddir; + } ctor::conf_values[cfg::host_cxx] = host_cxx; ctor::conf_values[cfg::build_cxx] = build_cxx; @@ -421,7 +437,11 @@ int regenerateCache(const Settings& default_settings, istr << "},\n"; istr << " .tools = {\n"; - istr << " { \"" << cfg::builddir << "\", \"" << settings.builddir << "\" },\n"; + if(!builddir.empty()) + { + istr << " { \"" << cfg::builddir << "\", \"" << builddir << "\" },\n"; + ctor::builddir = builddir; + } istr << " { \"" << cfg::host_cc << "\", \"" << host_cc << "\" },\n"; istr << " { \"" << cfg::host_cxx << "\", \"" << host_cxx << "\" },\n"; istr << " { \"" << cfg::host_ar << "\", \"" << host_ar << "\" },\n"; @@ -567,8 +587,10 @@ int configure(const Settings& global_settings, int argc, char* argv[]) return 0; } -int reconfigure(const Settings& settings, int argc, char* argv[]) +int reconfigure(const Settings& global_settings, int argc, char* argv[]) { + Settings settings{global_settings}; + bool no_rerun{false}; std::vector args; -- cgit v1.2.3