removed conf::dry

refactor, comments
This commit is contained in:
isanae
2020-12-03 17:45:33 -05:00
parent f2e81f5335
commit d94ce21204
10 changed files with 328 additions and 259 deletions
+1 -1
View File
@@ -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");
+6 -2
View File
@@ -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;
}
+236 -204
View File
File diff suppressed because it is too large Load Diff
+64 -31
View File
@@ -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<fs::path>& inis, const std::vector<std::string>& 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<std::string> format_options();
// base class for all conf structs
//
template <class DefaultType>
class conf_section
{
@@ -32,6 +56,7 @@ public:
return details::get_string(name_, key);
}
// undefined
template <class T>
T get(std::string_view key) const;
@@ -63,22 +88,19 @@ private:
};
// options in [global]
//
class conf_global : public conf_section<std::string>
{
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<bool>("redownload"); }
bool reextract() const { return get<bool>("reextract"); }
bool reconfigure() const { return get<bool>("reconfigure"); }
@@ -86,13 +108,11 @@ public:
bool clean() const { return get<bool>("clean_task"); }
bool fetch() const { return get<bool>("fetch_task"); }
bool build() const { return get<bool>("build_task"); }
bool ignore_uncommitted() const
{
return get<bool>("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<fs::path>
{
public:
conf_tools();
};
// options in [transifex]
//
class conf_transifex : public conf_section<std::string>
{
public:
conf_transifex();
};
// options in [versions]
//
class conf_versions : public conf_section<std::string>
{
public:
conf_versions();
};
// options in [prebuilt]
//
class conf_prebuilt : public conf_section<std::string>
{
public:
@@ -140,13 +172,14 @@ public:
};
// options in [paths]
//
class conf_paths : public conf_section<fs::path>
{
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
+2 -2
View File
@@ -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()))
+15 -15
View File
@@ -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);
+1 -1
View File
@@ -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";
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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(); });
+1 -1
View File
@@ -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<bool>("ignore_uncommitted"))
{
if (g.has_uncommitted_changes())
{