diff options
Diffstat (limited to 'src/configure.cc')
-rw-r--r-- | src/configure.cc | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/src/configure.cc b/src/configure.cc index c08ed88..7a68f03 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -7,6 +7,7 @@ #include <filesystem> #include <fstream> #include <optional> +#include <span> #include <getoptpp/getoptpp.hpp> @@ -18,8 +19,8 @@ #include "tools.h" #include "util.h" -std::filesystem::path configurationFile("configuration.cc"); -std::filesystem::path configHeaderFile("config.h"); +const std::filesystem::path configurationFile("configuration.cc"); +const std::filesystem::path configHeaderFile("config.h"); std::map<std::string, std::string> external_includedir; std::map<std::string, std::string> external_libdir; @@ -68,7 +69,7 @@ bool ctor::configuration::has(const std::string& key) const return tools.find(key) != tools.end(); } -const std::string& ctor::configuration::get(const std::string& key, const std::string& default_value) const +std::string ctor::configuration::get(const std::string& key, const std::string& default_value) const { if(key == ctor::cfg::ctor_includedir && ctor::includedir) { @@ -321,19 +322,19 @@ int regenerateCache(ctor::settings& settings, } auto add_path_args = - [&](const std::string& name) + [&](const std::string& arg_name) { - opt.add(name + "-includedir", required_argument, key++, - "Set path to " + name + " header file.", + opt.add(arg_name + "-includedir", required_argument, key++, + "Set path to " + arg_name + " header file.", [&]() { - external_includedir[name] = optarg; + external_includedir[arg_name] = optarg; return 0; }); - opt.add(name + "-libdir", required_argument, key++, - "Set path to " + name + " libraries.", + opt.add(arg_name + "-libdir", required_argument, key++, + "Set path to " + arg_name + " libraries.", [&]() { - external_libdir[name] = optarg; + external_libdir[arg_name] = optarg; return 0; }); }; @@ -357,16 +358,15 @@ int regenerateCache(ctor::settings& settings, opt.add("help", no_argument, 'h', "Print this help text.", - [&]() { + [&]() -> int { std::cout << "Configure how to build with " << name << "\n"; std::cout << "Usage: " << name << " configure [options]\n\n"; std::cout << "Options:\n"; opt.help(); exit(0); - return 0; }); - opt.process(vargs.size(), vargs.data()); + opt.process(static_cast<int>(vargs.size()), vargs.data()); if(host_arch_prefix.empty()) { @@ -821,12 +821,14 @@ int regenerateCache(ctor::settings& settings, int configure(const ctor::settings& global_settings, int argc, char* argv[]) { + auto args_span = std::span(argv, static_cast<std::size_t>(argc)); + ctor::settings settings{global_settings}; std::vector<std::string> args; - for(int i = 2; i < argc; ++i) // skip command and the first 'configure' arg + for(std::size_t i = 2; i < args_span.size(); ++i) // skip command and the first 'configure' arg { - args.push_back(argv[i]); + args.emplace_back(args_span[i]); } std::map<std::string, std::string> env; @@ -860,7 +862,7 @@ int configure(const ctor::settings& global_settings, int argc, char* argv[]) env["PATH"] = path_env; } - auto ret = regenerateCache(settings, argv[0], args, env); + auto ret = regenerateCache(settings, args_span[0], args, env); if(ret != 0) { return ret; @@ -873,19 +875,21 @@ int configure(const ctor::settings& global_settings, int argc, char* argv[]) int reconfigure(const ctor::settings& global_settings, int argc, char* argv[]) { + auto args_span = std::span(argv, static_cast<std::size_t>(argc)); + ctor::settings settings{global_settings}; bool no_rerun{false}; std::vector<std::string> args; - for(int i = 2; i < argc; ++i) // skip executable name and 'reconfigure' arg + for(std::size_t i = 2; i < args_span.size(); ++i) // skip executable name and 'reconfigure' arg { - if(i == 2 && std::string(argv[i]) == "--no-rerun") + if(i == 2 && std::string(args_span[i]) == "--no-rerun") { no_rerun = true; continue; } - args.push_back(argv[i]); + args.emplace_back(args_span[i]); } const auto& cfg = ctor::get_configuration(); @@ -895,14 +899,14 @@ int reconfigure(const ctor::settings& global_settings, int argc, char* argv[]) { std::cout << e.first << "=\"" << e.second << "\" "; } - std::cout << argv[0] << " configure "; + std::cout << args_span[0] << " configure "; for(const auto& arg : cfg.args) { std::cout << arg << " "; } std::cout << "\n"; - auto ret = regenerateCache(settings, argv[0], cfg.args, cfg.env); + auto ret = regenerateCache(settings, args_span[0], cfg.args, cfg.env); if(ret != 0) { return ret; @@ -915,5 +919,5 @@ int reconfigure(const ctor::settings& global_settings, int argc, char* argv[]) return 0; // this was originally invoked by configure, don't loop } - return execute(argv[0], args); + return execute(settings, args_span[0], args); } |