aboutsummaryrefslogtreecommitdiff
path: root/toolsrc
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2017-10-19 19:50:23 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2017-10-19 19:57:58 -0700
commit50ae9eec872a0802d2450b4ae2d640475d0d7889 (patch)
tree21360604e45e37b652ae6c4005f57f7028d735b0 /toolsrc
parent8cefb25bcb7edaedd20d8aa170b2e1b945fd1762 (diff)
downloadvcpkg-50ae9eec872a0802d2450b4ae2d640475d0d7889.tar.gz
vcpkg-50ae9eec872a0802d2450b4ae2d640475d0d7889.zip
Do not depend on newlines when getting output from powershell
Diffstat (limited to 'toolsrc')
-rw-r--r--toolsrc/include/vcpkg/base/system.h2
-rw-r--r--toolsrc/src/vcpkg/base/system.cpp16
-rw-r--r--toolsrc/src/vcpkg/vcpkgpaths.cpp14
3 files changed, 21 insertions, 11 deletions
diff --git a/toolsrc/include/vcpkg/base/system.h b/toolsrc/include/vcpkg/base/system.h
index b396ef293..e0d3264e2 100644
--- a/toolsrc/include/vcpkg/base/system.h
+++ b/toolsrc/include/vcpkg/base/system.h
@@ -22,7 +22,7 @@ namespace vcpkg::System
ExitCodeAndOutput cmd_execute_and_capture_output(const CStringView cmd_line);
- std::string create_powershell_script_cmd(const fs::path& script_path, const CStringView args = "");
+ ExitCodeAndOutput powershell_execute_and_capture_output(const fs::path& script_path, const CStringView args = "");
enum class Color
{
diff --git a/toolsrc/src/vcpkg/base/system.cpp b/toolsrc/src/vcpkg/base/system.cpp
index b04f79414..a1bc9daf6 100644
--- a/toolsrc/src/vcpkg/base/system.cpp
+++ b/toolsrc/src/vcpkg/base/system.cpp
@@ -269,11 +269,23 @@ namespace vcpkg::System
#endif
}
- std::string create_powershell_script_cmd(const fs::path& script_path, const CStringView args)
+ ExitCodeAndOutput powershell_execute_and_capture_output(const fs::path& script_path, const CStringView args)
{
// TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned
- return Strings::format(
+ const std::string cmd = Strings::format(
R"(powershell -NoProfile -ExecutionPolicy Bypass -Command "& {& '%s' %s}")", script_path.u8string(), args);
+
+ auto rc = System::cmd_execute_and_capture_output(cmd);
+
+ // Remove newline from all output.
+ // Powershell returns newlines when it hits the column count of the console.
+ // For example, this is 80 in cmd on Windows 7. If the expected output is longer than 80 lines, we get
+ // newlines in-between the data.
+ // To solve this, we design our interaction with powershell to not depend on newlines,
+ // and then strip all newlines here.
+ rc.output = Strings::replace_all(std::move(rc.output), "\n", "");
+
+ return rc;
}
void println() { putchar('\n'); }
diff --git a/toolsrc/src/vcpkg/vcpkgpaths.cpp b/toolsrc/src/vcpkg/vcpkgpaths.cpp
index 2f2dd877e..ef9e383bc 100644
--- a/toolsrc/src/vcpkg/vcpkgpaths.cpp
+++ b/toolsrc/src/vcpkg/vcpkgpaths.cpp
@@ -74,9 +74,8 @@ namespace vcpkg
tool_name,
version_as_string);
const fs::path script = scripts_folder / "fetchDependency.ps1";
- const auto install_cmd =
- System::create_powershell_script_cmd(script, Strings::format("-Dependency %s", tool_name));
- const System::ExitCodeAndOutput rc = System::cmd_execute_and_capture_output(install_cmd);
+ const System::ExitCodeAndOutput rc =
+ System::powershell_execute_and_capture_output(script, Strings::format("-Dependency %s", tool_name));
if (rc.exit_code)
{
System::println(System::Color::error,
@@ -324,14 +323,13 @@ namespace vcpkg
static std::vector<VisualStudioInstance> get_visual_studio_instances(const VcpkgPaths& paths)
{
const fs::path script = paths.scripts / "findVisualStudioInstallationInstances.ps1";
- const std::string cmd = System::create_powershell_script_cmd(script);
- const System::ExitCodeAndOutput ec_data = System::cmd_execute_and_capture_output(cmd);
+ const System::ExitCodeAndOutput ec_data = System::powershell_execute_and_capture_output(script);
Checks::check_exit(
VCPKG_LINE_INFO, ec_data.exit_code == 0, "Could not run script to detect Visual Studio instances");
- const std::vector<std::string> instances_as_strings = Strings::split(ec_data.output, "\n");
+ const std::vector<std::string> instances_as_strings = Strings::split(ec_data.output, "::<eol>");
Checks::check_exit(
- VCPKG_LINE_INFO, !instances_as_strings.empty(), "Could not detect any Visual Studio instances");
+ VCPKG_LINE_INFO, !instances_as_strings.empty(), "Could not detect any Visual Studio instances.\n");
std::vector<VisualStudioInstance> output;
for (const std::string& instance_as_string : instances_as_strings)
@@ -341,7 +339,7 @@ namespace vcpkg
split.size() == 4,
"Invalid Visual Studio instance format.\n"
"Expected: PreferenceWeight::ReleaseType::Version::PathToVisualStudio\n"
- "Actual : %s",
+ "Actual : %s\n",
instance_as_string);
output.push_back({split.at(3), split.at(2), split.at(1), split.at(0)});
}