diff options
| author | ruki <[email protected]> | 2026-01-30 22:41:30 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-01-30 22:41:30 +0800 |
| commit | 8a9d19e08aea07be760882d629fa90f4ab7c2da3 (patch) | |
| tree | 511a6dedd30c12e0a1b9da4b9f6d0b95ec52a06d | |
| parent | 9b87a6b6885d004d445f021b9536d08a18225351 (diff) | |
detect ape format
| -rw-r--r-- | core/src/xmake/binutils/format.c | 12 | ||||
| -rw-r--r-- | core/src/xmake/binutils/prefix.h | 1 | ||||
| -rw-r--r-- | tests/modules/binutils/test.lua | 12 | ||||
| -rw-r--r-- | tests/modules/os/test.lua | 8 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 4 |
5 files changed, 35 insertions, 2 deletions
diff --git a/core/src/xmake/binutils/format.c b/core/src/xmake/binutils/format.c index 670dec46b..240449f85 100644 --- a/core/src/xmake/binutils/format.c +++ b/core/src/xmake/binutils/format.c @@ -88,6 +88,12 @@ static __tb_inline__ tb_bool_t xm_binutils_format_is_shebang(tb_byte_t const* fi return first2[0] == '#' && first2[1] == '!'; } +static __tb_inline__ tb_bool_t xm_binutils_format_is_ape(tb_byte_t const* first8) { + return first8[0] == 'M' && first8[1] == 'Z' && + first8[2] == 'q' && first8[3] == 'F' && + first8[4] == 'p' && first8[5] == 'D'; +} + static __tb_inline__ tb_bool_t xm_binutils_format_is_elf(tb_byte_t const* first8) { return first8[0] == 0x7f && first8[1] == 'E' && first8[2] == 'L' && first8[3] == 'F'; } @@ -156,6 +162,11 @@ tb_int_t xm_binutils_format_detect(tb_stream_ref_t istream) { break; } + if (xm_binutils_format_is_ape(p)) { + format = XM_BINUTILS_FORMAT_APE; + break; + } + if (xm_binutils_format_is_elf(p)) { format = XM_BINUTILS_FORMAT_ELF; break; @@ -228,6 +239,7 @@ tb_int_t xm_binutils_format(lua_State *lua) { case XM_BINUTILS_FORMAT_AR: lua_pushliteral(lua, "ar"); break; case XM_BINUTILS_FORMAT_PE: lua_pushliteral(lua, "pe"); break; case XM_BINUTILS_FORMAT_SHEBANG: lua_pushliteral(lua, "shebang"); break; + case XM_BINUTILS_FORMAT_APE: lua_pushliteral(lua, "ape"); break; default: lua_pushliteral(lua, "unknown"); break; } diff --git a/core/src/xmake/binutils/prefix.h b/core/src/xmake/binutils/prefix.h index 482895c22..b3ffd8c27 100644 --- a/core/src/xmake/binutils/prefix.h +++ b/core/src/xmake/binutils/prefix.h @@ -35,6 +35,7 @@ #define XM_BINUTILS_FORMAT_AR 4 #define XM_BINUTILS_FORMAT_PE 5 #define XM_BINUTILS_FORMAT_SHEBANG 6 +#define XM_BINUTILS_FORMAT_APE 7 #define XM_BINUTILS_FORMAT_UNKNOWN 0 // COFF machine types (for format detection) diff --git a/tests/modules/binutils/test.lua b/tests/modules/binutils/test.lua index 363bf073b..543131c7f 100644 --- a/tests/modules/binutils/test.lua +++ b/tests/modules/binutils/test.lua @@ -14,6 +14,18 @@ function test_format(t) io.writefile(scriptfile, "#!/bin/sh\nexit 0\n") t:are_equal(binutils.format(scriptfile), "shebang") + local apefile = path.join(tempdir, "a.ape") + io.writefile(apefile, "MZqFpD00") + t:are_equal(binutils.format(apefile), "ape") + + local apecom = path.join(tempdir, "a.com") + io.writefile(apecom, "MZqFpD00") + t:are_equal(binutils.format(apecom), "ape") + + local comfile = path.join(tempdir, "b.com") + io.writefile(comfile, "12345678") + t:are_equal(binutils.format(comfile), "unknown") + local programfile = os.programfile() if programfile then local expected = "elf" diff --git a/tests/modules/os/test.lua b/tests/modules/os/test.lua index 71e9d610d..2dcab35c6 100644 --- a/tests/modules/os/test.lua +++ b/tests/modules/os/test.lua @@ -188,9 +188,17 @@ function test_isexec(t) io.writefile(batfile, "echo test\r\n") t:require(os.isexec(batfile)) + local comfile = path.join(tempdir, "a.com") + io.writefile(comfile, "12345678") + t:require(os.isexec(comfile)) + local suffix = path.join(tempdir, "prog") io.writefile(suffix .. ".exe", "") t:require(os.isexec(suffix)) + + local suffix2 = path.join(tempdir, "prog2") + io.writefile(suffix2 .. ".com", "") + t:require(os.isexec(suffix2)) else os.vrunv("chmod", {"-x", filepath}) t:require_not(os.isexec(filepath)) diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 6ffa08f74..ba3feca2d 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -1152,7 +1152,7 @@ function os.isexec(filepath) assert(filepath) if os.host() == "windows" then - local exts = {".exe", ".cmd", ".bat", ".ps1", ".sh"} + local exts = {".exe", ".com", ".cmd", ".bat", ".ps1", ".sh"} if os.isfile(filepath) then -- detect file extension first local extension = path.extension(filepath):lower() @@ -1166,7 +1166,7 @@ function os.isexec(filepath) if binutils and binutils.format then format = binutils.format(filepath) end - if format == "pe" or format == "shebang" then + if format == "pe" or format == "ape" or format == "shebang" then return true end end |
