fix(eval): fix has('wsl') #16153

Problem:
has('wsl') is decided at build-time.

Solution:
Check os_uname().
Fixes #12642, #16143
This commit is contained in:
erw7 2021-10-30 08:55:32 +09:00 committed by GitHub
parent ac358bfb2f
commit 16d06fa3eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 13 deletions

View File

@ -12,11 +12,6 @@ check_type_size("size_t" SIZEOF_SIZE_T)
check_type_size("long long" SIZEOF_LONG_LONG) check_type_size("long long" SIZEOF_LONG_LONG)
check_type_size("void *" SIZEOF_VOID_PTR) check_type_size("void *" SIZEOF_VOID_PTR)
if (CMAKE_HOST_SYSTEM_VERSION MATCHES ".*-(Microsoft|microsoft-standard)")
# Windows Subsystem for Linux
set(HAVE_WSL 1)
endif()
check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON) check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON)
# Headers # Headers

View File

@ -39,7 +39,6 @@
#cmakedefine HAVE_SYS_WAIT_H #cmakedefine HAVE_SYS_WAIT_H
#cmakedefine HAVE_TERMIOS_H #cmakedefine HAVE_TERMIOS_H
#cmakedefine HAVE_WORKING_LIBINTL #cmakedefine HAVE_WORKING_LIBINTL
#cmakedefine HAVE_WSL
#cmakedefine UNIX #cmakedefine UNIX
#cmakedefine CASE_INSENSITIVE_FILENAME #cmakedefine CASE_INSENSITIVE_FILENAME
#cmakedefine USE_FNAME_CASE #cmakedefine USE_FNAME_CASE

View File

@ -4553,9 +4553,6 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
"windows", "windows",
"winaltkeys", "winaltkeys",
"writebackup", "writebackup",
#if defined(HAVE_WSL)
"wsl",
#endif
"nvim", "nvim",
}; };
@ -4602,6 +4599,8 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
n = syntax_present(curwin); n = syntax_present(curwin);
} else if (STRICMP(name, "clipboard_working") == 0) { } else if (STRICMP(name, "clipboard_working") == 0) {
n = eval_has_provider("clipboard"); n = eval_has_provider("clipboard");
} else if (STRICMP(name, "wsl") == 0) {
n = has_wsl();
#ifdef UNIX #ifdef UNIX
} else if (STRICMP(name, "unnamedplus") == 0) { } else if (STRICMP(name, "unnamedplus") == 0) {
n = eval_has_provider("clipboard"); n = eval_has_provider("clipboard");
@ -4616,9 +4615,24 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->vval.v_number = n; rettv->vval.v_number = n;
} }
/* static bool has_wsl(void)
* "has_key()" function {
*/ static TriState has_wsl = kNone;
if (has_wsl == kNone) {
Error err = ERROR_INIT;
Object o = nlua_exec(
STATIC_CSTR_AS_STRING("return vim.loop.os_uname()['release']:lower()"
":match('microsoft') and true or false"),
(Array)ARRAY_DICT_INIT, &err);
assert(!ERROR_SET(&err));
assert(o.type == kObjectTypeBoolean);
has_wsl = o.data.boolean ? kTrue : kFalse;
api_free_object(o);
}
return has_wsl == kTrue;
}
/// "has_key()" function
static void f_has_key(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void f_has_key(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{ {
if (argvars[0].v_type != VAR_DICT) { if (argvars[0].v_type != VAR_DICT) {

View File

@ -59,7 +59,12 @@ describe('has()', function()
end) end)
it('"wsl"', function() it('"wsl"', function()
if 1 == funcs.has('win32') or 1 == funcs.has('mac') then local luv = require('luv')
local is_wsl =
luv.os_uname()['release']:lower():match('microsoft') and true or false
if is_wsl then
eq(1, funcs.has('wsl'))
else
eq(0, funcs.has('wsl')) eq(0, funcs.has('wsl'))
end end
end) end)