From f2806d10dd26341331a8903c1212adf10831ea3a Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sun, 17 May 2020 16:22:04 -0400 Subject: [PATCH] added --no-pull new task_conf() to avoid fiddling with names everywhere changed syntax from tool/section to tool:section, easier to parse --- mob.ini | 1 + src/commands.cpp | 8 ++++- src/commands.h | 1 + src/conf.cpp | 71 +++++++++++++++++--------------------- src/conf.h | 15 +++----- src/tasks/boost_di.cpp | 2 +- src/tasks/gtest.cpp | 2 +- src/tasks/libffi.cpp | 2 +- src/tasks/lz4.cpp | 2 +- src/tasks/modorganizer.cpp | 10 +++--- src/tasks/ncc.cpp | 6 ++-- src/tasks/nmm.cpp | 2 +- src/tasks/python.cpp | 2 +- src/tasks/spdlog.cpp | 2 +- src/tasks/task.cpp | 5 +++ src/tasks/task.h | 40 ++++++++++++++++++++- src/tasks/tasks.h | 1 - src/tasks/usvfs.cpp | 4 +-- src/tools/git.cpp | 54 +++++++++++++++++++---------- src/tools/tools.h | 8 +++-- 20 files changed, 147 insertions(+), 91 deletions(-) diff --git a/mob.ini b/mob.ini index 65d736a..0afa9f2 100644 --- a/mob.ini +++ b/mob.ini @@ -10,6 +10,7 @@ log_file = mob.log [options] mo_org = ModOrganizer2 mo_branch = master +no_pull = false [tools] sevenz = 7z.exe diff --git a/src/commands.cpp b/src/commands.cpp index 7beaff8..81a2b5b 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -279,6 +279,9 @@ clipp::group build_command::do_group() (clipp::option("-n", "--new") >> clean_) % "deletes everything and starts from scratch", + (clipp::option("-p", "--no-pull") >> nopull_) + % "clones repos if necessary, but never pulls once cloned", + (clipp::option("--keep-msbuild") >> keep_msbuild_) % "don't terminate msbuild.exe instances after building", @@ -298,6 +301,9 @@ void build_command::do_pre_run() if (rebuild_ || clean_) common.options.push_back("options/rebuild=true"); + + if (nopull_) + common.options.push_back("options/no_pull=true"); } int build_command::do_run() @@ -329,7 +335,7 @@ void build_command::terminate_msbuild() if (conf::dry()) return; - system("taskkill /im msbuild.exe /f > NUL"); + system("taskkill /im msbuild.exe /f > NUL 2>&1"); } diff --git a/src/commands.h b/src/commands.h index 94da6d0..ee86501 100644 --- a/src/commands.h +++ b/src/commands.h @@ -103,6 +103,7 @@ private: bool reextract_ = false; bool rebuild_ = false; bool clean_ = false; + bool nopull_ = false; bool keep_msbuild_ = false; void terminate_msbuild(); diff --git a/src/conf.cpp b/src/conf.cpp index 8f5cb4c..56813d5 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -138,7 +138,7 @@ std::string conf::global_by_name(const std::string& name) bool conf::bool_global_by_name(const std::string& name) { - std::istringstream iss(get_global("global", name)); + std::istringstream iss(global_by_name(name)); bool b; iss >> std::boolalpha >> b; return b; @@ -150,6 +150,15 @@ std::string conf::option_by_name( return get_for_task(task_names, "options", name); } +bool conf::bool_option_by_name( + const std::vector& task_names, const std::string& name) +{ + std::istringstream iss(option_by_name(task_names, name)); + bool b; + iss >> std::boolalpha >> b; + return b; +} + void conf::set_output_log_level(const std::string& s) { if (s.empty()) @@ -230,30 +239,28 @@ std::vector conf::format_options() struct parsed_option { - std::string section, key, value; + std::string task, section, key, value; }; parsed_option parse_option(const std::string& s) { - const auto slash = s.find("/"); - if (slash == std::string::npos) + // task:section/key=value + // task: is optional + std::regex re(R"((?:(.+)\:)?(.+)/(.*)=(.*))"); + std::smatch m; + + if (!std::regex_match(s, m, re)) { gcx().bail_out(context::conf, - "bad option {}, must be section/key=value", s); + "bad option {}, must be [task:]section/key=value", s); } - const auto equal = s.find("=", slash); - if (slash == std::string::npos) - { - gcx().bail_out(context::conf, - "bad option {}, must be section/key=value", s); - } + std::string task = trim_copy(m[1]); + std::string section = trim_copy(m[2]); + std::string key = trim_copy(m[3]); + std::string value = trim_copy(m[4]); - std::string section = s.substr(0, slash); - std::string key = s.substr(slash + 1, equal - slash - 1); - std::string value = s.substr(equal + 1); - - return {section, key, value}; + return {task, section, key, value}; } bool try_parts(fs::path& check, const std::vector& parts) @@ -671,16 +678,16 @@ void parse_ini(const fs::path& ini, bool add) std::string task, section; - const auto slash = s.find("/"); + const auto col = s.find(":"); - if (slash == std::string::npos) + if (col == std::string::npos) { section = s; } else { - task = s.substr(0, slash); - section = s.substr(slash +1 ); + task = s.substr(0, col); + section = s.substr(col + 1); } parse_section(ini, i, lines, task, section, add); @@ -694,24 +701,6 @@ void parse_ini(const fs::path& ini, bool add) bool check_missing_options() { - if (conf::mo_org({""}).empty()) - { - u8cerr - << "missing mo_org; either specify it the [options] section of " - << "the ini or pass '-s options/mo_org=something'\n"; - - return false; - } - - if (conf::mo_branch({""}).empty()) - { - u8cerr - << "missing mo_branch; either specify it the [options] section of " - << "the ini or pass '-s options/mo_org=something'\n"; - - return false; - } - if (paths::prefix().empty()) { u8cerr @@ -855,7 +844,11 @@ void init_options( for (auto&& o : opts) { const auto po = parse_option(o); - conf::set_global(po.section, po.key, po.value); + + if (po.task.empty()) + conf::set_global(po.section, po.key, po.value); + else + conf::set_for_task(po.task, po.section, po.key, po.value); } } diff --git a/src/conf.h b/src/conf.h index 38628cb..81c7296 100644 --- a/src/conf.h +++ b/src/conf.h @@ -38,6 +38,9 @@ public: static std::string option_by_name( const std::vector& task_names, const std::string& name); + static bool bool_option_by_name( + const std::vector& task_names, const std::string& name); + static int output_log_level() { return output_log_level_; } static void set_output_log_level(const std::string& s); @@ -51,17 +54,6 @@ public: static bool reextract() { return bool_global_by_name("reextract"); } static bool rebuild() { return bool_global_by_name("rebuild"); } - - static std::string mo_org(const std::vector& task_names) - { - return option_by_name(task_names, "mo_org"); - } - - static std::string mo_branch(const std::vector& task_names) - { - return option_by_name(task_names, "mo_branch"); - } - static std::vector format_options(); private: @@ -76,6 +68,7 @@ private: static int file_log_level_; }; + struct paths { #define VALUE(NAME) \ diff --git a/src/tasks/boost_di.cpp b/src/tasks/boost_di.cpp index 21be2a7..c31e93d 100644 --- a/src/tasks/boost_di.cpp +++ b/src/tasks/boost_di.cpp @@ -26,7 +26,7 @@ fs::path boost_di::source_path() void boost_di::do_fetch() { - run_tool(git(git::clone_or_pull) + run_tool(git(task_conf().git_op()) .url(make_github_url("boost-experimental", "di")) .branch("cpp14") .output(source_path())); diff --git a/src/tasks/gtest.cpp b/src/tasks/gtest.cpp index 571609d..d2a1c1a 100644 --- a/src/tasks/gtest.cpp +++ b/src/tasks/gtest.cpp @@ -31,7 +31,7 @@ void gtest::do_clean_for_rebuild() void gtest::do_fetch() { - run_tool(git(git::clone_or_pull) + run_tool(git(task_conf().git_op()) .url(make_github_url("google", "googletest")) .branch(version()) .output(source_path())); diff --git a/src/tasks/libffi.cpp b/src/tasks/libffi.cpp index e55d7ba..a9b4e65 100644 --- a/src/tasks/libffi.cpp +++ b/src/tasks/libffi.cpp @@ -26,7 +26,7 @@ fs::path libffi::source_path() void libffi::do_fetch() { - run_tool(git(git::clone_or_pull) + run_tool(git(task_conf().git_op()) .url(make_github_url("python","cpython-bin-deps")) .branch("libffi") .output(source_path())); diff --git a/src/tasks/lz4.cpp b/src/tasks/lz4.cpp index b8d5433..8f9c4f6 100644 --- a/src/tasks/lz4.cpp +++ b/src/tasks/lz4.cpp @@ -72,7 +72,7 @@ void lz4::build_and_install_prebuilt() void lz4::fetch_from_source() { - run_tool(git(git::clone_or_pull) + run_tool(git(task_conf().git_op()) .url(make_github_url("lz4","lz4")) .branch(version()) .output(source_path())); diff --git a/src/tasks/modorganizer.cpp b/src/tasks/modorganizer.cpp index ec2ccd5..4a603c9 100644 --- a/src/tasks/modorganizer.cpp +++ b/src/tasks/modorganizer.cpp @@ -58,9 +58,9 @@ void modorganizer::do_fetch() { initialize_super(super_path()); - run_tool(git(git::clone_or_pull) - .url(make_github_url(conf::mo_org(names()), repo_)) - .branch(conf::mo_branch(names())) + run_tool(git(task_conf().git_op()) + .url(make_github_url(task_conf().mo_org(), repo_)) + .branch(task_conf().mo_branch()) .output(this_source_path())); } @@ -75,10 +75,10 @@ void modorganizer::do_build_and_install() .arg("submodule") .arg("--quiet") .arg("add") - .arg("-b", conf::mo_branch(names())) + .arg("-b", task_conf().mo_branch()) .arg("--force") .arg("--name", name()) - .arg(make_github_url(conf::mo_org(names()), repo_)) + .arg(make_github_url(task_conf().mo_org(), repo_)) .arg(name()) .cwd(super_path()))); } diff --git a/src/tasks/ncc.cpp b/src/tasks/ncc.cpp index 21ae9fc..f67fb70 100644 --- a/src/tasks/ncc.cpp +++ b/src/tasks/ncc.cpp @@ -32,9 +32,9 @@ void ncc::do_clean_for_rebuild() void ncc::do_fetch() { - run_tool(git(git::clone_or_pull) - .url(make_github_url(conf::mo_org(names()), "modorganizer-NCC")) - .branch(conf::mo_branch(names())) + run_tool(git(task_conf().git_op()) + .url(make_github_url(task_conf().mo_org(), "modorganizer-NCC")) + .branch(task_conf().mo_branch()) .output(source_path())); } diff --git a/src/tasks/nmm.cpp b/src/tasks/nmm.cpp index 5423f7c..45e8b24 100644 --- a/src/tasks/nmm.cpp +++ b/src/tasks/nmm.cpp @@ -31,7 +31,7 @@ void nmm::do_clean_for_rebuild() void nmm::do_fetch() { - run_tool(git(git::clone_or_pull) + run_tool(git(task_conf().git_op()) .url(make_github_url("Nexus-Mods", "Nexus-Mod-Manager")) .branch(version()) .output(source_path())); diff --git a/src/tasks/python.cpp b/src/tasks/python.cpp index f5190f9..e85e230 100644 --- a/src/tasks/python.cpp +++ b/src/tasks/python.cpp @@ -111,7 +111,7 @@ void python::build_and_install_prebuilt() void python::fetch_from_source() { - run_tool(git(git::clone_or_pull) + run_tool(git(task_conf().git_op()) .url(make_github_url("python", "cpython")) .branch(version()) .output(source_path())); diff --git a/src/tasks/spdlog.cpp b/src/tasks/spdlog.cpp index d0abd49..a2ac18e 100644 --- a/src/tasks/spdlog.cpp +++ b/src/tasks/spdlog.cpp @@ -26,7 +26,7 @@ fs::path spdlog::source_path() void spdlog::do_fetch() { - run_tool(git(git::clone_or_pull) + run_tool(git(task_conf().git_op()) .url(make_github_url("gabime", "spdlog")) .branch(version()) .output(source_path())); diff --git a/src/tasks/task.cpp b/src/tasks/task.cpp index 7b19999..6ddc6b2 100644 --- a/src/tasks/task.cpp +++ b/src/tasks/task.cpp @@ -288,6 +288,11 @@ void task::parallel(std::vector>> t.join(); } +task_conf_holder task::task_conf() const +{ + return task_conf_holder(names_); +} + void task::run() { threaded_run(name(), [&] diff --git a/src/tasks/task.h b/src/tasks/task.h index c2d0e93..f9b6ee4 100644 --- a/src/tasks/task.h +++ b/src/tasks/task.h @@ -2,11 +2,13 @@ #include "../utility.h" #include "../context.h" +#include "../tools/tools.h" namespace mob { class task; +class tool; void add_task(std::unique_ptr t); @@ -25,7 +27,41 @@ void run_all_tasks(); void list_tasks(bool err=false); -class tool; +class task_conf_holder +{ +public: + task_conf_holder(std::vector names) + : names_(std::move(names)) + { + } + + std::string mo_org() + { + return conf::option_by_name(names_, "mo_org"); + } + + std::string mo_branch() + { + return conf::option_by_name(names_, "mo_branch"); + } + + bool no_pull() + { + return conf::bool_option_by_name(names_, "no_pull"); + } + + git::ops git_op() + { + if (no_pull()) + return git::clone; + else + return git::clone_or_pull2; + } + +private: + std::vector names_; +}; + class task { @@ -80,6 +116,8 @@ protected: void threaded_run(std::string name, std::function f); void parallel(std::vector>> v); + task_conf_holder task_conf() const; + private: struct thread_context; diff --git a/src/tasks/tasks.h b/src/tasks/tasks.h index dee788d..5e568dd 100644 --- a/src/tasks/tasks.h +++ b/src/tasks/tasks.h @@ -5,7 +5,6 @@ #include "../conf.h" #include "../utility.h" #include "../op.h" -#include "../tools/tools.h" namespace mob { diff --git a/src/tasks/usvfs.cpp b/src/tasks/usvfs.cpp index da33fa3..c588e5d 100644 --- a/src/tasks/usvfs.cpp +++ b/src/tasks/usvfs.cpp @@ -65,8 +65,8 @@ void usvfs::build_and_install_prebuilt() void usvfs::fetch_from_source() { - run_tool(git(git::clone_or_pull) - .url(make_github_url(conf::mo_org(names()), "usvfs")) + run_tool(git(task_conf().git_op()) + .url(make_github_url(task_conf().mo_org(), "usvfs")) .branch(version()) .output(source_path())); } diff --git a/src/tools/git.cpp b/src/tools/git.cpp index 78c3f5b..5720f2c 100644 --- a/src/tools/git.cpp +++ b/src/tools/git.cpp @@ -35,9 +35,31 @@ git& git::output(const fs::path& dir) void git::do_run() { + if (url_.empty() || where_.empty()) + bail_out("git missing parameters"); + + if (conf::redownload() || conf::reextract()) + { + cx_->trace(context::rebuild, "deleting directory controlled by git"); + op::delete_directory(*cx_, where_, op::optional); + } + + switch (op_) { - case clone_or_pull: + case clone: + { + do_clone(); + break; + } + + case pull: + { + do_pull(); + break; + } + + case clone_or_pull2: { do_clone_or_pull(); break; @@ -52,25 +74,19 @@ void git::do_run() void git::do_clone_or_pull() { - if (url_.empty() || where_.empty()) - bail_out("git missing parameters"); - - if (conf::redownload() || conf::reextract()) - { - cx_->trace(context::rebuild, "deleting directory controlled by git"); - op::delete_directory(*cx_, where_, op::optional); - } - - const fs::path dot_git = where_ / ".git"; - - if (!fs::exists(dot_git)) - clone(); - else - pull(); + if (!do_clone()) + do_pull(); } -void git::clone() +bool git::do_clone() { + const fs::path dot_git = where_ / ".git"; + if (fs::exists(dot_git)) + { + cx_->trace(context::generic, "not cloning, {} exists", dot_git); + return false; + } + process_ = process() .binary(binary()) .stderr_level(context::level::trace) @@ -84,9 +100,11 @@ void git::clone() .arg(where_); execute_and_join(); + + return true; } -void git::pull() +void git::do_pull() { process_ = process() .binary(binary()) diff --git a/src/tools/tools.h b/src/tools/tools.h index 659472d..5167fbc 100644 --- a/src/tools/tools.h +++ b/src/tools/tools.h @@ -134,7 +134,9 @@ class git : public basic_process_runner public: enum ops { - clone_or_pull = 1 + clone = 1, + pull, + clone_or_pull2 }; @@ -156,8 +158,8 @@ private: fs::path where_; void do_clone_or_pull(); - void clone(); - void pull(); + bool do_clone(); + void do_pull(); };