From 1876b9168fb06ae21b974ff90e4ea0e0066ef562 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 9 Nov 2020 04:05:38 -0500 Subject: [PATCH] some refactoring in release_command::do_official() comments --- src/cmd/commands.cpp | 10 +++--- src/cmd/commands.h | 4 ++- src/cmd/git.cpp | 3 ++ src/cmd/release.cpp | 74 +++++++++++++++++++++++++++--------------- vs/mob.vcxproj.filters | 2 +- 5 files changed, 58 insertions(+), 35 deletions(-) diff --git a/src/cmd/commands.cpp b/src/cmd/commands.cpp index be09a0f..c2bd002 100644 --- a/src/cmd/commands.cpp +++ b/src/cmd/commands.cpp @@ -27,13 +27,12 @@ void set_sigint_handler() std::string version() { - return "mob 4.0"; + return "mob whatever-is-on-master"; } void help(const clipp::group& g, const std::string& more) { -#pragma warning(suppress: 4548) auto usage_df = clipp::doc_formatting() .first_column(4) .doc_column(30); @@ -47,16 +46,15 @@ void help(const clipp::group& g, const std::string& more) << "\n\n" << "Options:\n" << clipp::documentation(g, options_df) - << "\n"; - - u8cout << "\nTo use global options with command options, ensure command options are together, with no global options in the middle.\n"; + << "\n\n" + << "To use global options with command options, make sure command " + << "options are together, with no global options in the middle.\n"; if (!more.empty()) u8cout << "\n" << more << "\n"; } - command::common_options command::common; command::command(flags f) diff --git a/src/cmd/commands.h b/src/cmd/commands.h index 5de4207..0c45da4 100644 --- a/src/cmd/commands.h +++ b/src/cmd/commands.h @@ -75,7 +75,7 @@ protected: // this command needs the ini loaded before running requires_options = 0x01, - // this command handles sigint by itself + // this command does not handle sigint by itself, run() will hook it handle_sigint = 0x02 }; @@ -306,6 +306,8 @@ private: int do_official(); void prepare(); + void check_repos_for_branch(); + bool check_clean_prefix(); fs::path make_filename(const std::string& what) const; diff --git a/src/cmd/git.cpp b/src/cmd/git.cpp index 524964f..667da73 100644 --- a/src/cmd/git.cpp +++ b/src/cmd/git.cpp @@ -217,15 +217,18 @@ std::vector git_command::get_repos() const { std::vector v; + // usvfs if (fs::exists(usvfs::source_path())) v.push_back(usvfs::source_path()); + // ncc if (fs::exists(ncc::source_path())) v.push_back(ncc::source_path()); const auto super = modorganizer::super_path(); + // all directories in super except for those starting with a dot if (fs::exists(super)) { for (auto e : fs::directory_iterator(super)) diff --git a/src/cmd/release.cpp b/src/cmd/release.cpp index cbc6405..5cec128 100644 --- a/src/cmd/release.cpp +++ b/src/cmd/release.cpp @@ -75,6 +75,7 @@ void release_command::make_src() modorganizer::super_path()); } + // build list list walk_dir(modorganizer::super_path(), files, ignore_re, total_size); // should be below 20MB @@ -112,6 +113,8 @@ void release_command::walk_dir( const fs::path& dir, std::vector& files, const std::vector& ignore_re, std::size_t& total_size) { + // adds all files that are not in the ignore list to `files`, recursive + for (auto e : fs::directory_iterator(dir)) { const auto p = e.path(); @@ -234,6 +237,8 @@ void release_command::convert_cl_to_conf() if (mode_ == modes::official) { + // force enable translations, installer and tx + common.options.push_back("task/mo_branch=" + branch_); common.options.push_back("translations:task/enabled=true"); common.options.push_back("installer:task/enabled=true"); @@ -289,6 +294,28 @@ int release_command::do_official() { set_sigint_handler(); + // make sure the given branch exists in all repos, this avoids failure + // much later on in the process; throws on failure + check_repos_for_branch(); + + // if the prefix exists, asks the user to delete it + if (!check_clean_prefix()) + return 1; + + run_all_tasks(); + build_command::terminate_msbuild(); + + prepare(); + make_bin(); + make_pdbs(); + make_src(); + make_installer(); + + return 0; +} + +void release_command::check_repos_for_branch() +{ u8cout << "checking repos for branch " << branch_ << "...\n"; thread_pool tp; @@ -323,42 +350,33 @@ int release_command::do_official() "repos that don't have it, or disable tasks with " "`-s TASKNAME:task/enabled=false`"); } +} +bool release_command::check_clean_prefix() +{ + if (!fs::exists(paths::prefix())) + return true; - if (fs::exists(paths::prefix())) + u8cout + << "prefix " << path_to_utf8(paths::prefix()) << " already exists\n" + << "delete? [Y/n] "; + + std::wstring s; + std::getline(std::wcin, s); + + if (s == L"" || s == L"y" || s == L"Y") { - u8cout - << "prefix " << path_to_utf8(paths::prefix()) << " already exists\n" - << "delete? [Y/n] "; - - std::wstring s; - std::getline(std::wcin, s); - - if (s == L"" || s == L"y" || s == L"Y") - { - build_command::terminate_msbuild(); - op::delete_directory(gcx(), paths::prefix()); - } - else - { - return 1; - } + build_command::terminate_msbuild(); + op::delete_directory(gcx(), paths::prefix()); + return true; } - run_all_tasks(); - build_command::terminate_msbuild(); - - prepare(); - make_bin(); - make_pdbs(); - make_src(); - make_installer(); - - return 0; + return false; } void release_command::prepare() { + // finding rc file rc_path_ = fs::path(utf8_to_utf16(utf8_rc_path_)); if (rc_path_.empty()) { @@ -366,6 +384,7 @@ void release_command::prepare() modorganizer::super_path() / "modorganizer" / "src" / "version.rc"; } + // getting version from rc or exe if (version_.empty()) { if (version_rc_) @@ -374,6 +393,7 @@ void release_command::prepare() version_ = version_from_exe(); } + // finding output path out_ = fs::path(utf8_to_utf16(utf8out_)); if (out_.empty()) out_ = paths::prefix() / "releases" / version_; diff --git a/vs/mob.vcxproj.filters b/vs/mob.vcxproj.filters index 64394d7..8660b42 100644 --- a/vs/mob.vcxproj.filters +++ b/vs/mob.vcxproj.filters @@ -246,7 +246,7 @@ src\cmd - src\cmd + src\utility \ No newline at end of file