summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShiffted <[email protected]>2026-06-11 00:49:15 +0200
committerShiffted <[email protected]>2026-06-11 00:49:15 +0200
commit4e41db7c11117eca50f8cec6cbdfc0f746965d3e (patch)
tree9a0d1880d19dd4398317c1284958e62dee4a96f5
parente8daedeb731439f7c26fb3bc024857e777d53ec2 (diff)
add fallback checks for gzip and tar detection
-rw-r--r--xmake/modules/detect/tools/find_gzip.lua12
-rw-r--r--xmake/modules/detect/tools/find_tar.lua12
2 files changed, 24 insertions, 0 deletions
diff --git a/xmake/modules/detect/tools/find_gzip.lua b/xmake/modules/detect/tools/find_gzip.lua
index ea0b97408..a3e456673 100644
--- a/xmake/modules/detect/tools/find_gzip.lua
+++ b/xmake/modules/detect/tools/find_gzip.lua
@@ -40,6 +40,18 @@ function main(opt)
-- init options
opt = opt or {}
+ opt.check = opt.check or function (program)
+ local ok = try { function () os.runv(program, {"--version"}, {envs = opt.envs, shell = opt.shell}) end }
+ if not ok then
+ -- some gzip do not support `--version`, so we fall back to compressing a temporary file to check it
+ local tmpfile = os.tmpfile()
+ io.writefile(tmpfile, "")
+ os.runv(program, {"-f", tmpfile}, {envs = opt.envs, shell = opt.shell})
+ os.rm(tmpfile .. ".gz")
+ os.rm(tmpfile)
+ end
+ end
+
-- find program
local program = find_program(opt.program or "gzip", opt)
diff --git a/xmake/modules/detect/tools/find_tar.lua b/xmake/modules/detect/tools/find_tar.lua
index e4c3f7d4f..37d69777a 100644
--- a/xmake/modules/detect/tools/find_tar.lua
+++ b/xmake/modules/detect/tools/find_tar.lua
@@ -40,6 +40,18 @@ function main(opt)
-- init options
opt = opt or {}
+ opt.check = opt.check or function (program)
+ local ok = try { function () os.runv(program, {"--version"}, {envs = opt.envs, shell = opt.shell}) end }
+ if not ok then
+ -- some tar do not support `--version`, so we fall back to creating a temporary archive to check it
+ local tmpdir = os.tmpfile() .. ".dir"
+ os.mkdir(tmpdir)
+ io.writefile(path.join(tmpdir, "test.txt"), "")
+ os.runv(program, {"-cf", "test.tar", "test.txt"}, {curdir = tmpdir, envs = opt.envs, shell = opt.shell})
+ os.rm(tmpdir)
+ end
+ end
+
-- find program
local program = find_program(opt.program or "tar", opt)