diff options
| author | Saikari <[email protected]> | 2026-01-28 18:49:00 +0300 |
|---|---|---|
| committer | Saikari <[email protected]> | 2026-01-28 18:49:00 +0300 |
| commit | a258bf46f84f9be20e990db154f5cc9e8fbc4c3e (patch) | |
| tree | 8b80cc1c6d562c3e40e446f08641f81a87d6b95a /xmake/core/base/os.lua | |
| parent | 9c86aa7667c81d4e492d7418702ae50befdbd38b (diff) | |
Add parse_pe function to check for PE headers and enhance os.isexec for Windows
Diffstat (limited to 'xmake/core/base/os.lua')
| -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 963a015c1..33a073773 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -1158,15 +1158,38 @@ 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" then + if ext == ".exe" or ext == ".cmd" or ext == ".bat" or ext == ".ps1" then return true end + -- check for PE header + local peinfo = io.parse_pe(filepath) + 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 else return os._access(filepath, "x") end end if os.host() == "windows" then - for _, suffix in ipairs({".exe", ".cmd", ".bat"}) do + for _, suffix in ipairs({".exe", ".cmd", ".bat", ".ps1"}) do if os.isfile(filepath .. suffix) then return true end |
