From 05f0bb724f1e2d59d851828cb5d16d64ef98b860 Mon Sep 17 00:00:00 2001 From: DavidWang19 Date: Sat, 2 May 2026 21:56:20 +0100 Subject: fix msvc/intel/snippet detect when temp path contains spaces Pass the temp bat / test binary via the *v variants of os.run / iorun / vrun so os.argv does not split the path on whitespace. --- xmake/modules/detect/sdks/find_iccenv.lua | 4 +++- xmake/modules/detect/sdks/find_icxenv.lua | 4 +++- xmake/modules/detect/sdks/find_ifortenv.lua | 4 +++- xmake/modules/detect/sdks/find_ifxenv.lua | 4 +++- xmake/modules/detect/sdks/find_vstudio.lua | 4 +++- xmake/modules/lib/detect/check_cxsnippets.lua | 7 +++++-- xmake/modules/lib/detect/check_fcsnippets.lua | 7 +++++-- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/xmake/modules/detect/sdks/find_iccenv.lua b/xmake/modules/detect/sdks/find_iccenv.lua index 050352b92..e33050843 100644 --- a/xmake/modules/detect/sdks/find_iccenv.lua +++ b/xmake/modules/detect/sdks/find_iccenv.lua @@ -53,7 +53,9 @@ function _load_iclvars(iclvars_bat, arch, opt) file:close() -- run geniclvars.bat - os.run(geniclvars_bat) + -- @note we use runv here so the bat path is not split on whitespace by os.argv, + -- which breaks detection when the temp file lives under a path with spaces. + os.runv(geniclvars_bat, {}) -- load all envirnoment variables local variables = {} diff --git a/xmake/modules/detect/sdks/find_icxenv.lua b/xmake/modules/detect/sdks/find_icxenv.lua index e715491b3..0a1941dc1 100644 --- a/xmake/modules/detect/sdks/find_icxenv.lua +++ b/xmake/modules/detect/sdks/find_icxenv.lua @@ -53,7 +53,9 @@ function _load_icxvars(icxvars_bat, arch, opt) file:close() -- run genicxvars.bat - os.run(genicxvars_bat) + -- @note we use runv here so the bat path is not split on whitespace by os.argv, + -- which breaks detection when the temp file lives under a path with spaces. + os.runv(genicxvars_bat, {}) -- load all envirnoment variables local variables = {} diff --git a/xmake/modules/detect/sdks/find_ifortenv.lua b/xmake/modules/detect/sdks/find_ifortenv.lua index 19664cbbc..9c877e79e 100644 --- a/xmake/modules/detect/sdks/find_ifortenv.lua +++ b/xmake/modules/detect/sdks/find_ifortenv.lua @@ -53,7 +53,9 @@ function _load_ifortvars(ifortvars_bat, arch, opt) file:close() -- run genifortvars.bat - os.run(genifortvars_bat) + -- @note we use runv here so the bat path is not split on whitespace by os.argv, + -- which breaks detection when the temp file lives under a path with spaces. + os.runv(genifortvars_bat, {}) -- load all envirnoment variables local variables = {} diff --git a/xmake/modules/detect/sdks/find_ifxenv.lua b/xmake/modules/detect/sdks/find_ifxenv.lua index 940d0e8fd..58d206e3f 100644 --- a/xmake/modules/detect/sdks/find_ifxenv.lua +++ b/xmake/modules/detect/sdks/find_ifxenv.lua @@ -53,7 +53,9 @@ function _load_ifxvars(ifxvars_bat, arch, opt) file:close() -- run genifxvars.bat - os.run(genifxvars_bat) + -- @note we use runv here so the bat path is not split on whitespace by os.argv, + -- which breaks detection when the temp file lives under a path with spaces. + os.runv(genifxvars_bat, {}) -- load all envirnoment variables local variables = {} diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua index e7699ee0d..c0daf8f53 100644 --- a/xmake/modules/detect/sdks/find_vstudio.lua +++ b/xmake/modules/detect/sdks/find_vstudio.lua @@ -294,7 +294,9 @@ function _load_vcvarsall_impl(vcvarsall, vsver, arch, opt) file:close() -- run genvcvars.bat - local outdata, errdata = try {function () return os.iorun(genvcvars_bat) end} + -- @note we use iorunv here so the bat path is not split on whitespace by os.argv, + -- which breaks detection when the temp file lives under a path with spaces. + local outdata, errdata = try {function () return os.iorunv(genvcvars_bat, {}) end} if errdata and #errdata > 0 and option.get("verbose") and option.get("diagnosis") then cprint("${color.warning}checkinfo: ${clear dim}get vcvars error: %s", errdata) end diff --git a/xmake/modules/lib/detect/check_cxsnippets.lua b/xmake/modules/lib/detect/check_cxsnippets.lua index 1e7dc604b..48a0f189b 100644 --- a/xmake/modules/lib/detect/check_cxsnippets.lua +++ b/xmake/modules/lib/detect/check_cxsnippets.lua @@ -255,14 +255,17 @@ function main(snippets, opt) linker.link("binary", {"cc", "cxx"}, objectfile, binaryfile, opt) end if opt.tryrun then + -- @note we use the *v variants so the binary path is not split on + -- whitespace by os.argv. mostly hits on Windows where TEMP lives + -- under the user profile and may contain spaces. if opt.output then - local output = os.iorun(binaryfile) + local output = os.iorunv(binaryfile, {}) if output then output = output:trim() end return true, output else - os.vrun(binaryfile) + os.vrunv(binaryfile, {}) end end local binary_match = opt.binary_match diff --git a/xmake/modules/lib/detect/check_fcsnippets.lua b/xmake/modules/lib/detect/check_fcsnippets.lua index 7314c96f8..b6dcd8f46 100644 --- a/xmake/modules/lib/detect/check_fcsnippets.lua +++ b/xmake/modules/lib/detect/check_fcsnippets.lua @@ -114,14 +114,17 @@ function main(snippets, opt) linker.link("binary", linkerkind, objectfile, binaryfile, opt) end if opt.tryrun then + -- @note we use the *v variants so the binary path is not split on + -- whitespace by os.argv. mostly hits on Windows where TEMP lives + -- under the user profile and may contain spaces. if opt.output then - local output = os.iorun(binaryfile) + local output = os.iorunv(binaryfile, {}) if output then output = output:trim() end return true, output else - os.vrun(binaryfile) + os.vrunv(binaryfile, {}) end end local binary_match = opt.binary_match -- cgit v1.3.1