summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-21 22:41:26 +0800
committerruki <[email protected]>2023-11-21 22:41:26 +0800
commitb07ccfbad1bf0ab942bf9247f09655c75f5cf199 (patch)
tree6e4a2afdc2afec5ad101f5246daf7836133fe0ef
parentd9bd4228a079cadf73092c1317a3a34717c6f3e6 (diff)
pack xmakesrc tar.gz and zip
-rw-r--r--core/xpack.lua48
-rw-r--r--xmake/includes/xpack/xmake.lua3
-rw-r--r--xmake/plugins/pack/xpack.lua22
3 files changed, 66 insertions, 7 deletions
diff --git a/core/xpack.lua b/core/xpack.lua
index a84c839d5..fb9c50264 100644
--- a/core/xpack.lua
+++ b/core/xpack.lua
@@ -69,3 +69,51 @@ xpack("xmake")
WriteRegDWORD ${HKLM} "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" 1
${EndIf}]], {description = "Increases the maximum path length limit, up to 32,767 characters (before 256)."})
+xpack("xmakesrc")
+ set_formats("src_zip", "src_targz")
+ set_basename("xmake-v$(version)")
+ on_load(function (package)
+ local format = package:format()
+ if format == "src_zip" then
+ package:set("extension", ".zip")
+ elseif format == "src_targz" then
+ package:set("extension", ".tar.gz")
+ end
+ end)
+ on_package(function (package)
+ import("devel.git")
+ import("utils.archive")
+ print("packing %s", package:outputfile())
+ local tmpdir = os.tmpfile() .. ".dir"
+ local repodir = path.join(tmpdir, "repo")
+ local srcdir = path.join(package:rootdir(), "xmakesrc")
+ local topdir = path.join(srcdir, "xmake-" .. package:version())
+ os.tryrm(repodir)
+ os.cp(path.directory(path.absolute(os.projectdir())), repodir)
+ git.clean({repodir = repodir, force = true, all = true})
+ git.reset({repodir = repodir, hard = true})
+ if os.isfile(path.join(repodir, ".gitmodules")) then
+ git.submodule.clean({repodir = repodir, force = true, all = true})
+ git.submodule.reset({repodir = repodir, hard = true})
+ end
+ os.mkdir(path.join(topdir, "scripts"))
+ os.vcp(path.join(repodir, "core"), topdir)
+ os.vcp(path.join(repodir, "xmake"), topdir)
+ os.vcp(path.join(repodir, "*.md"), topdir)
+ os.vcp(path.join(repodir, "configure"), topdir)
+ os.vcp(path.join(repodir, "scripts", "*.sh"), path.join(topdir, "scripts"))
+ os.vcp(path.join(repodir, "scripts", "man"), path.join(topdir, "scripts"))
+ os.vcp(path.join(repodir, "scripts", "debian"), path.join(topdir, "scripts"))
+ os.vcp(path.join(repodir, "scripts", "msys"), path.join(topdir, "scripts"))
+ os.rm(path.join(topdir, "core", "src", "tbox", "tbox", "src", "demo"))
+ os.rm(path.join(topdir, "core", "src", "luajit"))
+ os.rm(path.join(topdir, "core", "src", "pdcurses"))
+
+ -- archive files
+ local oldir = os.cd(srcdir)
+ local archivefiles = os.files("**")
+ os.cd(oldir)
+ archive.archive(path.absolute(package:outputfile()), archivefiles, {curdir = srcdir, compress = "best"})
+ os.tryrm(tmpdir)
+ end)
+
diff --git a/xmake/includes/xpack/xmake.lua b/xmake/includes/xpack/xmake.lua
index cbfedc600..3eb0d86cb 100644
--- a/xmake/includes/xpack/xmake.lua
+++ b/xmake/includes/xpack/xmake.lua
@@ -39,9 +39,12 @@ local apis = {
-- set company name
"xpack.set_company",
-- set package formats, e.g. nsis, deb, rpm, targz, zip, runself, ...
+ -- we can also add custom formats
"xpack.set_formats",
-- set the base name of the output file
"xpack.set_basename",
+ -- set the extension of the output file
+ "xpack.set_extension",
-- add targets to be packaged
"xpack.add_targets",
-- set installed binary directory, e.g. bin
diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua
index 0d6dd08f3..07e162c67 100644
--- a/xmake/plugins/pack/xpack.lua
+++ b/xmake/plugins/pack/xpack.lua
@@ -320,15 +320,23 @@ function xpack:specfile()
return self:get("specfile") or path.join(self:buildir(), self:basename() .. extension)
end
+-- get the extension
+function xpack:extension()
+ local extension = self:get("extension")
+ if extension == nil then
+ local extensions = {
+ nsis = ".exe",
+ zip = ".zip",
+ targz = ".tar.gz"
+ }
+ extension = extensions[self:format()] or ""
+ end
+ return extension
+end
+
-- get the output filename
function xpack:filename()
- local extensions = {
- nsis = ".exe",
- zip = ".zip",
- targz = ".tar.gz"
- }
- local extension = extensions[self:format()] or ""
- return self:basename() .. extension
+ return self:basename() .. self:extension()
end
-- get the output file