diff options
| author | Saikari <[email protected]> | 2026-02-02 03:37:52 +0300 |
|---|---|---|
| committer | Saikari <[email protected]> | 2026-02-02 03:37:52 +0300 |
| commit | 39797ac3c7cce56399185ab71b37ee92cafc67d3 (patch) | |
| tree | 29cfd34e675972ebd147084e7eedd7f4b67c4600 /tests/modules/stdin/test.lua | |
| parent | f3b8a1296313ee90a3451257f0f2cfa2964795b0 (diff) | |
refactor: streamline APE loader mode handling for Linux and improve MacOS compatibility
Diffstat (limited to 'tests/modules/stdin/test.lua')
| -rw-r--r-- | tests/modules/stdin/test.lua | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/tests/modules/stdin/test.lua b/tests/modules/stdin/test.lua index f54bb97c7..3f3539c61 100644 --- a/tests/modules/stdin/test.lua +++ b/tests/modules/stdin/test.lua @@ -5,49 +5,38 @@ function main(t) end -- Fix /usr/bin/ape loader mode on Linux - if os.host() == "linux" and path.filename(xmake) == "ape" and os.isfile("/proc/self/cmdline") then - local file = io.open("/proc/self/cmdline", "rb") - if file then - local content = file:read("*a") - file:close() - if content then - local args = {} - for arg in content:gmatch("[^\0]+") do - table.insert(args, arg) - end - if #args >= 2 and path.unix(args[1]) == xmake then - xmake = path.unix(args[2]) - if not path.is_absolute(xmake) then - xmake = path.absolute(xmake) + local function fix_ape_programfile(xmake) + if os.host() == "linux" and path.filename(xmake) == "ape" and os.isfile("/proc/self/cmdline") then + local file = io.open("/proc/self/cmdline", "rb") + if file then + local content = file:read("*a") + file:close() + if content then + local args = {} + for arg in content:gmatch("[^\0]+") do + table.insert(args, arg) + end + if #args >= 2 and path.unix(args[1]) == xmake then + xmake = path.unix(args[2]) + if not path.is_absolute(xmake) then + xmake = path.absolute(xmake) + end end end end end - end - - -- APE/Cosmocc workaround: force xmake name to avoid APE loader mode issues (e.g. ape-x86_64.elf) - local function setup_xmake_alias(xmake) - if path.filename(xmake):find("ape-", 1, true) then - local xmake_dir = path.join(os.tmpdir(), "xm_alias_" .. os.time()) - os.mkdir(xmake_dir) - local xmake_alias = path.join(xmake_dir, os.host() == "windows" and "xmake.exe" or "xmake") - os.cp(xmake, xmake_alias) - if os.host() ~= "windows" then - os.exec("chmod +x " .. xmake_alias) - end - return xmake_alias - end return xmake end - local is_ape = path.filename(xmake):find("ape-", 1, true) - -- Fix pwsh and cosmocc "err: ape error: l: not found (maybe chmod +x or ./ needed)" for Linux - --xmake = setup_xmake_alias(xmake) + xmake = fix_ape_programfile(xmake) + + local is_ape = path.filename(xmake):find("ape-", 1, true) + print("Using xmake programfile is_ape = ", is_ape) local run_stdin = string.format('env "%s" l --stdin', xmake) -- Fix pwsh and cosmocc "exec format error" for MacOS - if is_ape and (os.host() == "macosx" or os.host() == "linux") then + if is_ape and os.host() == "macosx" then run_stdin = string.format("sh -c ' \\\"%s\\\" l --stdin '", xmake) end |
