mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-06-07 14:07:29 +08:00
[vcpkg] Improve handling of ctrl-c inside install
or build
.
This commit is contained in:
parent
56e1d2f696
commit
faf7c2db7d
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user