From da9df7425ac0703baa1d1e619f281d5f3f148aa8 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Wed, 29 Nov 2023 13:05:43 -0500 Subject: libuv: win/spawn: run executables with no file extension Backport this commit from libuv PR 4241 to restore `execute_process()` support for running executables on Windows with no file extension. Fixes: #25450 --- Utilities/cmlibuv/src/win/process.c | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/Utilities/cmlibuv/src/win/process.c b/Utilities/cmlibuv/src/win/process.c index 14d7a69..172b80b 100644 --- a/Utilities/cmlibuv/src/win/process.c +++ b/Utilities/cmlibuv/src/win/process.c @@ -274,19 +274,16 @@ static WCHAR* path_search_walk_ext(const WCHAR *dir, const WCHAR *name, size_t name_len, WCHAR *cwd, - size_t cwd_len, - int name_has_ext) { + size_t cwd_len) { WCHAR* result; - /* If the name itself has a nonempty extension, try this extension first */ - if (name_has_ext) { - result = search_path_join_test(dir, dir_len, - name, name_len, - L"", 0, - cwd, cwd_len); - if (result != NULL) { - return result; - } + /* Try the name itself first */ + result = search_path_join_test(dir, dir_len, + name, name_len, + L"", 0, + cwd, cwd_len); + if (result != NULL) { + return result; } /* Try .com extension */ @@ -329,8 +326,7 @@ static WCHAR* path_search_walk_ext(const WCHAR *dir, * - If there's really only a filename, check the current directory for file, * then search all path directories. * - * - If filename specified has *any* extension, search for the file with the - * specified extension first. + * - Search for the file exactly as specified first. * * - If the literal filename is not found in a directory, try *appending* * (not replacing) .com first and then .exe. @@ -360,10 +356,8 @@ static WCHAR* search_path(const WCHAR *file, int file_has_dir; WCHAR* result = NULL; WCHAR *file_name_start; - WCHAR *dot; const WCHAR *dir_start, *dir_end, *dir_path; size_t dir_len; - int name_has_ext; size_t file_len = wcslen(file); size_t cwd_len = wcslen(cwd); @@ -387,17 +381,12 @@ static WCHAR* search_path(const WCHAR *file, file_has_dir = file_name_start != file; - /* Check if the filename includes an extension */ - dot = wcschr(file_name_start, L'.'); - name_has_ext = (dot != NULL && dot[1] != L'\0'); - if (file_has_dir) { /* The file has a path inside, don't use path */ result = path_search_walk_ext( file, file_name_start - file, file_name_start, file_len - (file_name_start - file), - cwd, cwd_len, - name_has_ext); + cwd, cwd_len); } else { dir_end = path; @@ -405,8 +394,7 @@ static WCHAR* search_path(const WCHAR *file, /* The file is really only a name; look in cwd first, then scan path */ result = path_search_walk_ext(L"", 0, file, file_len, - cwd, cwd_len, - name_has_ext); + cwd, cwd_len); while (result == NULL) { if (dir_end == NULL || *dir_end == L'\0') { @@ -454,8 +442,7 @@ static WCHAR* search_path(const WCHAR *file, result = path_search_walk_ext(dir_path, dir_len, file, file_len, - cwd, cwd_len, - name_has_ext); + cwd, cwd_len); } } -- cgit v0.12 From f6d2efa752d5e823011951c6e642c27334f9377f Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Wed, 29 Nov 2023 10:06:36 -0500 Subject: Tests: Add case to cover execute_process support for no extension on Windows Issue: #25450 --- Tests/RunCMake/CMakeLists.txt | 1 + Tests/RunCMake/execute_process/RunCMakeTest.cmake | 7 +++++++ .../execute_process/WindowsNoExtension-build-stdout.txt | 6 ++++++ Tests/RunCMake/execute_process/WindowsNoExtension.cmake | 12 ++++++++++++ .../execute_process/WindowsNoExtensionRunScript.cmake | 17 +++++++++++++++++ Tests/RunCMake/execute_process/exe_extension.c | 7 +++++++ Tests/RunCMake/execute_process/exe_no_extension.c | 7 +++++++ 7 files changed, 57 insertions(+) create mode 100644 Tests/RunCMake/execute_process/WindowsNoExtension-build-stdout.txt create mode 100644 Tests/RunCMake/execute_process/WindowsNoExtension.cmake create mode 100644 Tests/RunCMake/execute_process/WindowsNoExtensionRunScript.cmake create mode 100644 Tests/RunCMake/execute_process/exe_extension.c create mode 100644 Tests/RunCMake/execute_process/exe_no_extension.c diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 2b61fd1..57034e5 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -475,6 +475,7 @@ set(execute_process_ARGS -DEXIT_CODE_EXE=$ -DPRINT_STDIN_EXE=$ -DPython_EXECUTABLE=${Python_EXECUTABLE} + -DCYGWIN=${CYGWIN} ) if(NOT CMake_TEST_EXTERNAL_CMAKE) list(APPEND execute_process_ARGS -DTEST_ENCODING_EXE=$) diff --git a/Tests/RunCMake/execute_process/RunCMakeTest.cmake b/Tests/RunCMake/execute_process/RunCMakeTest.cmake index 1e9e10a..a3a3a9a 100644 --- a/Tests/RunCMake/execute_process/RunCMakeTest.cmake +++ b/Tests/RunCMake/execute_process/RunCMakeTest.cmake @@ -46,3 +46,10 @@ if(UNIX AND Python_EXECUTABLE) run_cmake_command(LastCommandAbnormalExit-1 ${CMAKE_COMMAND} -DPython_EXECUTABLE=${Python_EXECUTABLE} -P ${RunCMake_SOURCE_DIR}/LastCommandAbnormalExit-1.cmake) run_cmake_command(LastCommandAbnormalExit-2 ${CMAKE_COMMAND} -DPython_EXECUTABLE=${Python_EXECUTABLE} -P ${RunCMake_SOURCE_DIR}/LastCommandAbnormalExit-2.cmake) endif() + +if(WIN32 OR CYGWIN) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/WindowsNoExtension-build) + run_cmake(WindowsNoExtension) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(WindowsNoExtension-build ${CMAKE_COMMAND} --build . --config Debug --target RunScript) +endif() diff --git a/Tests/RunCMake/execute_process/WindowsNoExtension-build-stdout.txt b/Tests/RunCMake/execute_process/WindowsNoExtension-build-stdout.txt new file mode 100644 index 0000000..22318b2 --- /dev/null +++ b/Tests/RunCMake/execute_process/WindowsNoExtension-build-stdout.txt @@ -0,0 +1,6 @@ +[^ +]*This executable does not have an extension +[^ +]*This executable does not have an extension +[^ +]*This executable has an extension diff --git a/Tests/RunCMake/execute_process/WindowsNoExtension.cmake b/Tests/RunCMake/execute_process/WindowsNoExtension.cmake new file mode 100644 index 0000000..8aec89d --- /dev/null +++ b/Tests/RunCMake/execute_process/WindowsNoExtension.cmake @@ -0,0 +1,12 @@ +enable_language(C) + +add_executable(exe_extension exe_extension.c) +add_executable(exe_no_extension exe_no_extension.c) + +add_custom_target(RunScript + ${CMAKE_COMMAND} + -Dexe_extension=$ + -Dexe_no_extension=$ + -P ${CMAKE_CURRENT_SOURCE_DIR}/WindowsNoExtensionRunScript.cmake + DEPENDS exe_extension exe_no_extension + ) diff --git a/Tests/RunCMake/execute_process/WindowsNoExtensionRunScript.cmake b/Tests/RunCMake/execute_process/WindowsNoExtensionRunScript.cmake new file mode 100644 index 0000000..8e640a0 --- /dev/null +++ b/Tests/RunCMake/execute_process/WindowsNoExtensionRunScript.cmake @@ -0,0 +1,17 @@ +file(COPY_FILE "${exe_no_extension}" "${CMAKE_CURRENT_BINARY_DIR}/exe" INPUT_MAY_BE_RECENT) +execute_process( + COMMAND "${CMAKE_CURRENT_BINARY_DIR}/exe" + COMMAND_ERROR_IS_FATAL ANY + ) + +file(COPY_FILE "${exe_extension}" "${CMAKE_CURRENT_BINARY_DIR}/exe.exe" INPUT_MAY_BE_RECENT) +execute_process( + COMMAND "${CMAKE_CURRENT_BINARY_DIR}/exe" + COMMAND_ERROR_IS_FATAL ANY + ) + +file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/exe") +execute_process( + COMMAND "${CMAKE_CURRENT_BINARY_DIR}/exe" + COMMAND_ERROR_IS_FATAL ANY + ) diff --git a/Tests/RunCMake/execute_process/exe_extension.c b/Tests/RunCMake/execute_process/exe_extension.c new file mode 100644 index 0000000..b00d7f9 --- /dev/null +++ b/Tests/RunCMake/execute_process/exe_extension.c @@ -0,0 +1,7 @@ +#include + +int main(void) +{ + printf("This executable has an extension\n"); + return 0; +} diff --git a/Tests/RunCMake/execute_process/exe_no_extension.c b/Tests/RunCMake/execute_process/exe_no_extension.c new file mode 100644 index 0000000..b0596c3 --- /dev/null +++ b/Tests/RunCMake/execute_process/exe_no_extension.c @@ -0,0 +1,7 @@ +#include + +int main(void) +{ + printf("This executable does not have an extension\n"); + return 0; +} -- cgit v0.12