From 930227440ccdd806527b34add0a3ea33fe274efe Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 6 May 2020 01:13:26 -0400 Subject: [PATCH] renamed third_party to tools, it doesn't matter that they're provided by mob in a third_party directory don't try to find tools on startup, let them fail when used because they can rely on paths that are not available yet, like vcvars --- src/conf.cpp | 135 +++++++++++++++------------------------- src/conf.h | 32 +++++----- src/env.cpp | 8 ++- src/env.h | 2 + src/main.cpp | 2 - src/tasks/openssl.cpp | 2 +- src/tools/cmake.cpp | 2 +- src/tools/extractor.cpp | 6 +- src/tools/git.cpp | 4 +- src/tools/jom.cpp | 3 +- src/tools/msbuild.cpp | 4 +- src/tools/patcher.cpp | 2 +- src/tools/tools.cpp | 7 +-- 13 files changed, 87 insertions(+), 122 deletions(-) diff --git a/src/conf.cpp b/src/conf.cpp index ed67108..d5a780a 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -27,13 +27,19 @@ static string_map g_options = {"mo_branch", "master"} }; -static path_map g_third_party = +static path_map g_tools = { - {"sevenz", ""}, - {"jom", ""}, - {"patch", ""}, - {"nuget", ""}, - {"vswhere", ""}, + {"sevenz", "7z.exe"}, + {"jom", "jom.exe"}, + {"patch", "patch.exe"}, + {"nuget", "nuget.exe"}, + {"vswhere", "vswhere.exe"}, + {"perl", "perl.exe"}, + {"msbuild", "msbuild.exe"}, + {"devenv", "devenv.exe"}, + {"cmake", "cmake.exe"}, + {"git", "git.exe"}, + {"vcvars", ""}, }; static bool_map g_prebuilt = @@ -86,7 +92,6 @@ static path_map g_paths = {"install_plugins", ""}, {"patches", ""}, {"vs", ""}, - {"vcvars", ""}, {"qt_install", ""}, {"qt_bin", ""}, {"pf_x86", ""}, @@ -112,16 +117,16 @@ const typename Map::mapped_type& get( } +const fs::path& tools::by_name(const std::string& name) +{ + return get("tool", g_tools, name); +} + const std::string& conf::by_name(const std::string& name) { return get("option", g_options, name); } -const fs::path& third_party::by_name(const std::string& s) -{ - return get("third party", g_third_party, s); -} - bool prebuilt::by_name(const std::string& s) { return get("prebuilt", g_prebuilt, s); @@ -150,13 +155,6 @@ bool conf::reextract() { return g_reextract; } bool conf::rebuild() { return g_rebuild; } -fs::path tool_paths::perl() { return "perl.exe"; } -fs::path tool_paths::msbuild() { return "msbuild.exe"; } -fs::path tool_paths::devenv() { return "devenv.exe"; } -fs::path tool_paths::cmake() { return "cmake.exe"; } -fs::path tool_paths::git() { return "git.exe"; } - - void conf_command_line_options(clipp::group& g) { g.push_back( @@ -441,7 +439,7 @@ fs::path find_temp_dir() fs::path find_vs() { auto p = process() - .binary(third_party::vswhere()) + .binary(tools::vswhere()) .arg("-prerelease") .arg("-version", versions::vs()) .arg("-property", "installationPath") @@ -465,20 +463,34 @@ fs::path find_vs() return path; } -fs::path find_vcvars() +bool try_vcvars(fs::path& bat) { - const auto vcvars = - paths::vs() / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat"; + if (!fs::exists(bat)) + return false; - if (!fs::exists(vcvars)) - { - gcx().bail_out(context::conf, - "can't find vcvars batch file at " + vcvars.string()); - } - - return vcvars; + bat = fs::canonical(fs::absolute(bat)); + return true; } +void find_vcvars() +{ + fs::path& bat = g_tools["vcvars"]; + + if (!bat.empty()) + { + if (!try_vcvars(bat)) + gcx().bail_out(context::conf, "vcvars not found " + bat.string()); + } + else + { + bat = paths::vs() / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat"; + + if (!try_vcvars(bat)) + gcx().bail_out(context::conf, "vcvars not found " + bat.string()); + } + + gcx().trace(context::conf, "using vcvars at " + bat.string()); +} template @@ -609,8 +621,8 @@ void parse_ini() if (lines[i] == "[options]") parse_section(i, lines, g_options); - else if (lines[i] == "[third-party]") - parse_section(i, lines, g_third_party); + else if (lines[i] == "[tools]") + parse_section(i, lines, g_tools); else if (lines[i] == "[prebuilt]") parse_section(i, lines, g_prebuilt); else if (lines[i] == "[versions]") @@ -640,46 +652,6 @@ void check_missing_options() } } - -void find_in_third_party(const std::string& k, const std::string& exe) -{ - auto itor = g_third_party.find(k); - - if (itor == g_third_party.end()) - gcx().bail_out(context::conf, "unknown third party key " + k); - - if (!itor->second.empty()) - { - if (fs::exists(itor->second)) - { - itor->second = fs::canonical(itor->second); - return; - } - else - { - gcx().bail_out(context::conf, - "third party " + itor->second.string() + " not found"); - } - } - - auto p = paths::third_party() / "bin" / exe; - - if (fs::exists(p)) - { - itor->second = fs::canonical(p); - return; - } - - p = find_in_path(exe); - if (fs::exists(p)) - { - itor->second = fs::canonical(p); - return; - } - - gcx().bail_out(context::conf, "can't find " + exe); -} - template void set_path_if_empty(const std::string& k, F&& f) { @@ -717,23 +689,17 @@ void set_path_if_empty(const std::string& k, F&& f) itor->second = fs::canonical(cp); } - void init_options() { parse_ini(); check_missing_options(); - set_path_if_empty("third_party", find_third_party_directory); + set_path_if_empty("third_party", find_third_party_directory); - find_in_third_party("sevenz", "7z.exe"); - find_in_third_party("jom", "jom.exe"); - find_in_third_party("patch", "patch.exe"); - find_in_third_party("vswhere", "vswhere.exe"); - find_in_third_party("nuget", "nuget.exe"); + this_env::prepend_to_path(paths::third_party() / "bin"); set_path_if_empty("vs", find_vs); - set_path_if_empty("vcvars", find_vcvars); set_path_if_empty("qt_install", find_qt); set_path_if_empty("pf_x86", find_program_files_x86); set_path_if_empty("pf_x64", find_program_files_x64); @@ -751,6 +717,7 @@ void init_options() set_path_if_empty("install_plugins", paths::install_bin() / "plugins"); set_path_if_empty("qt_bin", paths::qt_install() / "bin"); + find_vcvars(); validate_qt(); } @@ -781,10 +748,10 @@ void dump_options() opts.insert(manual_opts.begin(), manual_opts.end()); table("options", g_options); - string_map third_party; - for (auto&& [k, v] : g_third_party) - third_party[k] = v.string(); - table("third-party", third_party); + string_map tools; + for (auto&& [k, v] : g_tools) + tools[k] = v.string(); + table("tools", tools); string_map prebuilt; for (auto&& [k, v] : g_prebuilt) diff --git a/src/conf.h b/src/conf.h index 4bf05aa..438a4f4 100644 --- a/src/conf.h +++ b/src/conf.h @@ -10,13 +10,21 @@ class bad_conf {}; static decltype(auto) NAME() { return by_name(#NAME); } -struct tool_paths +struct tools { - static fs::path perl(); - static fs::path msbuild(); - static fs::path devenv(); - static fs::path cmake(); - static fs::path git(); + static const fs::path& by_name(const std::string& s); + + VALUE(perl); + VALUE(msbuild); + VALUE(devenv); + VALUE(cmake); + VALUE(git); + VALUE(sevenz); + VALUE(jom); + VALUE(patch); + VALUE(nuget); + VALUE(vswhere); + VALUE(vcvars); }; struct conf @@ -39,17 +47,6 @@ struct conf VALUE(mo_branch); }; -struct third_party -{ - static const fs::path& by_name(const std::string& s); - - VALUE(sevenz); - VALUE(jom); - VALUE(patch); - VALUE(nuget); - VALUE(vswhere); -}; - struct prebuilt { static bool by_name(const std::string& s); @@ -109,7 +106,6 @@ struct paths VALUE(install_plugins); VALUE(vs); - VALUE(vcvars); VALUE(qt_install); VALUE(qt_bin); VALUE(pf_x86); diff --git a/src/env.cpp b/src/env.cpp index fd6fffb..f9eb768 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -33,7 +33,7 @@ env get_vcvars_env(arch a) // "vcvarsall.bat" amd64 && set > temp_file std::string cmd = - "\"" + paths::vcvars().string() + "\" " + arch_s + + "\"" + tools::vcvars().string() + "\" " + arch_s + " && set > \"" + tmp.string() + "\""; process::raw(gcx(), cmd) @@ -223,6 +223,12 @@ void this_env::set(const std::string& k, const std::string& v, env::flags f) } } +void this_env::prepend_to_path(const fs::path& p) +{ + gcx().trace(context::generic, "prepending to PATH: " + p.string()); + set("PATH", p.string() + ";", env::prepend); +} + std::string this_env::get(const std::string& name) { const std::size_t buffer_size = GetEnvironmentVariableA( diff --git a/src/env.h b/src/env.h index 9d3d55d..03556d7 100644 --- a/src/env.h +++ b/src/env.h @@ -47,6 +47,8 @@ struct this_env const std::string& v, env::flags f=env::replace); + static void prepend_to_path(const fs::path& p); + static env get(); static std::string get(const std::string& k); }; diff --git a/src/main.cpp b/src/main.cpp index 4a23e58..1277a9e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -99,8 +99,6 @@ int run(int argc, char** argv) curl_init curl; - //this_env::set("PATH", paths::third_party().string() + ";", env::prepend); - add_task(); add_task(); add_task(); diff --git a/src/tasks/openssl.cpp b/src/tasks/openssl.cpp index 4b30b6d..3951b0a 100644 --- a/src/tasks/openssl.cpp +++ b/src/tasks/openssl.cpp @@ -51,7 +51,7 @@ void openssl::do_build_and_install() void openssl::configure() { run_tool(process_runner(process() - .binary(tool_paths::perl()) + .binary(tools::perl()) .arg("Configure") .arg("--openssldir=", build_path()) .arg("--prefix=", build_path()) diff --git a/src/tools/cmake.cpp b/src/tools/cmake.cpp index 272d00c..c69ece5 100644 --- a/src/tools/cmake.cpp +++ b/src/tools/cmake.cpp @@ -8,7 +8,7 @@ cmake::cmake() : basic_process_runner("cmake"), gen_(jom), arch_(arch::def) { process_ - .binary(tool_paths::cmake()); + .binary(tools::cmake()); } cmake& cmake::generator(generators g) diff --git a/src/tools/extractor.cpp b/src/tools/extractor.cpp index 098e18d..e8eae77 100644 --- a/src/tools/extractor.cpp +++ b/src/tools/extractor.cpp @@ -76,12 +76,12 @@ void extractor::do_run() cx_->trace(context::generic, "this is a tar.gz, piping"); auto extract_tar = process() - .binary(third_party::sevenz()) + .binary(tools::sevenz()) .arg("x") .arg("-so", file_); auto extract_gz = process() - .binary(third_party::sevenz()) + .binary(tools::sevenz()) .arg("x") .arg("-aoa") .arg("-si") @@ -93,7 +93,7 @@ void extractor::do_run() else { process_ = process() - .binary(third_party::sevenz()) + .binary(tools::sevenz()) .arg("x") .arg("-aoa") .arg("-bd") diff --git a/src/tools/git.cpp b/src/tools/git.cpp index faf3014..aea3385 100644 --- a/src/tools/git.cpp +++ b/src/tools/git.cpp @@ -56,7 +56,7 @@ void git_clone::do_run() void git_clone::clone() { process_ = process() - .binary(tool_paths::git()) + .binary(tools::git()) .stderr_level(context::level::trace) .arg("clone") .arg("--recurse-submodules") @@ -73,7 +73,7 @@ void git_clone::clone() void git_clone::pull() { process_ = process() - .binary(tool_paths::git()) + .binary(tools::git()) .stderr_level(context::level::trace) .arg("pull") .arg("--recurse-submodules") diff --git a/src/tools/jom.cpp b/src/tools/jom.cpp index edbe309..cdc7e03 100644 --- a/src/tools/jom.cpp +++ b/src/tools/jom.cpp @@ -8,8 +8,6 @@ namespace mob jom::jom() : basic_process_runner("jom"), arch_(arch::def) { - process_ - .binary(third_party::jom()); } jom& jom::path(const fs::path& p) @@ -57,6 +55,7 @@ void jom::do_run() } process_ + .binary(tools::jom()) .stderr_filter([](process::filter& f) { if (f.line.find("empower your cores") != std::string::npos) diff --git a/src/tools/msbuild.cpp b/src/tools/msbuild.cpp index 2f722b6..eee5ce8 100644 --- a/src/tools/msbuild.cpp +++ b/src/tools/msbuild.cpp @@ -8,8 +8,6 @@ namespace mob msbuild::msbuild() : basic_process_runner("msbuild"), config_("Release"), arch_(arch::def) { - process_ - .binary(tool_paths::msbuild()); } msbuild& msbuild::solution(const fs::path& sln) @@ -77,8 +75,8 @@ void msbuild::do_run() plat = platform_; } - process_ + .binary(tools::msbuild()) .arg("-nologo") .arg("-maxCpuCount") .arg("-property:UseMultiToolTask=true") diff --git a/src/tools/patcher.cpp b/src/tools/patcher.cpp index 4fff938..b9ea5b4 100644 --- a/src/tools/patcher.cpp +++ b/src/tools/patcher.cpp @@ -86,7 +86,7 @@ void patcher::do_run() void patcher::do_patch(const fs::path& patch_file) { const auto base = process() - .binary(third_party::patch()) + .binary(tools::patch()) .arg("--read-only", "ignore") .arg("--strip", "0") .arg("--directory", output_) diff --git a/src/tools/tools.cpp b/src/tools/tools.cpp index 6ad84a4..ddd9636 100644 --- a/src/tools/tools.cpp +++ b/src/tools/tools.cpp @@ -63,9 +63,6 @@ bool tool::interrupted() const devenv_upgrade::devenv_upgrade(fs::path sln) : basic_process_runner("upgrade project"), sln_(std::move(sln)) { - process_ - .binary(tool_paths::devenv()) - .env(env::vs(arch::x64)); } void devenv_upgrade::do_run() @@ -77,6 +74,8 @@ void devenv_upgrade::do_run() } process_ + .binary(tools::devenv()) + .env(env::vs(arch::x64)) .arg("/upgrade") .arg(sln_); @@ -88,7 +87,7 @@ nuget::nuget(fs::path sln) : basic_process_runner("nuget"), sln_(std::move(sln)) { process_ - .binary(third_party::nuget()) + .binary(tools::nuget()) .arg("restore") .arg(sln_) .cwd(sln_.parent_path());