From 2f4cd5627631cc46d293de63268e6729241eee3d Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 18 Nov 2020 00:42:43 -0500 Subject: [PATCH] moved tasks to tasks namespace added python tool --- src/cmd/cmake.cpp | 3 ++- src/cmd/commands.h | 10 ++++--- src/cmd/git.cpp | 10 +++---- src/cmd/pr.cpp | 25 ++++++++--------- src/cmd/release.cpp | 17 +++++++----- src/cmd/tx.cpp | 2 +- src/core/conf.cpp | 2 +- src/core/context.h | 2 +- src/main.cpp | 4 ++- src/tasks/boost.cpp | 2 +- src/tasks/boost_di.cpp | 2 +- src/tasks/bzip2.cpp | 2 +- src/tasks/explorerpp.cpp | 2 +- src/tasks/fmt.cpp | 2 +- src/tasks/gtest.cpp | 2 +- src/tasks/installer.cpp | 2 +- src/tasks/libbsarch.cpp | 2 +- src/tasks/libffi.cpp | 2 +- src/tasks/libloot.cpp | 2 +- src/tasks/licenses.cpp | 2 +- src/tasks/lz4.cpp | 2 +- src/tasks/modorganizer.cpp | 2 +- src/tasks/ncc.cpp | 2 +- src/tasks/nmm.cpp | 2 +- src/tasks/openssl.cpp | 2 +- src/tasks/pyqt.cpp | 2 +- src/tasks/python.cpp | 2 +- src/tasks/sevenz.cpp | 2 +- src/tasks/sip.cpp | 22 +++------------ src/tasks/spdlog.cpp | 2 +- src/tasks/stylesheets.cpp | 2 +- src/tasks/tasks.h | 3 +-- src/tasks/translations.cpp | 2 +- src/tasks/usvfs.cpp | 2 +- src/tasks/zlib.cpp | 2 +- src/tools/tools.cpp | 55 ++++++++++++++++++++++++++++++++++---- src/tools/tools.h | 17 ++++++++++++ 37 files changed, 139 insertions(+), 81 deletions(-) diff --git a/src/cmd/cmake.cpp b/src/cmd/cmake.cpp index c42c1e9..4a64235 100644 --- a/src/cmd/cmake.cpp +++ b/src/cmd/cmake.cpp @@ -54,7 +54,8 @@ clipp::group cmake_command::do_group() int cmake_command::do_run() { - auto t = modorganizer::create_cmake_tool(fs::path(utf8_to_utf16(path_))); + auto t = tasks::modorganizer::create_cmake_tool( + fs::path(utf8_to_utf16(path_))); t.generator(gen_); t.cmd(cmd_); diff --git a/src/cmd/commands.h b/src/cmd/commands.h index 69879b3..0c3a021 100644 --- a/src/cmd/commands.h +++ b/src/cmd/commands.h @@ -2,11 +2,15 @@ #include "../utility/enum.h" +namespace mob::tasks +{ + class modorganizer; +} + namespace mob { class task; -class modorganizer; class url; // base class for all commands @@ -258,10 +262,10 @@ private: std::string pr_; std::string github_token_; - std::pair parse_pr( + std::pair parse_pr( const std::string& pr) const; - pr_info get_pr_info(const modorganizer* task, const std::string& pr); + pr_info get_pr_info(const tasks::modorganizer* task, const std::string& pr); std::vector get_matching_prs( const std::string& repo_pr); diff --git a/src/cmd/git.cpp b/src/cmd/git.cpp index 85f5abe..9770f1b 100644 --- a/src/cmd/git.cpp +++ b/src/cmd/git.cpp @@ -255,15 +255,15 @@ std::vector git_command::get_repos() const std::vector v; // usvfs - if (fs::exists(usvfs::source_path())) - v.push_back(usvfs::source_path()); + if (fs::exists(tasks::usvfs::source_path())) + v.push_back(tasks::usvfs::source_path()); // ncc - if (fs::exists(ncc::source_path())) - v.push_back(ncc::source_path()); + if (fs::exists(tasks::ncc::source_path())) + v.push_back(tasks::ncc::source_path()); - const auto super = modorganizer::super_path(); + const auto super = tasks::modorganizer::super_path(); // all directories in super except for those starting with a dot if (fs::exists(super)) diff --git a/src/cmd/pr.cpp b/src/cmd/pr.cpp index b71f7af..37108f0 100644 --- a/src/cmd/pr.cpp +++ b/src/cmd/pr.cpp @@ -79,7 +79,7 @@ int pr_command::do_run() return 1; } -std::pair pr_command::parse_pr( +std::pair pr_command::parse_pr( const std::string& pr) const { if (pr.empty()) @@ -99,7 +99,7 @@ std::pair pr_command::parse_pr( if (!task) return {}; - const auto* mo_task = dynamic_cast(task); + const auto* mo_task = dynamic_cast(task); if (!mo_task) { u8cerr << "only modorganizer tasks are supported\n"; @@ -123,7 +123,7 @@ int pr_command::pull() { for (auto&& pr : okay_prs) { - const auto* task = dynamic_cast( + const auto* task = dynamic_cast( find_one_task(pr.repo)); if (!task) @@ -136,7 +136,7 @@ int pr_command::pull() git::fetch( task->this_source_path(), task->git_url().string(), - ::fmt::format("pull/{}/head", pr.number)); + fmt::format("pull/{}/head", pr.number)); git::checkout(task->this_source_path(), "FETCH_HEAD"); } @@ -171,7 +171,7 @@ int pr_command::revert() { for (auto&& pr : okay_prs) { - const auto* task = dynamic_cast( + const auto* task = dynamic_cast( find_one_task(pr.repo)); if (!task) @@ -229,11 +229,11 @@ std::vector pr_command::search_prs( "https://api.github.com/search/issues?per_page=100&q=" "is:pr+org:{org:}+author:{author:}+is:open+head:{branch:}"; - const auto search_url = ::fmt::format( + const auto search_url = fmt::format( pattern, - ::fmt::arg("org", org), - ::fmt::arg("author", author), - ::fmt::arg("branch", branch)); + fmt::arg("org", org), + fmt::arg("author", author), + fmt::arg("branch", branch)); u8cout << "search url is " << search_url << "\n"; @@ -292,7 +292,7 @@ std::vector pr_command::search_prs( } pr_command::pr_info pr_command::get_pr_info( - const modorganizer* task, const std::string& pr) + const tasks::modorganizer* task, const std::string& pr) { nlohmann::json json; @@ -302,7 +302,7 @@ pr_command::pr_info pr_command::get_pr_info( return {}; } - const url u(::fmt::format( + const url u(fmt::format( "https://api.github.com/repos/{}/{}/pulls/{}", task->org(), task->repo(), pr)); @@ -359,7 +359,8 @@ std::vector pr_command::validate_prs( } else { - const auto* mo_task = dynamic_cast(tasks[0]); + const auto* mo_task = + dynamic_cast(tasks[0]); if (!mo_task) { diff --git a/src/cmd/release.cpp b/src/cmd/release.cpp index 5cec128..39c519f 100644 --- a/src/cmd/release.cpp +++ b/src/cmd/release.cpp @@ -68,15 +68,15 @@ void release_command::make_src() std::vector files; std::size_t total_size = 0; - if (!fs::exists(modorganizer::super_path())) + if (!fs::exists(tasks::modorganizer::super_path())) { gcx().bail_out(context::generic, "modorganizer super path not found: {}", - modorganizer::super_path()); + tasks::modorganizer::super_path()); } // build list list - walk_dir(modorganizer::super_path(), files, ignore_re, total_size); + walk_dir(tasks::modorganizer::super_path(), files, ignore_re, total_size); // should be below 20MB const std::size_t max_expected_size = 20 * 1024 * 1024; @@ -95,7 +95,7 @@ void release_command::make_src() } op::archive_from_files(gcx(), - files, modorganizer::super_path(), out); + files, tasks::modorganizer::super_path(), out); } void release_command::make_installer() @@ -328,7 +328,7 @@ void release_command::check_repos_for_branch() tp.add([this, t, &failed] { - const auto* o = dynamic_cast(t); + const auto* o = dynamic_cast(t); if (!git::branch_exists(o->git_url(), branch_)) { @@ -381,7 +381,10 @@ void release_command::prepare() if (rc_path_.empty()) { rc_path_ = - modorganizer::super_path() / "modorganizer" / "src" / "version.rc"; + tasks::modorganizer::super_path() + / "modorganizer" + / "src" + / "version.rc"; } // getting version from rc or exe @@ -484,7 +487,7 @@ std::string release_command::version_from_exe() const // using the first language in the list to get FileVersion const auto* lcp = static_cast(value_pointer); - const auto sub_block = ::fmt::format( + const auto sub_block = fmt::format( L"\\StringFileInfo\\{:04x}{:04x}\\FileVersion", lcp->wLanguage, lcp->wCodePage); diff --git a/src/cmd/tx.cpp b/src/cmd/tx.cpp index 95ba31d..f61837a 100644 --- a/src/cmd/tx.cpp +++ b/src/cmd/tx.cpp @@ -182,7 +182,7 @@ void tx_command::do_build() if (fs::exists(root / ".tx") && fs::exists(root / "translations")) root = root / "translations"; - translations::projects ps(root); + tasks::translations::projects ps(root); fs::path dest = dest_; op::create_directories(gcx(), dest, op::unsafe); diff --git a/src/core/conf.cpp b/src/core/conf.cpp index 6e3c204..25cf361 100644 --- a/src/core/conf.cpp +++ b/src/core/conf.cpp @@ -1051,7 +1051,7 @@ fs::path find_iscc() for (int v : {5, 6, 7, 8}) { - const fs::path inno = ::fmt::format("inno setup {}", v); + const fs::path inno = fmt::format("inno setup {}", v); for (fs::path pf : {paths::pf_x86(), paths::pf_x64()}) { diff --git a/src/core/context.h b/src/core/context.h index d3f2c90..e81e171 100644 --- a/src/core/context.h +++ b/src/core/context.h @@ -200,7 +200,7 @@ private: try { - const std::string utf8 = ::fmt::format( + const std::string utf8 = fmt::format( f, details::converter>::convert( std::forward(args))...); diff --git a/src/main.cpp b/src/main.cpp index 3367805..a848325 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,8 @@ namespace mob void add_tasks() { + using namespace tasks; + // add new tasks here // // top level tasks are run sequentially, tasks added to a parallel_tasks will @@ -41,7 +43,7 @@ void add_tasks() .add_task(); add_task(false) - .add_task() + .add_task() .add_task() .add_task() .add_task() diff --git a/src/tasks/boost.cpp b/src/tasks/boost.cpp index e77f5cd..c0eb930 100644 --- a/src/tasks/boost.cpp +++ b/src/tasks/boost.cpp @@ -2,7 +2,7 @@ #include "tasks.h" #include "../core/process.h" -namespace mob +namespace mob::tasks { boost::boost() diff --git a/src/tasks/boost_di.cpp b/src/tasks/boost_di.cpp index d6b7140..02a8660 100644 --- a/src/tasks/boost_di.cpp +++ b/src/tasks/boost_di.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { boost_di::boost_di() diff --git a/src/tasks/bzip2.cpp b/src/tasks/bzip2.cpp index 33a6ef6..89b1e5a 100644 --- a/src/tasks/bzip2.cpp +++ b/src/tasks/bzip2.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { bzip2::bzip2() diff --git a/src/tasks/explorerpp.cpp b/src/tasks/explorerpp.cpp index 56cc9ab..43274ff 100644 --- a/src/tasks/explorerpp.cpp +++ b/src/tasks/explorerpp.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { explorerpp::explorerpp() diff --git a/src/tasks/fmt.cpp b/src/tasks/fmt.cpp index c3b038b..15db151 100644 --- a/src/tasks/fmt.cpp +++ b/src/tasks/fmt.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { fmt::fmt() diff --git a/src/tasks/gtest.cpp b/src/tasks/gtest.cpp index b107e48..2cc8f6c 100644 --- a/src/tasks/gtest.cpp +++ b/src/tasks/gtest.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { gtest::gtest() diff --git a/src/tasks/installer.cpp b/src/tasks/installer.cpp index 51ea489..66b2a84 100644 --- a/src/tasks/installer.cpp +++ b/src/tasks/installer.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { installer::installer() diff --git a/src/tasks/libbsarch.cpp b/src/tasks/libbsarch.cpp index 5eb0a90..5df4b9d 100644 --- a/src/tasks/libbsarch.cpp +++ b/src/tasks/libbsarch.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { libbsarch::libbsarch() diff --git a/src/tasks/libffi.cpp b/src/tasks/libffi.cpp index d55dccc..5817832 100644 --- a/src/tasks/libffi.cpp +++ b/src/tasks/libffi.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { libffi::libffi() diff --git a/src/tasks/libloot.cpp b/src/tasks/libloot.cpp index c9e4050..c758d76 100644 --- a/src/tasks/libloot.cpp +++ b/src/tasks/libloot.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { libloot::libloot() diff --git a/src/tasks/licenses.cpp b/src/tasks/licenses.cpp index e94ded9..6279d1d 100644 --- a/src/tasks/licenses.cpp +++ b/src/tasks/licenses.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { licenses::licenses() diff --git a/src/tasks/lz4.cpp b/src/tasks/lz4.cpp index 1d2038e..56de22f 100644 --- a/src/tasks/lz4.cpp +++ b/src/tasks/lz4.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { lz4::lz4() diff --git a/src/tasks/modorganizer.cpp b/src/tasks/modorganizer.cpp index 01bf060..44ed7f0 100644 --- a/src/tasks/modorganizer.cpp +++ b/src/tasks/modorganizer.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { static std::mutex g_super_mutex; diff --git a/src/tasks/ncc.cpp b/src/tasks/ncc.cpp index 4af1302..44260cd 100644 --- a/src/tasks/ncc.cpp +++ b/src/tasks/ncc.cpp @@ -2,7 +2,7 @@ #include "tasks.h" #include "../core/process.h" -namespace mob +namespace mob::tasks { ncc::ncc() diff --git a/src/tasks/nmm.cpp b/src/tasks/nmm.cpp index e25d9e3..abf869f 100644 --- a/src/tasks/nmm.cpp +++ b/src/tasks/nmm.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { nmm::nmm() diff --git a/src/tasks/openssl.cpp b/src/tasks/openssl.cpp index 5c85b3e..68fb97d 100644 --- a/src/tasks/openssl.cpp +++ b/src/tasks/openssl.cpp @@ -2,7 +2,7 @@ #include "tasks.h" #include "../core/process.h" -namespace mob +namespace mob::tasks { openssl::openssl() diff --git a/src/tasks/pyqt.cpp b/src/tasks/pyqt.cpp index 1489a80..e1426ec 100644 --- a/src/tasks/pyqt.cpp +++ b/src/tasks/pyqt.cpp @@ -2,7 +2,7 @@ #include "tasks.h" #include "../core/process.h" -namespace mob +namespace mob::tasks { pyqt::pyqt() diff --git a/src/tasks/python.cpp b/src/tasks/python.cpp index 7628a5c..2daa204 100644 --- a/src/tasks/python.cpp +++ b/src/tasks/python.cpp @@ -2,7 +2,7 @@ #include "tasks.h" #include "../core/process.h" -namespace mob +namespace mob::tasks { python::python() diff --git a/src/tasks/sevenz.cpp b/src/tasks/sevenz.cpp index 54e678b..9803734 100644 --- a/src/tasks/sevenz.cpp +++ b/src/tasks/sevenz.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { sevenz::sevenz() diff --git a/src/tasks/sip.cpp b/src/tasks/sip.cpp index 8962614..3503f30 100644 --- a/src/tasks/sip.cpp +++ b/src/tasks/sip.cpp @@ -2,7 +2,7 @@ #include "tasks.h" #include "../core/process.h" -namespace mob +namespace mob::tasks { sip::sip() @@ -143,24 +143,10 @@ void sip::generate() } } - run_tool(process_runner(process() - .binary(python::python_exe()) - .chcp(65001) - .stdout_encoding(encodings::utf8) - .stderr_encoding(encodings::utf8) - .stderr_filter([&](process::filter& f) - { - if (f.line.find("zip_safe flag not set") != std::string::npos) - f.lv = context::level::trace; - else if (f.line.find("module references __file__") != std::string::npos) - f.lv = context::level::trace; - }) - .arg("-X", "utf8") + run_tool(mob::python() + .root(source_path()) .arg("setup.py") - .arg("install") - .cwd(source_path()) - .env(this_env::get() - .set("PYTHONUTF8", "1")))); + .arg("install")); const std::string filename = "sip-module-script.py"; diff --git a/src/tasks/spdlog.cpp b/src/tasks/spdlog.cpp index c45f83d..4cddee1 100644 --- a/src/tasks/spdlog.cpp +++ b/src/tasks/spdlog.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { spdlog::spdlog() diff --git a/src/tasks/stylesheets.cpp b/src/tasks/stylesheets.cpp index 18fd257..7704d71 100644 --- a/src/tasks/stylesheets.cpp +++ b/src/tasks/stylesheets.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { stylesheets::stylesheets() diff --git a/src/tasks/tasks.h b/src/tasks/tasks.h index 0f3c159..33b7b8f 100644 --- a/src/tasks/tasks.h +++ b/src/tasks/tasks.h @@ -6,7 +6,7 @@ #include "../core/conf.h" #include "../core/op.h" -namespace mob +namespace mob::tasks { class boost : public basic_task @@ -327,7 +327,6 @@ private: cmake create_this_cmake_tool(cmake::ops o=cmake::generate); msbuild create_this_msbuild_tool(msbuild::ops o=msbuild::build); void initialize_super(const fs::path& super_root); - }; diff --git a/src/tasks/translations.cpp b/src/tasks/translations.cpp index e61191e..0bfd1de 100644 --- a/src/tasks/translations.cpp +++ b/src/tasks/translations.cpp @@ -3,7 +3,7 @@ #include "../core/env.h" #include "../utility/threading.h" -namespace mob +namespace mob::tasks { translations::projects::lang::lang(std::string n) diff --git a/src/tasks/usvfs.cpp b/src/tasks/usvfs.cpp index f7bd904..b576db4 100644 --- a/src/tasks/usvfs.cpp +++ b/src/tasks/usvfs.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { usvfs::usvfs() diff --git a/src/tasks/zlib.cpp b/src/tasks/zlib.cpp index 52271a5..fbf134e 100644 --- a/src/tasks/zlib.cpp +++ b/src/tasks/zlib.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "tasks.h" -namespace mob +namespace mob::tasks { zlib::zlib() diff --git a/src/tools/tools.cpp b/src/tools/tools.cpp index b6f0242..78d8f4c 100644 --- a/src/tools/tools.cpp +++ b/src/tools/tools.cpp @@ -229,6 +229,51 @@ void nuget::do_run() execute_and_join(); } +python::python() + : basic_process_runner("python") +{ +} + +python& python::root(const fs::path& p) +{ + root_ = p; + return *this; +} + +python& python::arg(const std::string& s) +{ + args_.push_back(s); + return *this; +} + +void python::do_run() +{ + auto p = process() + .binary(tasks::python::python_exe()) + .chcp(65001) + .stdout_encoding(encodings::utf8) + .stderr_encoding(encodings::utf8) + .stderr_filter([&](process::filter& f) + { + if (f.line.find("zip_safe flag not set") != std::string::npos) + f.lv = context::level::trace; + else if (f.line.find("module references __file__") != std::string::npos) + f.lv = context::level::trace; + }) + .arg("-X", "utf8"); + + for (auto&& a : args_) + p.arg(a); + + p + .cwd(root_) + .env(this_env::get() + .set("PYTHONUTF8", "1")); + + set_process(p); + execute_and_join(); +} + pip::pip(ops op) : basic_process_runner("pip"), op_(op) @@ -293,7 +338,7 @@ void pip::do_ensure() else if (f.line.find("Consider adding this directory")) f.lv = context::level::debug; }) - .binary(python::python_exe()) + .binary(tasks::python::python_exe()) .arg("-m", "ensurepip")); execute_and_join(); @@ -301,7 +346,7 @@ void pip::do_ensure() // upgrade set_process(process() - .binary(python::python_exe()) + .binary(tasks::python::python_exe()) .arg("-m pip") .arg("install") .arg("--no-warn-script-location") @@ -312,7 +357,7 @@ void pip::do_ensure() // ssl errors while downloading through python without certifi set_process(process() - .binary(python::python_exe()) + .binary(tasks::python::python_exe()) .arg("-m pip") .arg("install") .arg("--no-warn-script-location") @@ -324,7 +369,7 @@ void pip::do_ensure() void pip::do_install() { auto p = process() - .binary(python::python_exe()) + .binary(tasks::python::python_exe()) .chcp(65001) .stdout_encoding(encodings::utf8) .stderr_encoding(encodings::utf8) @@ -350,7 +395,7 @@ void pip::do_install() void pip::do_download() { set_process(process() - .binary(python::python_exe()) + .binary(tasks::python::python_exe()) .chcp(65001) .stdout_encoding(encodings::utf8) .stderr_encoding(encodings::utf8) diff --git a/src/tools/tools.h b/src/tools/tools.h index 8950a18..34eedc3 100644 --- a/src/tools/tools.h +++ b/src/tools/tools.h @@ -590,6 +590,23 @@ private: }; +class python : public basic_process_runner +{ +public: + python(); + + python& root(const fs::path& p); + python& arg(const std::string& s); + +protected: + void do_run() override; + +private: + fs::path root_; + std::vector args_; +}; + + class pip : public basic_process_runner { public: