diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2018-10-16 01:26:04 -0700 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2018-10-16 01:26:04 -0700 |
| commit | faf7c2db7d154e113a65fc0efa3e4266680ed0c4 (patch) | |
| tree | 4c5b697824a7e4b2cc82b2078de5c5b3a009d915 | |
| parent | 56e1d2f6961693b45f2b61b6e6985229be56e674 (diff) | |
| download | vcpkg-faf7c2db7d154e113a65fc0efa3e4266680ed0c4.tar.gz vcpkg-faf7c2db7d154e113a65fc0efa3e4266680ed0c4.zip | |
[vcpkg] Improve handling of ctrl-c inside `install` or `build`.
| -rw-r--r-- | toolsrc/src/vcpkg/base/system.cpp | 9 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/build.cpp | 12 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/commands.env.cpp | 4 |
3 files changed, 16 insertions, 9 deletions
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 <NUL)", toolset.vcvarsall.u8string(), Strings::join(" ", toolset.vcvarsall_options), arch, @@ -381,9 +381,15 @@ namespace vcpkg::Build }); auto command = make_build_env_cmd(pre_build_info, toolset); - if (!command.empty()) command.append(" && "); + if (!command.empty()) + { +#ifdef _WIN32 + command.append(" & "); +#else + command.append(" && "); +#endif + } command.append(cmd_launch_cmake); - const auto timer = Chrono::ElapsedTimer::create_started(); const int return_code = System::cmd_execute_clean(command); diff --git a/toolsrc/src/vcpkg/commands.env.cpp b/toolsrc/src/vcpkg/commands.env.cpp index f56bda1ec..ea00617d4 100644 --- a/toolsrc/src/vcpkg/commands.env.cpp +++ b/toolsrc/src/vcpkg/commands.env.cpp @@ -64,11 +64,11 @@ namespace vcpkg::Commands::Env if (add_python) extra_env.emplace("PYTHONPATH", (paths.installed / triplet.to_string() / "python").u8string()); if (path_vars.size() > 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); } |
