Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edit command. #1221

Merged
merged 5 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,12 @@ set_property(TARGET closes-stdout PROPERTY PDB_NAME "closes-stdout${VCPKG_PDB_SU
set(READS_STDIN_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/reads-stdin.c")
add_executable(reads-stdin ${READS_STDIN_SOURCES} "${CMAKE_CURRENT_SOURCE_DIR}/src/vcpkg.manifest")
set_property(TARGET reads-stdin PROPERTY PDB_NAME "reads-stdin${VCPKG_PDB_SUFFIX}")

# === Target: test-editor ===

set(TEST_EDITOR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/test-editor.c")
add_executable(test-editor ${TEST_EDITOR_SOURCES} "${CMAKE_CURRENT_SOURCE_DIR}/src/vcpkg.manifest")
set_property(TARGET test-editor PROPERTY PDB_NAME "test-editor${VCPKG_PDB_SUFFIX}")
endif()

# === Target: format ===
Expand All @@ -554,6 +560,7 @@ if(CLANG_FORMAT)
COMMAND "${CLANG_FORMAT}" -i -verbose ${CLOSES_STDIN_SOURCES}
COMMAND "${CLANG_FORMAT}" -i -verbose ${CLOSES_STDOUT_SOURCES}
COMMAND "${CLANG_FORMAT}" -i -verbose ${READS_STDIN_SOURCES}
COMMAND "${CLANG_FORMAT}" -i -verbose ${TEST_EDITOR_SOURCES}
)
endif()

Expand Down
33 changes: 33 additions & 0 deletions azure-pipelines/end-to-end-tests-dir/edit.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
. $PSScriptRoot/../end-to-end-tests-prelude.ps1

$expected = "$env:VCPKG_ROOT/ports/zlib`n$env:VCPKG_ROOT/ports/zlib/portfile.cmake`n-n"
$expected = $expected.Replace('\', '/')

Refresh-TestRoot

$buildDir = (Get-Item $VcpkgExe).Directory
$tempFilePath = "$TestingRoot/result.txt"

$env:VCPKG_TEST_OUTPUT = $tempFilePath
$editor = "$buildDir/test-editor"
if ($IsWindows) {
$editor += '.exe'
}

Write-Host "Using editor $editor"
$env:EDITOR = $editor
try {
Run-Vcpkg edit zlib
Throw-IfFailed

$result = Get-Content -LiteralPath $tempFilePath -Raw
} finally {
Remove-Item env:VCPKG_TEST_OUTPUT
Remove-Item env:EDITOR
}

$result = $result.Trim().Replace('\', '/')

if ($result -ne $expected) {
throw 'Did not edit the expected directory.'
}
38 changes: 38 additions & 0 deletions src/test-editor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

int main(int argc, const char* argv[])
{
const char* path;
FILE* f;

path = getenv("VCPKG_TEST_OUTPUT");
if (!path)
{
puts("bad env var");
return 1;
}

f = fopen(path, "wb");
if (!f)
{
puts("bad open");
return 1;
}

for (int idx = 1; idx < argc; ++idx)
{
if (fputs(argv[idx], f) < 0)
{
puts("bad write");
}

if (fputs("\n", f) < 0)
{
puts("bad write newline");
}
}

fclose(f);
}
25 changes: 5 additions & 20 deletions src/vcpkg/base/system.process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ namespace
StringView cmd_line,
const WorkingDirectory& wd,
const Environment& env,
BOOL bInheritHandles,
DWORD dwCreationFlags,
STARTUPINFOEXW& startup_info) noexcept
{
Expand Down Expand Up @@ -764,7 +765,7 @@ namespace
Strings::to_utf16(cmd_line).data(),
nullptr,
nullptr,
TRUE,
bInheritHandles,
IDLE_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT | EXTENDED_STARTUPINFO_PRESENT |
dwCreationFlags,
call_environment,
Expand Down Expand Up @@ -1118,7 +1119,7 @@ namespace
startup_info_ex.lpAttributeList = proc_attribute_list.get();

auto process_create =
windows_create_process(debug_id, ret.proc_info, cmd_line, wd, env, dwCreationFlags, startup_info_ex);
windows_create_process(debug_id, ret.proc_info, cmd_line, wd, env, TRUE, dwCreationFlags, startup_info_ex);

if (!process_create)
{
Expand Down Expand Up @@ -1320,28 +1321,12 @@ namespace vcpkg
startup_info_ex.StartupInfo.cb = sizeof(STARTUPINFOEXW);
startup_info_ex.StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
startup_info_ex.StartupInfo.wShowWindow = SW_HIDE;

ProcAttributeList proc_attribute_list;
auto proc_attribute_list_create = proc_attribute_list.create(1);
if (!proc_attribute_list_create)
{
debug_print_cmd_execute_background_failure(debug_id, proc_attribute_list_create.error());
return;
}

auto maybe_error = proc_attribute_list.update_attribute(PROC_THREAD_ATTRIBUTE_HANDLE_LIST, nullptr, 0);
if (!maybe_error)
{
debug_print_cmd_execute_background_failure(debug_id, maybe_error.error());
return;
}

startup_info_ex.lpAttributeList = proc_attribute_list.get();
auto process_create = windows_create_process(debug_id,
process_info,
cmd_line.command_line(),
default_working_directory,
default_environment,
FALSE,
CREATE_NEW_CONSOLE | CREATE_NO_WINDOW | CREATE_BREAKAWAY_FROM_JOB,
startup_info_ex);
if (!process_create)
Expand Down Expand Up @@ -1408,7 +1393,7 @@ namespace vcpkg
SpawnProcessGuard spawn_process_guard;
ProcessInfo process_info;
auto process_create =
windows_create_process(debug_id, process_info, cmd_line.command_line(), wd, env, 0, startup_info_ex);
windows_create_process(debug_id, process_info, cmd_line.command_line(), wd, env, TRUE, 0, startup_info_ex);
if (!process_create)
{
return std::move(process_create).error();
Expand Down