summaryrefslogtreecommitdiff
path: root/xmake/modules/utils
diff options
context:
space:
mode:
authorruki <[email protected]>2026-03-03 14:56:04 +0800
committerGitHub <[email protected]>2026-03-03 14:56:04 +0800
commit83dcecd2bde90ca5a78fd263ba0f79401c5c223c (patch)
tree18324c368eefdad119e3efe88b140eede1ad395e /xmake/modules/utils
parent4662898e3eae02b84045bae6448c79758edbd5c9 (diff)
parent1b5179defb0f9973e6dba387ec177e6c99efbe5d (diff)
Merge pull request #7366 from xmake-io/gz
Improve targz and add tarxz pack format
Diffstat (limited to 'xmake/modules/utils')
-rw-r--r--xmake/modules/utils/archive/archive.lua90
1 files changed, 70 insertions, 20 deletions
diff --git a/xmake/modules/utils/archive/archive.lua b/xmake/modules/utils/archive/archive.lua
index 7a40f2cce..cd33d34b7 100644
--- a/xmake/modules/utils/archive/archive.lua
+++ b/xmake/modules/utils/archive/archive.lua
@@ -92,7 +92,18 @@ function _archive_using_7z(archivefile, inputfiles, extension, opt)
end
-- init argv
- local argv = {"a", archivefile, "-y"}
+ local argv = {"a"}
+ if extension == ".gz" then
+ table.insert(argv, "-tgzip")
+ end
+ if extension == ".tar" then
+ table.insert(argv, "-ttar")
+ end
+ if extension == ".xz" then
+ table.insert(argv, "-txz")
+ end
+ table.insert(argv, archivefile)
+ table.insert(argv, "-y")
local excludesfile
if opt.excludes then
excludesfile = os.tmpfile()
@@ -100,7 +111,7 @@ function _archive_using_7z(archivefile, inputfiles, extension, opt)
table.insert(argv, "-xr@" .. excludesfile)
end
local compress = opt.compress
- if compress then
+ if compress and extension ~= ".tar" then
if compress == "fastest" then
table.insert(argv, "-mx1")
elseif compress == "faster" then
@@ -188,7 +199,22 @@ function _archive_using_gzip(archivefile, inputfiles, extension, opt)
end
-- init argv
- local argv = {"-k", "-c", archivefile}
+ local argv = {"-c", archivefile}
+ local keep = _g.gzip_keep
+ if keep == nil then
+ -- https://github.com/xmake-io/xmake/issues/7361
+ keep = try {function ()
+ local outdata, errdata = os.iorunv(gzip.program, {"--help"})
+ local result = (outdata or "") .. (errdata or "")
+ if result and (result:find(" -k", 1, true) or result:find("--keep", 1, true)) then
+ return true
+ end
+ end}
+ _g.gzip_keep = keep or false
+ end
+ if keep then
+ table.insert(argv, 1, "-k")
+ end
if not option.get("verbose") then
table.insert(argv, "-q")
end
@@ -233,17 +259,30 @@ function _archive_using_tar(archivefile, inputfiles, extension, opt)
local compress = false
local archivefile_tar
if extension ~= ".tar" then
- if is_host("windows") then
- return false
- else
- compress = true
- archivefile_tar = path.join(path.directory(archivefile), path.basename(archivefile))
- end
+ compress = true
+ archivefile_tar = path.join(path.directory(archivefile), path.basename(archivefile))
end
-- init argv
local argv = {}
- if compress then
+ local program = tar.program
+ if is_host("windows") then
+ local force_local = _g.force_local
+ if force_local == nil then
+ force_local = try {function ()
+ local outdata, errdata = os.iorunv(program, {"--help"})
+ local result = (outdata or "") .. (errdata or "")
+ if result and result:find("--force-local", 1, true) then
+ return true
+ end
+ end}
+ _g.force_local = force_local or false
+ end
+ if force_local then
+ table.insert(argv, "--force-local")
+ end
+ end
+ if compress and not is_host("windows") then
table.insert(argv, "-a")
end
if option.get("verbose") then
@@ -275,13 +314,24 @@ function _archive_using_tar(archivefile, inputfiles, extension, opt)
end
-- archive it
- os.vrunv(tar.program, argv, {curdir = opt.curdir})
+ os.vrunv(program, argv, {curdir = opt.curdir})
if inputlistfile then
os.tryrm(inputlistfile)
end
if archivefile_tar and os.isfile(archivefile_tar) then
- _archive_tarfile(archivefile, archivefile_tar, opt)
- os.rm(archivefile_tar)
+ try {
+ function ()
+ _archive_tarfile(archivefile, archivefile_tar, opt)
+ os.tryrm(archivefile_tar)
+ return true
+ end,
+ catch {
+ function (errs)
+ os.tryrm(archivefile_tar)
+ raise(errs)
+ end
+ }
+ }
end
return true
end
@@ -312,8 +362,8 @@ end
-- only archive tar file
function _archive_tarfile(archivefile, tarfile, opt)
local archivers = {
- [".xz"] = {_archive_using_xz}
- , [".gz"] = {_archive_using_gzip}
+ [".xz"] = {_archive_using_xz, _archive_using_7z}
+ , [".gz"] = {_archive_using_gzip, _archive_using_7z}
}
local extension = opt.extension or path.extension(archivefile)
return _archive(archivefile, tarfile, extension, archivers[extension], opt)
@@ -336,11 +386,11 @@ function main(archivefile, inputfiles, opt)
local archivers = {
[".zip"] = {_archive_using_zip, _archive_using_7z}
, [".7z"] = {_archive_using_7z}
- , [".xz"] = {_archive_using_xz}
- , [".gz"] = {_archive_using_gzip}
- , [".tar"] = {_archive_using_tar}
- , [".tar.gz"] = {_archive_using_tar, _archive_using_gzip}
- , [".tar.xz"] = {_archive_using_tar, _archive_using_xz}
+ , [".xz"] = {_archive_using_xz, _archive_using_7z}
+ , [".gz"] = {_archive_using_gzip, _archive_using_7z}
+ , [".tar"] = {_archive_using_tar, _archive_using_7z}
+ , [".tar.gz"] = {_archive_using_tar}
+ , [".tar.xz"] = {_archive_using_tar}
, [".xmz"] = {_archive_using_xmz}
}