diff options
| author | ruki <[email protected]> | 2026-06-12 22:20:28 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-06-12 22:20:28 +0800 |
| commit | a7072bbec6c52a56aab9babac97c0077b0a2021c (patch) | |
| tree | 4fc94d983cb3a63e48ee01cf511efcf96a2a1dfb | |
| parent | e8daedeb731439f7c26fb3bc024857e777d53ec2 (diff) | |
| parent | 9d9673d3eb54aacb2f37c6b1f6425ea9f267c119 (diff) | |
Merge pull request #7599 from Shiffted/fix-openbsd
Fix openbsd extractor detection
| -rw-r--r-- | xmake/modules/detect/tools/find_gzip.lua | 12 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_tar.lua | 12 | ||||
| -rw-r--r-- | xmake/modules/utils/archive/extract.lua | 19 |
3 files changed, 43 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) diff --git a/xmake/modules/utils/archive/extract.lua b/xmake/modules/utils/archive/extract.lua index a11f4146f..8116617fb 100644 --- a/xmake/modules/utils/archive/extract.lua +++ b/xmake/modules/utils/archive/extract.lua @@ -65,6 +65,25 @@ function _extract_using_tar(archivefile, outputdir, extension, opt) table.insert(argv, "--force-local") end end + + if is_host("bsd") then + -- pass explicit compression flag only to tar without auto-detection, + -- as auto-detection can handle more cases. + local auto_detect = _g.compression_auto_detect + if auto_detect == nil then + auto_detect = try { function () os.runv(program, {"--version"}); return true end } or false + _g.compression_auto_detect = auto_detect + end + if not auto_detect then + if extension == ".tgz" or extension == ".tar.gz" then + table.insert(argv, "-z") + elseif extension == ".tar.bz2" then + table.insert(argv, "-j") + elseif extension == ".tar.Z" then + table.insert(argv, "-Z") + end + end + end table.insert(argv, "-xf") table.insert(argv, path.absolute(archivefile)) |
