mirror of
https://github.com/ModOrganizer2/mob.git
synced 2026-07-27 14:07:05 -07:00
reworked tools and run_tool() to use member functions to various settings
This commit is contained in:
+1
-1
@@ -91,7 +91,7 @@ const std::string& get_conf(const std::string& name)
|
||||
}
|
||||
|
||||
|
||||
bool conf::verbose() { return true; }
|
||||
bool conf::verbose() { return false; }
|
||||
bool conf::dry() { return false; }
|
||||
|
||||
fs::path third_party::sevenz() { return "7z"; }
|
||||
|
||||
+225
-102
File diff suppressed because it is too large
Load Diff
+5
-10
@@ -7,15 +7,6 @@
|
||||
namespace builder
|
||||
{
|
||||
|
||||
std::string redir_nul()
|
||||
{
|
||||
if (conf::verbose())
|
||||
return {};
|
||||
else
|
||||
return " > NUL";
|
||||
}
|
||||
|
||||
|
||||
url::url(const char* p)
|
||||
: s_(p)
|
||||
{
|
||||
@@ -86,10 +77,13 @@ void curl_downloader::run()
|
||||
{
|
||||
auto* c = curl_easy_init();
|
||||
|
||||
char error_buffer[CURL_ERROR_SIZE + 1] = {};
|
||||
|
||||
curl_easy_setopt(c, CURLOPT_URL, url_.c_str());
|
||||
curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, on_write_static);
|
||||
curl_easy_setopt(c, CURLOPT_WRITEDATA, this);
|
||||
curl_easy_setopt(c, CURLOPT_FOLLOWLOCATION, 1l);
|
||||
curl_easy_setopt(c, CURLOPT_ERRORBUFFER, error_buffer);
|
||||
|
||||
file_deleter output_deleter(path_);
|
||||
|
||||
@@ -99,7 +93,7 @@ void curl_downloader::run()
|
||||
if (interrupt_)
|
||||
return;
|
||||
|
||||
if (r == 0)
|
||||
if (r == CURLE_OK)
|
||||
{
|
||||
long h = 0;
|
||||
curl_easy_getinfo(c, CURLINFO_RESPONSE_CODE, &h);
|
||||
@@ -117,6 +111,7 @@ void curl_downloader::run()
|
||||
else
|
||||
{
|
||||
error(url_.string() + " curl: " + curl_easy_strerror(r));
|
||||
error(error_buffer);
|
||||
}
|
||||
|
||||
curl_easy_cleanup(c);
|
||||
|
||||
+208
-100
File diff suppressed because it is too large
Load Diff
+120
-52
@@ -12,11 +12,16 @@ void vcvars();
|
||||
class tool
|
||||
{
|
||||
public:
|
||||
tool(tool&& t);
|
||||
tool& operator=(tool&& t);
|
||||
|
||||
virtual ~tool() = default;
|
||||
|
||||
void run();
|
||||
void interrupt();
|
||||
|
||||
void result() {}
|
||||
|
||||
protected:
|
||||
tool(std::string name);
|
||||
|
||||
@@ -34,37 +39,35 @@ private:
|
||||
class downloader : public tool
|
||||
{
|
||||
public:
|
||||
downloader(url u);
|
||||
downloader(std::vector<url> urls);
|
||||
downloader();
|
||||
downloader(builder::url u);
|
||||
|
||||
fs::path file() const;
|
||||
downloader& url(const builder::url& u);
|
||||
|
||||
fs::path result() const;
|
||||
|
||||
protected:
|
||||
void do_run() override;
|
||||
void do_interrupt() override;
|
||||
|
||||
private:
|
||||
curl_downloader dl_;
|
||||
std::unique_ptr<curl_downloader> dl_;
|
||||
fs::path file_;
|
||||
std::vector<url> urls_;
|
||||
std::vector<builder::url> urls_;
|
||||
|
||||
fs::path path_for_url(const url& u) const;
|
||||
fs::path path_for_url(const builder::url& u) const;
|
||||
};
|
||||
|
||||
|
||||
class process_runner : public tool
|
||||
class basic_process_runner : public tool
|
||||
{
|
||||
public:
|
||||
process_runner(std::string name, std::string cmd, fs::path cwd={});
|
||||
process_runner(const cmd& c);
|
||||
|
||||
void join(bool check_exit_code=true);
|
||||
int exit_code() const;
|
||||
|
||||
protected:
|
||||
process_runner(std::string name);
|
||||
basic_process_runner(std::string name);
|
||||
|
||||
void do_run() override;
|
||||
void do_interrupt() override;
|
||||
|
||||
int execute_and_join(process p, bool check_exit_code=true);
|
||||
@@ -77,17 +80,74 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class git_clone : public process_runner
|
||||
class process_runner : public basic_process_runner
|
||||
{
|
||||
public:
|
||||
git_clone(
|
||||
std::string author, std::string repo, std::string b, fs::path where);
|
||||
process_runner(fs::path exe, cmd::flags flags)
|
||||
: basic_process_runner(exe.filename().string()), cmd_(exe, flags)
|
||||
{
|
||||
}
|
||||
|
||||
process_runner& name(const std::string& s)
|
||||
{
|
||||
cmd_.name(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::string& name() const
|
||||
{
|
||||
return cmd_.name();
|
||||
}
|
||||
|
||||
process_runner& cwd(const fs::path& p)
|
||||
{
|
||||
cmd_.cwd(p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const fs::path& cwd() const
|
||||
{
|
||||
return cmd_.cwd();
|
||||
}
|
||||
|
||||
template <class... Args>
|
||||
process_runner& arg(Args&&... args)
|
||||
{
|
||||
cmd_.arg(std::forward<Args>(args)...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
int result() const
|
||||
{
|
||||
return exit_code();
|
||||
}
|
||||
|
||||
protected:
|
||||
void do_run() override
|
||||
{
|
||||
execute_and_join(cmd_);
|
||||
}
|
||||
|
||||
private:
|
||||
cmd cmd_;
|
||||
};
|
||||
|
||||
|
||||
class git_clone : public basic_process_runner
|
||||
{
|
||||
public:
|
||||
git_clone();
|
||||
|
||||
git_clone& org(const std::string& name);
|
||||
git_clone& repo(const std::string& name);
|
||||
git_clone& branch(const std::string& name);
|
||||
git_clone& output(const fs::path& dir);
|
||||
|
||||
protected:
|
||||
void do_run() override;
|
||||
|
||||
private:
|
||||
std::string author_;
|
||||
std::string org_;
|
||||
std::string repo_;
|
||||
std::string branch_;
|
||||
fs::path where_;
|
||||
@@ -98,10 +158,12 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class decompresser : public process_runner
|
||||
class decompresser : public basic_process_runner
|
||||
{
|
||||
public:
|
||||
decompresser(fs::path file, fs::path where);
|
||||
decompresser();
|
||||
decompresser& file(const fs::path& file);
|
||||
decompresser& output(const fs::path& dir);
|
||||
|
||||
protected:
|
||||
void do_run() override;
|
||||
@@ -115,10 +177,13 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class patcher : public process_runner
|
||||
class patcher : public basic_process_runner
|
||||
{
|
||||
public:
|
||||
patcher(fs::path patch_dir, fs::path output_dir);
|
||||
patcher();
|
||||
|
||||
patcher& task(const std::string& name);
|
||||
patcher& root(const fs::path& dir);
|
||||
|
||||
protected:
|
||||
void do_run() override;
|
||||
@@ -129,70 +194,73 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class cmake_for_nmake : public process_runner
|
||||
class cmake : public basic_process_runner
|
||||
{
|
||||
public:
|
||||
cmake_for_nmake(fs::path root, std::string args={}, fs::path prefix={});
|
||||
static fs::path build_path();
|
||||
enum generators
|
||||
{
|
||||
vs = 0x01,
|
||||
nmake = 0x02
|
||||
};
|
||||
|
||||
cmake();
|
||||
|
||||
cmake& generator(generators g);
|
||||
cmake& root(const fs::path& p);
|
||||
cmake& prefix(const fs::path& s);
|
||||
cmake& def(const std::string& s);
|
||||
|
||||
fs::path result() const;
|
||||
|
||||
protected:
|
||||
void do_run() override;
|
||||
|
||||
private:
|
||||
fs::path root_;
|
||||
std::string args_;
|
||||
generators gen_;
|
||||
fs::path prefix_;
|
||||
fs::path output_;
|
||||
cmd cmd_;
|
||||
};
|
||||
|
||||
|
||||
class cmake_for_vs : public process_runner
|
||||
{
|
||||
public:
|
||||
cmake_for_vs(fs::path root, std::string args={}, fs::path prefix={});
|
||||
static fs::path build_path();
|
||||
|
||||
protected:
|
||||
void do_run() override;
|
||||
|
||||
private:
|
||||
fs::path root_;
|
||||
std::string args_;
|
||||
fs::path prefix_;
|
||||
};
|
||||
|
||||
|
||||
class jom : public process_runner
|
||||
class jom : public basic_process_runner
|
||||
{
|
||||
public:
|
||||
enum flags
|
||||
{
|
||||
default_flags = 0x00,
|
||||
noflags = 0x00,
|
||||
single_job = 0x01,
|
||||
accept_failure = 0x02
|
||||
};
|
||||
|
||||
jom(
|
||||
fs::path dir, std::string target, std::string args,
|
||||
flags f=default_flags);
|
||||
jom();
|
||||
|
||||
jom& path(const fs::path& p);
|
||||
jom& target(const std::string& s);
|
||||
jom& def(const std::string& s);
|
||||
jom& flag(flags f);
|
||||
|
||||
int result() const;
|
||||
|
||||
protected:
|
||||
void do_run() override;
|
||||
|
||||
private:
|
||||
fs::path dir_;
|
||||
cmd cmd_;
|
||||
std::string target_;
|
||||
std::string args_;
|
||||
flags flags_;
|
||||
};
|
||||
|
||||
|
||||
class msbuild : public process_runner
|
||||
class msbuild : public basic_process_runner
|
||||
{
|
||||
public:
|
||||
msbuild(
|
||||
fs::path sln,
|
||||
std::vector<std::string> projects,
|
||||
std::vector<std::string> params);
|
||||
msbuild();
|
||||
|
||||
msbuild& solution(const fs::path& sln);
|
||||
msbuild& projects(const std::vector<std::string>& names);
|
||||
msbuild& parameters(const std::vector<std::string>& params);
|
||||
|
||||
protected:
|
||||
void do_run() override;
|
||||
|
||||
+29
-11
@@ -189,6 +189,16 @@ std::string join(const std::vector<std::string>& v, const std::string& sep)
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
std::string redir_nul()
|
||||
{
|
||||
if (conf::verbose())
|
||||
return {};
|
||||
else
|
||||
return " > NUL";
|
||||
}
|
||||
|
||||
|
||||
cmd& cmd::name(const std::string& s)
|
||||
{
|
||||
name_ = s;
|
||||
@@ -214,40 +224,48 @@ const fs::path& cmd::cwd() const
|
||||
return cwd_;
|
||||
}
|
||||
|
||||
void cmd::add_arg(const std::string& name, const std::string& value, flags f)
|
||||
std::string cmd::string() const
|
||||
{
|
||||
if (flags_ & stdout_is_verbose)
|
||||
return s_ + redir_nul();
|
||||
else
|
||||
return s_;
|
||||
}
|
||||
|
||||
void cmd::add_arg(const std::string& k, const std::string& v, arg_flags f)
|
||||
{
|
||||
if ((f & quiet) && conf::verbose())
|
||||
return;
|
||||
|
||||
if (name.empty() && value.empty())
|
||||
if (k.empty() && v.empty())
|
||||
return;
|
||||
|
||||
if (name.empty())
|
||||
s_ += " " + value;
|
||||
else if (f & nospace)
|
||||
s_ += " " + name + value;
|
||||
if (k.empty())
|
||||
s_ += " " + v;
|
||||
else if ((f & nospace) || k.back() == '=')
|
||||
s_ += " " + k + v;
|
||||
else
|
||||
s_ += " " + name + " " + value;
|
||||
s_ += " " + k + " " + v;
|
||||
}
|
||||
|
||||
std::string cmd::arg_to_string(const char* s)
|
||||
{
|
||||
return std::string(" ") + s;
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string cmd::arg_to_string(const std::string& s)
|
||||
{
|
||||
return " " + s;
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string cmd::arg_to_string(const fs::path& p)
|
||||
{
|
||||
return " \"" + p.string() + "\"";
|
||||
return "\"" + p.string() + "\"";
|
||||
}
|
||||
|
||||
std::string cmd::arg_to_string(const url& u)
|
||||
{
|
||||
return " " + u.string();
|
||||
return u.string();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+16
-11
@@ -144,15 +144,22 @@ std::string join(const std::vector<std::string>& v, const std::string& sep);
|
||||
class cmd
|
||||
{
|
||||
public:
|
||||
enum flags
|
||||
enum arg_flags
|
||||
{
|
||||
noflags = 0x00,
|
||||
noargflags = 0x00,
|
||||
quiet = 0x01,
|
||||
nospace = 0x02
|
||||
};
|
||||
|
||||
cmd(const fs::path& exe)
|
||||
: exe_(exe.filename().string())
|
||||
enum flags
|
||||
{
|
||||
noflags = 0x00,
|
||||
stdout_is_verbose = 0x01
|
||||
};
|
||||
|
||||
|
||||
cmd(const fs::path& exe, flags f)
|
||||
: exe_(exe.filename().string()), flags_(f)
|
||||
{
|
||||
s_ += arg_to_string(exe);
|
||||
}
|
||||
@@ -164,31 +171,29 @@ public:
|
||||
const fs::path& cwd() const;
|
||||
|
||||
template <class T>
|
||||
cmd& arg(const T& value, flags f=noflags)
|
||||
cmd& arg(const T& value, arg_flags f=noargflags)
|
||||
{
|
||||
add_arg("", arg_to_string(value), f);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
cmd& arg(const std::string& name, const T& value, flags f=noflags)
|
||||
cmd& arg(const std::string& name, const T& value, arg_flags f=noargflags)
|
||||
{
|
||||
add_arg(name, arg_to_string(value), f);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::string& string() const
|
||||
{
|
||||
return s_;
|
||||
}
|
||||
std::string string() const;
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::string exe_;
|
||||
fs::path cwd_;
|
||||
std::string s_;
|
||||
flags flags_;
|
||||
|
||||
void add_arg(const std::string& name, const std::string& value, flags f);
|
||||
void add_arg(const std::string& k, const std::string& v, arg_flags f);
|
||||
|
||||
std::string arg_to_string(const char* s);
|
||||
std::string arg_to_string(const std::string& s);
|
||||
|
||||
Reference in New Issue
Block a user