refactor(terminal)!: drop winpty, require Windows 10 #18253

Problem:
winpty is only needed for Windows 8.1. Removing it reduces our build and code
complexity.

Solution:
- Remove winpty.
- Require Windows 10.

closes #18252
This commit is contained in:
erw7 2022-04-27 13:17:06 +09:00 committed by GitHub
parent 3933592338
commit 5f3018fa1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 187 deletions

View File

@ -509,11 +509,6 @@ endif()
find_package(LIBVTERM 0.1 REQUIRED)
include_directories(SYSTEM ${LIBVTERM_INCLUDE_DIRS})
if(WIN32)
find_package(Winpty 0.4.3 REQUIRED)
include_directories(SYSTEM ${WINPTY_INCLUDE_DIRS})
endif()
option(CLANG_ASAN_UBSAN "Enable Clang address & undefined behavior sanitizer for nvim binary." OFF)
option(CLANG_MSAN "Enable Clang memory sanitizer for nvim binary." OFF)
option(CLANG_TSAN "Enable Clang thread sanitizer for nvim binary." OFF)

View File

@ -1,10 +0,0 @@
include(LibFindMacros)
find_path(WINPTY_INCLUDE_DIR winpty.h)
set(WINPTY_INCLUDE_DIRS ${WINPTY_INCLUDE_DIR})
find_library(WINPTY_LIBRARY winpty)
find_program(WINPTY_AGENT_EXE winpty-agent.exe)
set(WINPTY_LIBRARIES ${WINPTY_LIBRARY})
find_package_handle_standard_args(Winpty DEFAULT_MSG WINPTY_LIBRARY WINPTY_INCLUDE_DIR)

View File

@ -929,7 +929,7 @@ nvim_get_chan_info({chan}) *nvim_get_chan_info()*
• "pty" (optional) Name of pseudoterminal. On a POSIX
system this is a device path like "/dev/pts/1". If the
name is unknown, the key will still be present if a pty
is used (e.g. for winpty on Windows).
is used (e.g. for conpty on Windows).
• "buffer" (optional) Buffer with connected |terminal|
instance.
• "client" (optional) Info about the peer (client on the

View File

@ -465,7 +465,6 @@ endif()
if(WIN32)
list(APPEND NVIM_LINK_LIBRARIES netapi32)
list(APPEND NVIM_LINK_LIBRARIES ${WINPTY_LIBRARIES})
endif()
# Use "luv" as imported library, to work around CMake using "-lluv" for
@ -552,8 +551,6 @@ if(WIN32)
diff.exe
tee.exe
win32yank.exe
winpty-agent.exe
winpty.dll
xxd.exe
# Dependencies for neovim-qt

View File

@ -1740,7 +1740,7 @@ void nvim_set_client_info(uint64_t channel_id, String name, Dictionary version,
/// - "pty" (optional) Name of pseudoterminal. On a POSIX system this
/// is a device path like "/dev/pts/1". If the name is unknown,
/// the key will still be present if a pty is used (e.g. for
/// winpty on Windows).
/// conpty on Windows).
/// - "buffer" (optional) Buffer with connected |terminal| instance.
/// - "client" (optional) Info about the peer (client on the other end of
/// the RPC channel), if provided by it via

View File

@ -4,7 +4,6 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <winpty_constants.h>
#include "nvim/ascii.h"
#include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8
@ -23,11 +22,7 @@ static void CALLBACK pty_process_finish1(void *context, BOOLEAN unused)
PtyProcess *ptyproc = (PtyProcess *)context;
Process *proc = (Process *)ptyproc;
if (ptyproc->type == kConpty
&& ptyproc->object.conpty != NULL) {
os_conpty_free(ptyproc->object.conpty);
ptyproc->object.conpty = NULL;
}
os_conpty_free(ptyproc->conpty);
uv_timer_init(&proc->loop->uv, &ptyproc->wait_eof_timer);
ptyproc->wait_eof_timer.data = (void *)ptyproc;
uv_timer_start(&ptyproc->wait_eof_timer, wait_eof_timer_cb, 200, 200);
@ -39,10 +34,6 @@ int pty_process_spawn(PtyProcess *ptyproc)
{
Process *proc = (Process *)ptyproc;
int status = 0;
winpty_error_ptr_t err = NULL;
winpty_config_t *cfg = NULL;
winpty_spawn_config_t *spawncfg = NULL;
winpty_t *winpty_object = NULL;
conpty_t *conpty_object = NULL;
char *in_name = NULL;
char *out_name = NULL;
@ -56,38 +47,11 @@ int pty_process_spawn(PtyProcess *ptyproc)
assert(proc->err.closed);
if (os_has_conpty_working()) {
if ((conpty_object =
os_conpty_init(&in_name, &out_name, ptyproc->width, ptyproc->height)) != NULL) {
ptyproc->type = kConpty;
}
}
if (ptyproc->type == kWinpty) {
cfg = winpty_config_new(WINPTY_FLAG_ALLOW_CURPROC_DESKTOP_CREATION, &err);
if (cfg == NULL) {
emsg = "winpty_config_new failed";
goto cleanup;
}
winpty_config_set_initial_size(cfg, ptyproc->width, ptyproc->height);
winpty_object = winpty_open(cfg, &err);
if (winpty_object == NULL) {
emsg = "winpty_open failed";
goto cleanup;
}
status = utf16_to_utf8(winpty_conin_name(winpty_object), -1, &in_name);
if (status != 0) {
emsg = "utf16_to_utf8(winpty_conin_name) failed";
goto cleanup;
}
status = utf16_to_utf8(winpty_conout_name(winpty_object), -1, &out_name);
if (status != 0) {
emsg = "utf16_to_utf8(winpty_conout_name) failed";
goto cleanup;
}
if (!os_has_conpty_working()
|| (conpty_object =
os_conpty_init(&in_name, &out_name, ptyproc->width, ptyproc->height)) == NULL) {
status = UV_ENOSYS;
goto cleanup;
}
if (!proc->in.closed) {
@ -130,44 +94,15 @@ int pty_process_spawn(PtyProcess *ptyproc)
goto cleanup;
}
if (ptyproc->type == kConpty) {
if (!os_conpty_spawn(conpty_object,
&process_handle,
NULL,
cmd_line,
cwd,
env)) {
emsg = "os_conpty_spawn failed";
status = (int)GetLastError();
goto cleanup;
}
} else {
spawncfg = winpty_spawn_config_new(WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN,
NULL, // Optional application name
cmd_line,
cwd,
env,
&err);
if (spawncfg == NULL) {
emsg = "winpty_spawn_config_new failed";
goto cleanup;
}
DWORD win_err = 0;
if (!winpty_spawn(winpty_object,
spawncfg,
&process_handle,
NULL, // Optional thread handle
&win_err,
&err)) {
if (win_err) {
status = (int)win_err;
emsg = "failed to spawn process";
} else {
emsg = "winpty_spawn failed";
}
goto cleanup;
}
if (!os_conpty_spawn(conpty_object,
&process_handle,
NULL,
cmd_line,
cwd,
env)) {
emsg = "os_conpty_spawn failed";
status = (int)GetLastError();
goto cleanup;
}
proc->pid = (int)GetProcessId(process_handle);
@ -186,11 +121,8 @@ int pty_process_spawn(PtyProcess *ptyproc)
uv_run(&proc->loop->uv, UV_RUN_ONCE);
}
(ptyproc->type == kConpty) ?
(void *)(ptyproc->object.conpty = conpty_object) :
(void *)(ptyproc->object.winpty = winpty_object);
ptyproc->conpty = conpty_object;
ptyproc->process_handle = process_handle;
winpty_object = NULL;
conpty_object = NULL;
process_handle = NULL;
@ -200,16 +132,7 @@ cleanup:
ELOG("pty_process_spawn(%s): %s: error code: %d",
proc->argv[0], emsg, status);
status = os_translate_sys_error(status);
} else if (err != NULL) {
status = (int)winpty_error_code(err);
ELOG("pty_process_spawn(%s): %s: error code: %d",
proc->argv[0], emsg, status);
status = translate_winpty_error(status);
}
winpty_error_free(err);
winpty_config_free(cfg);
winpty_spawn_config_free(spawncfg);
winpty_free(winpty_object);
os_conpty_free(conpty_object);
xfree(in_name);
xfree(out_name);
@ -232,12 +155,7 @@ const char *pty_process_tty_name(PtyProcess *ptyproc)
void pty_process_resize(PtyProcess *ptyproc, uint16_t width, uint16_t height)
FUNC_ATTR_NONNULL_ALL
{
if (ptyproc->type == kConpty
&& ptyproc->object.conpty != NULL) {
os_conpty_set_size(ptyproc->object.conpty, width, height);
} else if (ptyproc->object.winpty != NULL) {
winpty_set_size(ptyproc->object.winpty, width, height, NULL);
}
os_conpty_set_size(ptyproc->conpty, width, height);
}
void pty_process_close(PtyProcess *ptyproc)
@ -255,11 +173,6 @@ void pty_process_close(PtyProcess *ptyproc)
void pty_process_close_master(PtyProcess *ptyproc)
FUNC_ATTR_NONNULL_ALL
{
if (ptyproc->type == kWinpty
&& ptyproc->object.winpty != NULL) {
winpty_free(ptyproc->object.winpty);
ptyproc->object.winpty = NULL;
}
}
void pty_process_teardown(Loop *loop)
@ -434,40 +347,6 @@ static void quote_cmd_arg(char *dest, size_t dest_remaining, const char *src)
}
}
/// Translate winpty error code to libuv error.
///
/// @param[in] winpty_errno Winpty error code returned by winpty_error_code
/// function.
///
/// @returns Error code of libuv error.
int translate_winpty_error(int winpty_errno)
{
if (winpty_errno <= 0) {
return winpty_errno; // If < 0 then it's already a libuv error.
}
switch (winpty_errno) {
case WINPTY_ERROR_OUT_OF_MEMORY:
return UV_ENOMEM;
case WINPTY_ERROR_SPAWN_CREATE_PROCESS_FAILED:
return UV_EAI_FAIL;
case WINPTY_ERROR_LOST_CONNECTION:
return UV_ENOTCONN;
case WINPTY_ERROR_AGENT_EXE_MISSING:
return UV_ENOENT;
case WINPTY_ERROR_UNSPECIFIED:
return UV_UNKNOWN;
case WINPTY_ERROR_AGENT_DIED:
return UV_ESRCH;
case WINPTY_ERROR_AGENT_TIMEOUT:
return UV_ETIMEDOUT;
case WINPTY_ERROR_AGENT_CREATION_FAILED:
return UV_EAI_FAIL;
default:
return UV_UNKNOWN;
}
}
typedef struct EnvNode {
wchar_t *str;
size_t len;
@ -484,7 +363,7 @@ static int build_env_block(dict_T *denv, wchar_t **env_block)
{
const size_t denv_size = (size_t)tv_dict_len(denv);
size_t env_block_len = 0;
int rc;
int rc = 0;
char **env = tv_dict_to_env(denv);
QUEUE *q;

View File

@ -2,25 +2,15 @@
#define NVIM_OS_PTY_PROCESS_WIN_H
#include <uv.h>
#include <winpty.h>
#include "nvim/event/process.h"
#include "nvim/lib/queue.h"
#include "nvim/os/pty_conpty_win.h"
typedef enum {
kWinpty,
kConpty,
} PtyType;
typedef struct pty_process {
Process process;
uint16_t width, height;
union {
winpty_t *winpty;
conpty_t *conpty;
} object;
PtyType type;
conpty_t *conpty;
HANDLE finish_wait;
HANDLE process_handle;
uv_timer_t wait_eof_timer;
@ -38,8 +28,7 @@ static inline PtyProcess pty_process_init(Loop *loop, void *data)
rv.process = process_init(loop, kProcessTypePty, data);
rv.width = 80;
rv.height = 24;
rv.object.winpty = NULL;
rv.type = kWinpty;
rv.conpty = NULL;
rv.finish_wait = NULL;
rv.process_handle = NULL;
return rv;

View File

@ -191,9 +191,6 @@ set(WIN32YANK_X86_SHA256 62f34e5a46c5d4a7b3f3b512e1ff7b77fedd432f42581cbe825233a
set(WIN32YANK_X86_64_URL https://github.com/equalsraf/win32yank/releases/download/v0.0.4/win32yank-x64.zip)
set(WIN32YANK_X86_64_SHA256 33a747a92da60fb65e668edbf7661d3d902411a2d545fe9dc08623cecd142a20)
set(WINPTY_URL https://github.com/rprichard/winpty/releases/download/0.4.3/winpty-0.4.3-msvc2015.zip)
set(WINPTY_SHA256 35a48ece2ff4acdcbc8299d4920de53eb86b1fb41e64d2fe5ae7898931bcee89)
set(GETTEXT_URL https://ftp.gnu.org/pub/gnu/gettext/gettext-0.20.1.tar.gz)
set(GETTEXT_SHA256 66415634c6e8c3fa8b71362879ec7575e27da43da562c798a8a2f223e6e47f5c)
@ -284,18 +281,6 @@ if(WIN32)
elseif(TARGET_ARCH STREQUAL "X86")
set(TARGET_ARCH ia32)
endif()
GetBinaryDep(TARGET winpty
INSTALL_COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/bin
COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/winpty/${TARGET_ARCH}/bin/*
-DTO=${DEPS_INSTALL_DIR}/bin/
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake
COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/winpty/include/*
-DTO=${DEPS_INSTALL_DIR}/include/
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake
COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/winpty/${TARGET_ARCH}/lib/*
-DTO=${DEPS_INSTALL_DIR}/lib/
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake)
endif()
# clean-shared-libraries removes ${DEPS_INSTALL_DIR}/lib/nvim/parser/c.dll,