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
This commit is contained in:
isanae
2020-05-06 01:13:26 -04:00
parent facf4c32f3
commit 930227440c
13 changed files with 87 additions and 122 deletions
+51 -84
View File
@@ -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 <class T>
@@ -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 <class F>
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)
+14 -18
View File
@@ -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);
+7 -1
View File
@@ -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(
+2
View File
@@ -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);
};
-2
View File
@@ -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<sevenz>();
add_task<zlib>();
add_task<fmt>();
+1 -1
View File
@@ -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())
+1 -1
View File
@@ -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)
+3 -3
View File
@@ -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")
+2 -2
View File
@@ -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")
+1 -2
View File
@@ -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)
+1 -3
View File
@@ -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")
+1 -1
View File
@@ -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_)
+3 -4
View File
@@ -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());