diff options
| author | Saikari <[email protected]> | 2026-01-28 18:53:16 +0300 |
|---|---|---|
| committer | Saikari <[email protected]> | 2026-01-28 18:53:16 +0300 |
| commit | fa12bdfd81c297fecb611789020058a87c52eb16 (patch) | |
| tree | d0220d967cc23fd811331584477ffedc6dcf44b6 | |
| parent | a258bf46f84f9be20e990db154f5cc9e8fbc4c3e (diff) | |
Enhance os.isexec function to improve Windows executable detection and add PE header checks
| -rw-r--r-- | xmake/core/base/os.lua | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 33a073773..c8526837a 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -1158,7 +1158,7 @@ function os.isexec(filepath) if os.isfile(filepath) then if os.host() == "windows" then local ext = path.extension(filepath):lower() - if ext == ".exe" or ext == ".cmd" or ext == ".bat" or ext == ".ps1" then + if ext == ".cmd" or ext == ".bat" or ext == ".ps1" then return true end -- check for PE header @@ -1189,11 +1189,34 @@ function os.isexec(filepath) end end if os.host() == "windows" then - for _, suffix in ipairs({".exe", ".cmd", ".bat", ".ps1"}) do + for _, suffix in ipairs({".cmd", ".bat", ".ps1"}) do if os.isfile(filepath .. suffix) then return true end end + -- check for PE header + local peinfo = io.parse_pe(filepath .. ".exe") + if peinfo then + local pe_arch = peinfo.arch + -- x64 or x86 + if pe_arch == "x86" or pe_arch == "x64" and os.is_arch("x86_64") then + return true + else + return false + end + -- arm64 + if pe_arch == "arm64" and os.is_arch("arm64") then + return true + else + return false + end + -- arm32 + if pe_arch == "arm" and os.is_arch("arm.*") then + return true + else + return false + end + end end return false end |
