diff options
| author | ruki <[email protected]> | 2026-03-03 14:56:04 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-03 14:56:04 +0800 |
| commit | 83dcecd2bde90ca5a78fd263ba0f79401c5c223c (patch) | |
| tree | 18324c368eefdad119e3efe88b140eede1ad395e | |
| parent | 4662898e3eae02b84045bae6448c79758edbd5c9 (diff) | |
| parent | 1b5179defb0f9973e6dba387ec177e6c99efbe5d (diff) | |
Merge pull request #7366 from xmake-io/gz
Improve targz and add tarxz pack format
| -rw-r--r-- | tests/plugins/pack/console/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/utils/archive/archive.lua | 90 | ||||
| -rw-r--r-- | xmake/plugins/pack/main.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/pack/srctarxz/main.lua | 5 | ||||
| -rw-r--r-- | xmake/plugins/pack/tarxz/main.lua | 5 | ||||
| -rw-r--r-- | xmake/plugins/pack/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/pack/xpack.lua | 6 |
7 files changed, 88 insertions, 24 deletions
diff --git a/tests/plugins/pack/console/xmake.lua b/tests/plugins/pack/console/xmake.lua index 6db4316c5..8f3ae0bdd 100644 --- a/tests/plugins/pack/console/xmake.lua +++ b/tests/plugins/pack/console/xmake.lua @@ -19,7 +19,7 @@ target("foo") add_packages("zlib") xpack("test") - set_formats("nsis", "srpm", "rpm", "deb", "zip", "targz", "srczip", "srctargz", "runself", "wix", "dmg", "appimage") + set_formats("nsis", "srpm", "rpm", "deb", "zip", "targz", "tarxz", "srczip", "srctargz", "srctarxz", "runself", "wix", "dmg", "appimage") set_title("hello") set_author("ruki <[email protected]>") set_description("A test installer.") 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} } diff --git a/xmake/plugins/pack/main.lua b/xmake/plugins/pack/main.lua index fb0c983a0..8ba76d62d 100644 --- a/xmake/plugins/pack/main.lua +++ b/xmake/plugins/pack/main.lua @@ -145,5 +145,3 @@ function main() project.unlock() cprint("${color.success}pack ok") end - - diff --git a/xmake/plugins/pack/srctarxz/main.lua b/xmake/plugins/pack/srctarxz/main.lua new file mode 100644 index 000000000..508344165 --- /dev/null +++ b/xmake/plugins/pack/srctarxz/main.lua @@ -0,0 +1,5 @@ +import(".archive") + +function main(package) + archive(package) +end diff --git a/xmake/plugins/pack/tarxz/main.lua b/xmake/plugins/pack/tarxz/main.lua new file mode 100644 index 000000000..508344165 --- /dev/null +++ b/xmake/plugins/pack/tarxz/main.lua @@ -0,0 +1,5 @@ +import(".archive") + +function main(package) + archive(package) +end diff --git a/xmake/plugins/pack/xmake.lua b/xmake/plugins/pack/xmake.lua index 34eb5bd63..f95abcf98 100644 --- a/xmake/plugins/pack/xmake.lua +++ b/xmake/plugins/pack/xmake.lua @@ -33,7 +33,7 @@ task("pack") "e.g.", " - xmake pack -f nsis,deb,rpm", "values:", - values = {"nsis", "wix", "deb", "srpm", "rpm", "runself", "targz", "zip", "srctargz", "srczip"}}, + values = {"nsis", "wix", "deb", "srpm", "rpm", "runself", "targz", "tarxz", "zip", "srctargz", "srctarxz", "srczip"}}, {}, {nil, "packages", "vs", nil, "The package names."} } diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua index a20b480bc..fbd53ae22 100644 --- a/xmake/plugins/pack/xpack.lua +++ b/xmake/plugins/pack/xpack.lua @@ -205,10 +205,12 @@ function xpack:inputkind() nsis = "binary", zip = "binary", targz = "binary", + tarxz = "binary", dmg = "binary", appimage = "binary", srczip = "source", srctargz = "source", + srctarxz = "source", runself = "source", deb = "source", srpm = "source", @@ -226,10 +228,12 @@ function xpack:outputkind() nsis = "binary", zip = "binary", targz = "binary", + tarxz = "binary", dmg = "binary", appimage = "binary", srczip = "source", srctargz = "source", + srctarxz = "source", runself = "source", deb = "binary", srpm = "source", @@ -381,10 +385,12 @@ function xpack:extension() nsis = ".exe", zip = ".zip", targz = ".tar.gz", + tarxz = ".tar.xz", dmg = ".dmg", appimage = ".AppImage", srczip = ".zip", srctargz = ".tar.gz", + srctarxz = ".tar.xz", runself = ".gz.run", deb = ".deb", srpm = ".src.rpm", |
