mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-11-24 16:19:00 +08:00
Add System::powershell_execute()
This commit is contained in:
parent
92872439b9
commit
2af7fe8690
@ -44,6 +44,10 @@ namespace vcpkg::System
|
||||
|
||||
ExitCodeAndOutput cmd_execute_and_capture_output(const CStringView cmd_line);
|
||||
|
||||
void powershell_execute(const std::string& title,
|
||||
const fs::path& script_path,
|
||||
const std::vector<PowershellParameter>& parameters = {});
|
||||
|
||||
std::string powershell_execute_and_capture_output(const std::string& title,
|
||||
const fs::path& script_path,
|
||||
const std::vector<PowershellParameter>& parameters = {});
|
||||
|
@ -119,6 +119,16 @@ namespace vcpkg::System
|
||||
{
|
||||
}
|
||||
|
||||
static std::string make_powershell_cmd(const fs::path& script_path,
|
||||
const std::vector<PowershellParameter>& parameters)
|
||||
{
|
||||
const std::string args = Strings::join(" ", parameters, [](auto&& v) { return v.s; });
|
||||
|
||||
// TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned
|
||||
return Strings::format(
|
||||
R"(powershell -NoProfile -ExecutionPolicy Bypass -Command "& {& '%s' %s}")", script_path.u8string(), args);
|
||||
}
|
||||
|
||||
int cmd_execute_clean(const CStringView cmd_line)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
@ -317,16 +327,37 @@ namespace vcpkg::System
|
||||
#endif
|
||||
}
|
||||
|
||||
void powershell_execute(const std::string& title,
|
||||
const fs::path& script_path,
|
||||
const std::vector<PowershellParameter>& parameters)
|
||||
{
|
||||
const std::string cmd = make_powershell_cmd(script_path, parameters);
|
||||
const int rc = System::cmd_execute(cmd);
|
||||
|
||||
if (rc)
|
||||
{
|
||||
System::println(Color::error,
|
||||
"%s\n"
|
||||
"Could not run:\n"
|
||||
" '%s'",
|
||||
title,
|
||||
script_path.generic_string());
|
||||
|
||||
{
|
||||
auto locked_metrics = Metrics::g_metrics.lock();
|
||||
locked_metrics->track_property("error", "powershell script failed");
|
||||
locked_metrics->track_property("title", title);
|
||||
}
|
||||
|
||||
Checks::exit_with_code(VCPKG_LINE_INFO, rc);
|
||||
}
|
||||
}
|
||||
|
||||
std::string powershell_execute_and_capture_output(const std::string& title,
|
||||
const fs::path& script_path,
|
||||
const std::vector<PowershellParameter>& parameters)
|
||||
{
|
||||
const std::string args = Strings::join(" ", parameters, [](auto&& v) { return v.s; });
|
||||
|
||||
// TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned
|
||||
const std::string cmd = Strings::format(
|
||||
R"(powershell -NoProfile -ExecutionPolicy Bypass -Command "& {& '%s' %s}")", script_path.u8string(), args);
|
||||
|
||||
const std::string cmd = make_powershell_cmd(script_path, parameters);
|
||||
auto rc = System::cmd_execute_and_capture_output(cmd);
|
||||
|
||||
if (rc.exit_code)
|
||||
|
Loading…
Reference in New Issue
Block a user