Skip to content

Commit

Permalink
[vcpkg] Improve handling of ctrl-c inside install or build.
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0219-msft committed Oct 16, 2018
1 parent 56e1d2f commit faf7c2d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
9 changes: 5 additions & 4 deletions toolsrc/src/vcpkg/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
12 changes: 9 additions & 3 deletions toolsrc/src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions toolsrc/src/vcpkg/commands.env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit faf7c2d

Please sign in to comment.