summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-17 23:44:42 +0800
committerruki <[email protected]>2023-11-17 23:44:42 +0800
commit8f959aa5b93dd69c97bef2c49a0ee093460d078e (patch)
tree48b41664ff2c8fea5444e9789ee3b2da0bb17d59
parent08aa2aa500c79d8683629c5861beeebd99683213 (diff)
archive package files
-rw-r--r--xmake/plugins/pack/archive.lua54
-rw-r--r--xmake/plugins/pack/zip/main.lua2
2 files changed, 52 insertions, 4 deletions
diff --git a/xmake/plugins/pack/archive.lua b/xmake/plugins/pack/archive.lua
index cc6b3431a..cd389a43b 100644
--- a/xmake/plugins/pack/archive.lua
+++ b/xmake/plugins/pack/archive.lua
@@ -23,13 +23,61 @@ import("core.base.option")
import("utils.archive")
import("batchcmds")
+-- get archive directory
+function _get_archivedir(package)
+ return path.join(package:buildir(), "archive", package:format())
+end
+
+-- run command
+function _run_command(package, cmd)
+ local opt = cmd.opt or {}
+ local kind = cmd.kind
+ local archivedir = _get_archivedir(package)
+ if kind == "cp" then
+ local srcpath = cmd.srcpath
+ local dstpath = path.join(archivedir, cmd.dstpath)
+ os.vcp(srcpath, dstpath, opt)
+ elseif kind == "rm" then
+ local filepath = path.join(archivedir, cmd.filepath)
+ os.tryrm(filepath, opt)
+ elseif kind == "rmdir" then
+ local dir = path.join(archivedir, cmd.dir)
+ if os.isdir(dir) then
+ os.tryrm(dir, opt)
+ end
+ elseif kind == "mv" then
+ local srcpath = cmd.srcpath
+ local dstpath = path.join(archivedir, cmd.dstpath)
+ os.vmv(srcpath, dstpath, opt)
+ elseif kind == "cd" then
+ local dir = path.join(archivedir, cmd.dir)
+ os.cd(dir)
+ elseif kind == "mkdir" then
+ local dir = path.join(archivedir, cmd.dir)
+ os.mkdir(dir)
+ end
+end
+
+-- run commands
+function _run_commands(package, cmds)
+ for _, cmd in ipairs(cmds) do
+ _run_command(package, cmd)
+ end
+end
+
-- pack archive package
function _pack_archive(package)
- local batchcmds_ = batchcmds.get_installcmds(package)
--- batchcmds_:runcmds()
+
+ -- do install
+ _run_commands(package, batchcmds.get_installcmds(package):cmds())
+
+ -- archive install files
+ local archivedir = _get_archivedir(package)
+ local archivefiles = os.files(path.join(archivedir, "**"))
+ archive.archive(package:outputfile(), archivefiles)
end
-function main(package, format)
+function main(package)
cprint("packing %s", package:outputfile())
_pack_archive(package)
end
diff --git a/xmake/plugins/pack/zip/main.lua b/xmake/plugins/pack/zip/main.lua
index b54e6bf8a..fe511bff9 100644
--- a/xmake/plugins/pack/zip/main.lua
+++ b/xmake/plugins/pack/zip/main.lua
@@ -22,5 +22,5 @@
import(".archive")
function main(package)
- archive(package, "zip")
+ archive(package)
end