From d94ce2120417418802d625b909a8893928315bca Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sun, 22 Nov 2020 13:16:27 -0500 Subject: [PATCH] removed conf::dry refactor, comments --- src/cmd/build.cpp | 2 +- src/cmd/commands.cpp | 8 +- src/core/conf.cpp | 440 +++++++++++++++++++++++-------------------- src/core/conf.h | 95 +++++++--- src/core/context.cpp | 4 +- src/core/op.cpp | 30 +-- src/core/paths.cpp | 2 +- src/core/process.cpp | 2 +- src/net.cpp | 2 +- src/tools/git.cpp | 2 +- 10 files changed, 328 insertions(+), 259 deletions(-) diff --git a/src/cmd/build.cpp b/src/cmd/build.cpp index 2ce10b6..82af07f 100644 --- a/src/cmd/build.cpp +++ b/src/cmd/build.cpp @@ -235,7 +235,7 @@ void build_command::dump_timings() void build_command::terminate_msbuild() { - if (conf::dry()) + if (conf().global().dry()) return; system("taskkill /im msbuild.exe /f > NUL 2>&1"); diff --git a/src/cmd/commands.cpp b/src/cmd/commands.cpp index 89607b4..d01105d 100644 --- a/src/cmd/commands.cpp +++ b/src/cmd/commands.cpp @@ -220,7 +220,9 @@ int command::load_options() return r; init_options(inis_, common.options); - log_options(); + + for (auto&& line : format_options()) + gcx().trace(context::conf, "{}", line); if (!verify_options()) return 1; @@ -332,7 +334,9 @@ clipp::group options_command::do_group() int options_command::do_run() { - dump_available_options(); + for (auto&& line : format_options()) + u8cout << line << "\n"; + return 0; } diff --git a/src/core/conf.cpp b/src/core/conf.cpp index fbaf132..d936676 100644 --- a/src/core/conf.cpp +++ b/src/core/conf.cpp @@ -13,9 +13,13 @@ namespace mob::details using key_value_map = std::map>; using section_map = std::map>; -using task_map = std::map>; +// holds all the options not related to tasks (global, tools, paths, etc.) static section_map g_conf; + +// holds all the task options; has a special map element with an empty string +// for options that apply to all tasks, and elements with specific task names +// for overrides static section_map g_tasks; // special cases to avoid string manipulations @@ -23,12 +27,13 @@ static int g_output_log_level = 3; static int g_file_log_level = 5; static bool g_dry = false; - bool bool_from_string(std::string_view s) { return (s == "true" || s == "yes" || s == "1"); } +// returns a string from conf, bails out if it doesn't exist +// std::string get_string(std::string_view section, std::string_view key) { auto sitor = g_conf.find(section); @@ -42,6 +47,8 @@ std::string get_string(std::string_view section, std::string_view key) return kitor->second; } +// calls get_string(), converts to int +// int get_int(std::string_view section, std::string_view key) { const auto s = get_string(section, key); @@ -56,12 +63,16 @@ int get_int(std::string_view section, std::string_view key) } } +// calls get_string(), converts to bool +// bool get_bool(std::string_view section, std::string_view key) { const auto s = get_string(section, key); return bool_from_string(s); } +// sets the given option, bails out if the option doesn't exist +// void set_string(std::string_view section, std::string_view key, std::string_view value) { auto sitor = g_conf.find(section); @@ -75,11 +86,17 @@ void set_string(std::string_view section, std::string_view key, std::string_view kitor->second = value; } +// sets the given option, adds it if it doesn't exist; used when setting options +// from the master ini +// void add_string(const std::string& section, const std::string& key, std::string value) { g_conf[section][key] = value; } + +// finds an option for the given task, returns empty if not found +// std::optional find_string_for_task( std::string_view task_name, std::string_view key) { @@ -98,28 +115,29 @@ std::optional find_string_for_task( return itor->second; } +// gets an option for any of the given task names, typically aliases +// +// there's a hierarchy for task options: +// +// 1) there's a special "_override" entry in g_tasks, for options set from +// the command line that should override everything, like --no-pull +// should override all pull settings for all tasks +// +// 2) if the key is not found in "_override", then there can be an entry +// in g_tasks with any of given task names +// +// 3) if there's no entry for the task, or the entry doesn't have the key, +// check if the task is a 'super' task (anything under +// modorganizer_super); g_tasks has another special entry 'super' for +// options that apply to all super tasks +// +// 4) if this is not a super task, or this key doesn't exist in the super +// section, then use the generic task option for it, stored in an +// element with an empty string in g_tasks +// std::string get_string_for_task( const std::vector& task_names, std::string_view key) { - // there's a hierarchy for task options: - // - // 1) there's a special "_override" entry in g_tasks, for options set from - // the command line that should override everything, like --no-pull - // should override all pull settings for all tasks - // - // 2) if the key is not found in "_override", then there can be an entry - // in g_tasks with any of given task names - // - // 3) if there's no entry for the task, or the entry doesn't have the key, - // check if the task is a 'super' task (anything under - // modorganizer_super); g_tasks has another special entry 'super' for - // options that apply to all super tasks - // - // 4) if this is not a super task, or this key doesn't exist in the super - // section, then use the generic task option for it, stored in an - // element with an empty string in g_tasks - - // some command line options will override any user settings, like // --no-pull, those are stored in a special _override task name auto v = find_string_for_task("_override", key); @@ -159,6 +177,8 @@ std::string get_string_for_task( key, join(task_names, ",")); } +// calls get_string_for_task(), converts to bool +// bool get_bool_for_task( const std::vector& task_names, std::string_view key) { @@ -166,6 +186,8 @@ bool get_bool_for_task( return bool_from_string(s); } +// sets the given task option, bails out if the option doesn't exist +// void set_string_for_task( const std::string& task_name, const std::string& key, std::string value) { @@ -175,6 +197,9 @@ void set_string_for_task( g_tasks[task_name][key] = std::move(value); } +// sets the given task option, adds it if it doesn't exist; used when setting +// options from the master ini +// void add_string_for_task( const std::string& task_name, const std::string& key, std::string value) { @@ -249,25 +274,33 @@ std::vector format_options() return lines; } +// sets commonly used options that need to be converted to int/bool, for +// performance +// void set_special_options() { - conf().global().set_output_log_level( - details::get_string("global", "output_log_level")); - - conf().global().set_file_log_level( - details::get_string("global", "file_log_level")); - - conf().global().set_dry( - details::get_string("global", "dry")); + details::g_output_log_level = details::get_int("global", "output_log_level"); + details::g_file_log_level = details::get_int("global", "file_log_level"); + details::g_dry = details::get_bool("global", "dry"); } +// sets an option `key` in the `paths` section; if the path is currently empty, +// sets it using `f` (which is either a callable or a string) +// +// in any case, makes it absolute and canonical, bails out if the path does not +// exist +// +// this is used for paths that should already exist (qt, vs, etc.) +// template -void set_path_if_empty(std::string_view k, F&& f) +void set_path_if_empty(std::string_view key, F&& f) { - fs::path p = details::get_string("paths", k); + // current value + fs::path p = conf().path().get(key); if (p.empty()) { + // empty, set it from `f` if constexpr (std::is_same_v>) p = f; else @@ -276,7 +309,7 @@ void set_path_if_empty(std::string_view k, F&& f) p = fs::absolute(p); - if (!conf::dry()) + if (!conf().global().dry()) { if (!fs::exists(p)) gcx().bail_out(context::conf, "path {} not found", p); @@ -284,13 +317,23 @@ void set_path_if_empty(std::string_view k, F&& f) p = fs::canonical(p); } - details::set_string("paths", k, path_to_utf8(p)); + // new value + details::set_string("paths", key, path_to_utf8(p)); } -void make_canonical_path( +// sets an option `key` in the `paths` section: +// - if the path is empty, sets it as default_parent/default_dir, +// - if the path is not empty but is relative, resolves it against +// default_parent +// +// in any case, makes it absolute but weakly canonical since it might not exist +// at that point (this is used for build, install, etc.) +// +void resolve_path( std::string_view key, const fs::path& default_parent, std::string_view default_dir) { + // current value fs::path p = conf().path().get(key); if (p.empty()) @@ -303,61 +346,52 @@ void make_canonical_path( p = default_parent / p; } - if (!conf::dry()) + if (!conf().global().dry()) p = fs::weakly_canonical(fs::absolute(p)); details::set_string("paths", key, path_to_utf8(p)); } -struct parsed_option -{ - std::string section, key, value; -}; - -parsed_option parse_option(const std::string& s) -{ - // parses "section/key=value" - static std::regex re(R"((.+)/(.+)=(.*))"); - std::smatch m; - - if (!std::regex_match(s, m, re)) - { - gcx().bail_out(context::conf, - "bad option {}, must be [task:]section/key=value", s); - } - - return { - trim_copy(m[1].str()), - trim_copy(m[2].str()), - trim_copy(m[3].str()) - }; -} - +// `section_string` can be something like "global" or "paths", but also "task" +// or a task-specific name like "uibase:task" +// +// `master` is true if the ini being processed is the master ini so options are +// added to the maps instead of set, which throws if they're not found +// void process_option( const std::string& section_string, const std::string& key, const std::string& value, bool master) { + // split section string on ":" const auto col = section_string.find(":"); std::string task, section; if (col == std::string::npos) { + // not a "task_name:task" section section = section_string; } else { + // that's a "task_name:task" section task = section_string.substr(0, col); section = section_string.substr(col + 1); } if (section == "task") { + // task options go in g_tasks + if (task == "_override") { + // special case, comes from options on the command line details::set_string_for_task("_override", key, value); } else if (task != "") { + // task specific + + // task must exist const auto& tasks = find_tasks(task); MOB_ASSERT(!tasks.empty()); @@ -366,6 +400,8 @@ void process_option( } else { + // global task option + if (master) details::add_string_for_task("", key, value); else @@ -374,6 +410,8 @@ void process_option( } else { + // not a task option, goes into g_conf + if (master) details::add_string(section, key, value); else @@ -381,6 +419,8 @@ void process_option( } } +// reads the given ini and adds all of its content to the options +// void process_ini(const fs::path& ini, bool master) { const auto data = parse_ini(ini); @@ -395,73 +435,41 @@ void process_ini(const fs::path& ini, bool master) } } +// parses the given option strings and adds them as options +// void process_cmd_options(const std::vector& opts) { + // parses "section/key=value" + static std::regex re(R"((.+)/(.+)=(.*))"); + gcx().debug(context::conf, "overriding from command line:"); for (auto&& o : opts) { - const auto po = parse_option(o); - process_option(po.section, po.key, po.value, false); + std::smatch m; + if (!std::regex_match(o, m, re)) + { + gcx().bail_out(context::conf, + "bad option {}, must be [task:]section/key=value", o); + } + + process_option(m[1], m[2], m[3], false); } } -void init_options( - const std::vector& inis, const std::vector& opts) +// goes through all the options that have to do with paths, checks them and +// resolves them if necessary +// +void resolve_paths() { - MOB_ASSERT(!inis.empty()); - - // Keep track of the INI that contained a prefix: - fs::path ini_prefix; - bool master = true; - - for (auto&& ini : inis) - { - // Check if the prefix is set by this ini file: - fs::path cprefix = master ? fs::path{} : conf().path().prefix(); - - process_ini(ini, master); - - if (conf().path().prefix() != cprefix) - ini_prefix = ini; - - master = false; - } - - - if (!opts.empty()) - { - const auto prefix_before = conf().path().prefix(); - - process_cmd_options(opts); - - if (conf().path().prefix() != prefix_before) - { - // overridden by command line - ini_prefix = ""; - } - } - - - set_special_options(); - - if (!conf().path().prefix().empty()) - make_canonical_path("prefix", ini_prefix.empty() ? fs::current_path() : ini_prefix.parent_path(), ""); - - auto log_file = conf().global().log_file(); - if (log_file.is_relative()) - log_file = conf().path().prefix() / log_file; - - context::set_log_file(log_file); - - gcx().debug(context::conf, - "command line: {}", std::wstring(GetCommandLineW())); - - gcx().debug(context::conf, "using inis in order:"); - - for (auto&& ini : inis) - gcx().debug(context::conf, " . {}", ini); + // first, if any of these paths are empty, they are set using the second + // argument, which can be callable or a path + // + // the resulting path is made absolute and canonical and will bail out if it + // doesn't exist + // make sure third-party is in PATH before the other paths are checked + // because some of these paths will need to look in there to find stuff set_path_if_empty("third_party", find_third_party_directory); this_env::prepend_to_path(conf().path().third_party() / "bin"); @@ -474,39 +482,124 @@ void init_options( set_path_if_empty("licenses", find_in_root("licenses")); set_path_if_empty("qt_bin", qt::installation_path() / "bin"); + // second, if any of these paths are relative, they use the second argument + // as the root; if they're empty, they combine the second and third + // arguments + // + // these paths might not exist yet, so they're only made weakly canonical, + // they'll be created as needed during the build process + + const auto p = conf().path(); + + resolve_path("cache", p.prefix(), "downloads"); + resolve_path("build", p.prefix(), "build"); + resolve_path("install", p.prefix(), "install"); + resolve_path("install_installer", p.install(), "installer"); + resolve_path("install_bin", p.install(), "bin"); + resolve_path("install_libs", p.install(), "libs"); + resolve_path("install_pdbs", p.install(), "pdb"); + resolve_path("install_dlls", p.install_bin(), "dlls"); + resolve_path("install_loot", p.install_bin(), "loot"); + resolve_path("install_plugins", p.install_bin(), "plugins"); + resolve_path("install_licenses", p.install_bin(), "licenses"); + resolve_path("install_pythoncore", p.install_dlls(), "pythoncore"); + resolve_path("install_stylesheets", p.install_bin(), "stylesheets"); + resolve_path("install_translations", p.install_bin(), "resources/translations"); + + // finally, resolve the tools that are unlikely to be in PATH; all the + // other tools (7z, jom, patch, etc.) are assumed to be in PATH (which + // now contains third-party) or have valid absolute paths in the ini + details::set_string("tools", "vcvars", path_to_utf8(find_vcvars())); - - this_env::append_to_path(conf().path().get("qt_bin")); - - make_canonical_path("cache", conf().path().prefix(), "downloads"); - make_canonical_path("build", conf().path().prefix(), "build"); - make_canonical_path("install", conf().path().prefix(), "install"); - make_canonical_path("install_installer", conf().path().install(), "installer"); - make_canonical_path("install_bin", conf().path().install(), "bin"); - make_canonical_path("install_libs", conf().path().install(), "libs"); - make_canonical_path("install_pdbs", conf().path().install(), "pdb"); - make_canonical_path("install_dlls", conf().path().install_bin(), "dlls"); - make_canonical_path("install_loot", conf().path().install_bin(), "loot"); - make_canonical_path("install_plugins", conf().path().install_bin(), "plugins"); - make_canonical_path("install_licenses", conf().path().install_bin(), "licenses"); - - make_canonical_path( - "install_pythoncore", - conf().path().install_dlls(), "pythoncore"); - - make_canonical_path( - "install_stylesheets", - conf().path().install_bin(), "stylesheets"); - - make_canonical_path( - "install_translations", - conf().path().install_bin(), "resources/translations"); - details::set_string("tools", "iscc", path_to_utf8(find_iscc())); } +void init_options( + const std::vector& inis, const std::vector& opts) +{ + MOB_ASSERT(!inis.empty()); + + // some logging + gcx().debug(context::conf, "cl: {}", std::wstring(GetCommandLineW())); + gcx().debug(context::conf, "using inis in order:"); + for (auto&& ini : inis) + gcx().debug(context::conf, " . {}", ini); + + + // used to resolve a relative prefix; by default, it's resolved against cwd, + // but if an ini other than the master contains a prefix, use the ini's + // parent directory instead + fs::path prefix_root = fs::current_path(); + + // true for the first ini, will add values to the configuration maps instead + // of setting them, which throws if the option doesn't exist + // + // the goal is that the first, master ini contains all existing options and + // if an option set in another ini or on the command line doesn't exist in + // the master, it's an error + bool master = true; + + for (auto&& ini : inis) + { + const fs::path prefix_before = conf().path().prefix(); + + process_ini(ini, master); + + // check if the prefix was changed by this ini + if (!master && conf().path().prefix() != prefix_before) + { + // remember its path + prefix_root = ini.parent_path(); + } + + // further inis should only contain options that already exist + master = false; + } + + + if (!opts.empty()) + { + const fs::path prefix_before = conf().path().prefix(); + + process_cmd_options(opts); + + // check if the prefix was changed on the command line + if (conf().path().prefix() != prefix_before) + { + // use cwd as the parent of a relative prefix + prefix_root = fs::current_path(); + } + } + + // converts some options to ints or bools, these are used everywhere, like + // the log levels + set_special_options(); + + // an empty prefix is an error and will fail in validate_options(), but + // don't check it here to allow some commands to run, like `mob options`, + // and make sure it's not set to something that's not empty to make sure it + // _does_ fail later on + if (!conf().path().prefix().empty()) + resolve_path("prefix", prefix_root, ""); + + // set up the log file, resolve against prefix if relative + fs::path log_file = conf().global().get("log_file"); + if (log_file.is_relative()) + log_file = conf().path().prefix() / log_file; + + context::set_log_file(log_file); + + // goes through all paths and tools, finds missing or relative stuff, bails + // out of stuff can't be found + resolve_paths(); + + // make sure qt's bin directory is in the path + this_env::append_to_path(conf().path().get("qt_bin")); +} + bool verify_options() { + // can't have an empty prefix if (conf().path().prefix().empty()) { u8cerr @@ -516,7 +609,7 @@ bool verify_options() return false; } - // will be created later if it doesn't exist + // don't build mo inside mob if (fs::exists(conf().path().prefix())) { if (fs::equivalent(conf().path().prefix(), mob_exe_path().parent_path())) @@ -532,18 +625,6 @@ bool verify_options() return true; } -void log_options() -{ - for (auto&& line : format_options()) - gcx().trace(context::conf, "{}", line); -} - -void dump_available_options() -{ - for (auto&& line : format_options()) - u8cout << line << "\n"; -} - conf_global conf::global() { @@ -580,11 +661,6 @@ conf_paths conf::path() return {}; } -bool conf::dry() -{ - return conf().global().dry(); -} - conf_global::conf_global() : conf_section("global") @@ -596,60 +672,16 @@ int conf_global::output_log_level() const return details::g_output_log_level; } -void conf_global::set_output_log_level(const std::string& s) -{ - if (s.empty()) - return; - - try - { - const auto i = std::stoi(s); - - if (i < 0 || i > 6) - gcx().bail_out(context::generic, "bad output log level {}", i); - - details::g_output_log_level = i; - } - catch(std::exception&) - { - gcx().bail_out(context::generic, "bad output log level {}", s); - } -} - int conf_global::file_log_level() const { return details::g_file_log_level; } -void conf_global::set_file_log_level(const std::string& s) -{ - if (s.empty()) - return; - - try - { - const auto i = std::stoi(s); - if (i < 0 || i > 6) - gcx().bail_out(context::generic, "bad file log level {}", i); - - details::g_file_log_level = i; - } - catch(std::exception&) - { - gcx().bail_out(context::generic, "bad file log level {}", s); - } -} - bool conf_global::dry() const { return details::g_dry; } -void conf_global::set_dry(std::string_view s) -{ - details::g_dry = details::bool_from_string(s); -} - conf_task::conf_task(std::vector names) : names_(std::move(names)) diff --git a/src/core/conf.h b/src/core/conf.h index 659d9cd..a91d069 100644 --- a/src/core/conf.h +++ b/src/core/conf.h @@ -1,28 +1,52 @@ #pragma once +// these shouldn't be called directly, they're used by some of the template +// below +// +namespace mob::details +{ + +// returns an option named `key` from the given `section` +// +std::string get_string(std::string_view section, std::string_view key); + +// calls get_string(), converts to bool +// +bool get_bool(std::string_view section, std::string_view key); + +// calls get_string(), converts to in +// +int get_int(std::string_view section, std::string_view key); + +// sets the given option, bails out if the option doesn't exist +// +void set_string( + std::string_view section, std::string_view key, std::string_view value); + +} // namespace + + namespace mob { -namespace details -{ - std::string get_string(std::string_view section, std::string_view key); - bool get_bool(std::string_view section, std::string_view key); - int get_int(std::string_view section, std::string_view key); - - void set_string( - std::string_view section, std::string_view key, - std::string_view value); -} - - +// reads options from the given inis and option strings, resolves all the paths +// and necessary tools, also adds a couple of things to PATH +// void init_options( const std::vector& inis, const std::vector& opts); +// checks some of the options once everything is loaded, returns false if +// something's wrong +// bool verify_options(); -void log_options(); -void dump_available_options(); + +// returns all options formatted as three columns +// +std::vector format_options(); +// base class for all conf structs +// template class conf_section { @@ -32,6 +56,7 @@ public: return details::get_string(name_, key); } + // undefined template T get(std::string_view key) const; @@ -63,22 +88,19 @@ private: }; +// options in [global] +// class conf_global : public conf_section { public: conf_global(); + // convenience, doesn't need string manipulation int output_log_level() const; - void set_output_log_level(const std::string& s); - int file_log_level() const; - void set_file_log_level(const std::string& s); - bool dry() const; - void set_dry(std::string_view s); - - fs::path log_file() const { return get("log_file"); } + // convenience bool redownload() const { return get("redownload"); } bool reextract() const { return get("reextract"); } bool reconfigure() const { return get("reconfigure"); } @@ -86,13 +108,11 @@ public: bool clean() const { return get("clean_task"); } bool fetch() const { return get("fetch_task"); } bool build() const { return get("build_task"); } - - bool ignore_uncommitted() const - { - return get("ignore_uncommitted"); - } }; + +// options in [task] or [task_name:task] +// class conf_task { public: @@ -115,24 +135,36 @@ private: bool get_bool(std::string_view name) const; }; + +// options in [tools] +// class conf_tools : public conf_section { public: conf_tools(); }; + +// options in [transifex] +// class conf_transifex : public conf_section { public: conf_transifex(); }; + +// options in [versions] +// class conf_versions : public conf_section { public: conf_versions(); }; + +// options in [prebuilt] +// class conf_prebuilt : public conf_section { public: @@ -140,13 +172,14 @@ public: }; +// options in [paths] +// class conf_paths : public conf_section { public: conf_paths(); -#define VALUE(NAME) \ - fs::path NAME() const { return get(#NAME); } +#define VALUE(NAME) fs::path NAME() const { return get(#NAME); } VALUE(third_party); VALUE(prefix); @@ -181,6 +214,9 @@ public: }; +// should be used as conf().global().whatever(), doesn't actually hold anything, +// but it's better than a bunch of static functions +// class conf { public: @@ -191,9 +227,6 @@ public: conf_prebuilt prebuilt(); conf_versions version(); conf_paths path(); - - // this just forwards to conf_global, but it's used everywhere - static bool dry(); }; } // namespace diff --git a/src/core/context.cpp b/src/core/context.cpp index 888984d..efe9a6d 100644 --- a/src/core/context.cpp +++ b/src/core/context.cpp @@ -80,7 +80,7 @@ const char* reason_string(context::reason r) case context::cmd: return "cmd"; case context::std_out: return "stdout"; case context::std_err: return "stderr"; - case context::fs: return (conf::dry() ? "fs-dry" : "fs"); + case context::fs: return (conf().global().dry() ? "fs-dry" : "fs"); case context::net: return "net"; case context::generic: return ""; case context::conf: return "conf"; @@ -227,7 +227,7 @@ bool context::enabled(level lv) void context::set_log_file(const fs::path& p) { - if (!conf::dry() && !p.empty()) + if (!mob::conf().global().dry() && !p.empty()) { // creating directory if (!exists(p.parent_path())) diff --git a/src/core/op.cpp b/src/core/op.cpp index 6f6da9d..4105164 100644 --- a/src/core/op.cpp +++ b/src/core/op.cpp @@ -29,7 +29,7 @@ void touch(const context& cx, const fs::path& p, flags f) cx.trace(context::fs, "touching {}", p); check(cx, p, f); - if (!conf::dry()) + if (!conf().global().dry()) do_touch(cx, p); } @@ -38,7 +38,7 @@ void create_directories(const context& cx, const fs::path& p, flags f) cx.trace(context::fs, "creating dir {}", p); check(cx, p, f); - if (!conf::dry()) + if (!conf().global().dry()) do_create_directories(cx, p); } @@ -63,7 +63,7 @@ void delete_directory(const context& cx, const fs::path& p, flags f) if (fs::exists(p) && !fs::is_directory(p)) cx.bail_out(context::fs, "{} is not a dir", p); - if (!conf::dry()) + if (!conf().global().dry()) do_delete_directory(cx, p); } @@ -95,7 +95,7 @@ void delete_file(const context& cx, const fs::path& p, flags f) return; } - if (!conf::dry()) + if (!conf().global().dry()) do_delete_file(cx, p); } @@ -131,7 +131,7 @@ void remove_readonly(const context& cx, const fs::path& dir, flags f) cx.trace(context::fs, "removing read-only from {}", dir); check(cx, dir, f); - if (!conf::dry()) + if (!conf().global().dry()) { for (auto&& p : fs::recursive_directory_iterator(dir)) { @@ -228,7 +228,7 @@ void rename(const context& cx, const fs::path& src, const fs::path& dest, flags cx.trace(context::fs, "renaming {} to {}", src, dest); - if (!conf::dry()) + if (!conf().global().dry()) do_rename(cx, src, dest); } @@ -249,7 +249,7 @@ void move_to_directory( cx.trace(context::fs, "moving {} to {}", src, target); - if (!conf::dry()) + if (!conf().global().dry()) do_rename(cx, src, target); } @@ -262,7 +262,7 @@ void copy_file_to_dir_if_better( if (file.u8string().find(u8"*") != std::string::npos) cx.bail_out(context::fs, "{} contains a glob", file); - if (!conf::dry()) + if (!conf().global().dry()) { if (!fs::exists(file) || !fs::is_regular_file(file)) { @@ -286,7 +286,7 @@ void copy_file_to_dir_if_better( { cx.trace(context::fs, "{} -> {}", file, dir); - if (!conf::dry()) + if (!conf().global().dry()) do_copy_file_to_dir(cx, file, dir); } else @@ -304,7 +304,7 @@ void copy_file_to_file_if_better( if (src.u8string().find(u8"*") != std::string::npos) cx.bail_out(context::fs, "{} contains a glob", src); - if (!conf::dry()) + if (!conf().global().dry()) { if (!fs::exists(src)) { @@ -330,7 +330,7 @@ void copy_file_to_file_if_better( { cx.trace(context::fs, "{} -> {}", src, dest); - if (!conf::dry()) + if (!conf().global().dry()) do_copy_file_to_file(cx, src, dest); } else @@ -409,7 +409,7 @@ void replace_file( check(cx, src, f); check(cx, dest, f); - if (conf::dry()) + if (conf().global().dry()) return; const wchar_t* backup_p = nullptr; @@ -491,7 +491,7 @@ void write_text_file( check(cx, p, f); - if (conf::dry()) + if (conf().global().dry()) return; { @@ -524,7 +524,7 @@ void archive_from_glob( cx.trace(context::fs, "archiving {} into {}", src_glob, dest_file); check(cx, dest_file, f); - if (conf::dry()) + if (conf().global().dry()) return; archiver::create_from_glob(cx, dest_file, src_glob, ignore); @@ -541,7 +541,7 @@ void archive_from_files( "archiving {} files rooted in {} into {}", files.size(), files_root, dest_file); - if (conf::dry()) + if (conf().global().dry()) return; archiver::create_from_files(cx, dest_file, files, files_root); diff --git a/src/core/paths.cpp b/src/core/paths.cpp index fe27126..8adacc8 100644 --- a/src/core/paths.cpp +++ b/src/core/paths.cpp @@ -400,7 +400,7 @@ fs::path find_vcvars() // check from the ini first fs::path bat = conf().tool().get("vcvars"); - if (conf::dry()) + if (conf().global().dry()) { if (bat.empty()) bat = "vcvars.bat"; diff --git a/src/core/process.cpp b/src/core/process.cpp index 2cf6df9..4cddd0f 100644 --- a/src/core/process.cpp +++ b/src/core/process.cpp @@ -257,7 +257,7 @@ void process::run() const auto what = make_cmd(); cx_->debug(context::cmd, "> {}", what); - if (conf::dry()) + if (conf().global().dry()) return; // shouldn't happen diff --git a/src/net.cpp b/src/net.cpp index 3f028cc..9a5aa35 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -113,7 +113,7 @@ curl_downloader& curl_downloader::start() ok_ = false; cx_.debug(context::net, "downloading {} to {}", url_, path_); - if (conf::dry()) + if (conf().global().dry()) return *this; thread_ = start_thread([&]{ run(); }); diff --git a/src/tools/git.cpp b/src/tools/git.cpp index 71f14d4..a729959 100644 --- a/src/tools/git.cpp +++ b/src/tools/git.cpp @@ -21,7 +21,7 @@ void git::delete_directory(const context& cx, const fs::path& p) git g(no_op); g.root(p); - if (!conf().global().ignore_uncommitted()) + if (!conf().global().get("ignore_uncommitted")) { if (g.has_uncommitted_changes()) {