From faf7c2db7d154e113a65fc0efa3e4266680ed0c4 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Tue, 16 Oct 2018 01:26:04 -0700 Subject: [vcpkg] Improve handling of ctrl-c inside `install` or `build`. --- toolsrc/src/vcpkg/base/system.cpp | 9 +++++---- toolsrc/src/vcpkg/build.cpp | 12 +++++++++--- toolsrc/src/vcpkg/commands.env.cpp | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/base/system.cpp b/toolsrc/src/vcpkg/base/system.cpp index 085471b19..78ba28324 100644 --- a/toolsrc/src/vcpkg/base/system.cpp +++ b/toolsrc/src/vcpkg/base/system.cpp @@ -223,7 +223,7 @@ namespace vcpkg::System memset(&startup_info, 0, sizeof(STARTUPINFOW)); startup_info.cb = sizeof(STARTUPINFOW); - // Basically we are wrapping it in quotes + // Wrapping the command in a single set of quotes causes cmd.exe to correctly execute const std::string actual_cmd_line = Strings::format(R"###(cmd.exe /c "%s")###", cmd_line); Debug::println("CreateProcessW(%s)", actual_cmd_line); bool succeeded = TRUE == CreateProcessW(nullptr, @@ -316,9 +316,6 @@ namespace vcpkg::System ExitCodeAndOutput cmd_execute_and_capture_output(const CStringView cmd_line) noexcept { - // Flush stdout before launching external process - fflush(stdout); - auto timer = Chrono::ElapsedTimer::create_started(); #if defined(_WIN32) @@ -328,6 +325,8 @@ namespace vcpkg::System std::wstring output; wchar_t buf[1024]; GlobalState::g_ctrl_c_state.transition_to_spawn_process(); + // Flush stdout before launching external process + fflush(stdout); const auto pipe = _wpopen(Strings::to_utf16(actual_cmd_line).c_str(), L"r"); if (pipe == nullptr) { @@ -364,6 +363,8 @@ namespace vcpkg::System Debug::println("popen(%s)", actual_cmd_line); std::string output; char buf[1024]; + // Flush stdout before launching external process + fflush(stdout); const auto pipe = popen(actual_cmd_line.c_str(), "r"); if (pipe == nullptr) { diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index f5f2b9c6c..7569f340f 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -245,7 +245,7 @@ namespace vcpkg::Build const auto arch = to_vcvarsall_toolchain(pre_build_info.target_architecture, toolset); const auto target = to_vcvarsall_target(pre_build_info.cmake_system_name); - return Strings::format(R"("%s" %s %s %s %s 2>&1)", + return Strings::format(R"("%s" %s %s %s %s 2>&1 0) extra_env.emplace("PATH", Strings::join(";", path_vars)); - std::string env_cmd_prefix = env_cmd.empty() ? "" : Strings::format("%s &&", env_cmd); + std::string env_cmd_prefix = env_cmd.empty() ? "" : Strings::format("%s && ", env_cmd); std::string env_cmd_suffix = args.command_arguments.empty() ? "cmd" : Strings::format("cmd /c %s", args.command_arguments.at(0)); - const std::string cmd = Strings::format("%s %s", env_cmd_prefix, env_cmd_suffix); + const std::string cmd = Strings::format("%s%s", env_cmd_prefix, env_cmd_suffix); System::cmd_execute_clean(cmd, extra_env); Checks::exit_success(VCPKG_LINE_INFO); } -- cgit v1.2.3