aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src
diff options
context:
space:
mode:
Diffstat (limited to 'toolsrc/src')
-rw-r--r--toolsrc/src/vcpkg/base/system.cpp43
1 files changed, 37 insertions, 6 deletions
diff --git a/toolsrc/src/vcpkg/base/system.cpp b/toolsrc/src/vcpkg/base/system.cpp
index 9d8e1ce84..e3d3ad292 100644
--- a/toolsrc/src/vcpkg/base/system.cpp
+++ b/toolsrc/src/vcpkg/base/system.cpp
@@ -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)