mirror of
https://github.com/ModOrganizer2/mob.git
synced 2026-07-27 14:07:05 -07:00
added --no-pull
new task_conf() to avoid fiddling with names everywhere changed syntax from tool/section to tool:section, easier to parse
This commit is contained in:
@@ -10,6 +10,7 @@ log_file = mob.log
|
||||
[options]
|
||||
mo_org = ModOrganizer2
|
||||
mo_branch = master
|
||||
no_pull = false
|
||||
|
||||
[tools]
|
||||
sevenz = 7z.exe
|
||||
|
||||
+7
-1
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ private:
|
||||
bool reextract_ = false;
|
||||
bool rebuild_ = false;
|
||||
bool clean_ = false;
|
||||
bool nopull_ = false;
|
||||
bool keep_msbuild_ = false;
|
||||
|
||||
void terminate_msbuild();
|
||||
|
||||
+32
-39
@@ -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<std::string>& 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<std::string> 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<std::string>& 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-11
@@ -38,6 +38,9 @@ public:
|
||||
static std::string option_by_name(
|
||||
const std::vector<std::string>& task_names, const std::string& name);
|
||||
|
||||
static bool bool_option_by_name(
|
||||
const std::vector<std::string>& 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<std::string>& task_names)
|
||||
{
|
||||
return option_by_name(task_names, "mo_org");
|
||||
}
|
||||
|
||||
static std::string mo_branch(const std::vector<std::string>& task_names)
|
||||
{
|
||||
return option_by_name(task_names, "mo_branch");
|
||||
}
|
||||
|
||||
static std::vector<std::string> format_options();
|
||||
|
||||
private:
|
||||
@@ -76,6 +68,7 @@ private:
|
||||
static int file_log_level_;
|
||||
};
|
||||
|
||||
|
||||
struct paths
|
||||
{
|
||||
#define VALUE(NAME) \
|
||||
|
||||
@@ -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()));
|
||||
|
||||
+1
-1
@@ -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()));
|
||||
|
||||
@@ -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()));
|
||||
|
||||
+1
-1
@@ -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()));
|
||||
|
||||
@@ -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())));
|
||||
}
|
||||
|
||||
+3
-3
@@ -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()));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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()));
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -288,6 +288,11 @@ void task::parallel(std::vector<std::pair<std::string, std::function<void ()>>>
|
||||
t.join();
|
||||
}
|
||||
|
||||
task_conf_holder task::task_conf() const
|
||||
{
|
||||
return task_conf_holder(names_);
|
||||
}
|
||||
|
||||
void task::run()
|
||||
{
|
||||
threaded_run(name(), [&]
|
||||
|
||||
+39
-1
@@ -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<task> 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<std::string> 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<std::string> names_;
|
||||
};
|
||||
|
||||
|
||||
class task
|
||||
{
|
||||
@@ -80,6 +116,8 @@ protected:
|
||||
void threaded_run(std::string name, std::function<void ()> f);
|
||||
void parallel(std::vector<std::pair<std::string, std::function<void ()>>> v);
|
||||
|
||||
task_conf_holder task_conf() const;
|
||||
|
||||
private:
|
||||
struct thread_context;
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "../conf.h"
|
||||
#include "../utility.h"
|
||||
#include "../op.h"
|
||||
#include "../tools/tools.h"
|
||||
|
||||
namespace mob
|
||||
{
|
||||
|
||||
+2
-2
@@ -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()));
|
||||
}
|
||||
|
||||
+36
-18
@@ -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())
|
||||
|
||||
+5
-3
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user