summaryrefslogtreecommitdiff
path: root/xmake/plugins
diff options
context:
space:
mode:
authorruki <[email protected]>2023-12-18 22:39:48 +0800
committerruki <[email protected]>2023-12-18 22:39:48 +0800
commit9725c72f8834475640800ec1ac5315ac803cb0a0 (patch)
tree88e2aa72755d14161a2daff7eb7ad063d20c60f1 /xmake/plugins
parent4041150b168e3101197aede658014025dd676e1b (diff)
add srpm.spec
Diffstat (limited to 'xmake/plugins')
-rw-r--r--xmake/plugins/pack/srpm/main.lua68
-rw-r--r--xmake/plugins/pack/xpack.lua4
2 files changed, 71 insertions, 1 deletions
diff --git a/xmake/plugins/pack/srpm/main.lua b/xmake/plugins/pack/srpm/main.lua
index e5368d2be..7fd300c33 100644
--- a/xmake/plugins/pack/srpm/main.lua
+++ b/xmake/plugins/pack/srpm/main.lua
@@ -52,6 +52,72 @@ function _get_rpmbuild()
return rpmbuild, oldenvs
end
+-- get specvars
+function _get_specvars(package)
+ local specvars = table.clone(package:specvars())
+ return specvars
+end
+
+-- pack srpm package
+function _pack_srpm(rpmbuild, package)
+
+ -- install the initial specfile
+ local specfile = package:specfile()
+ if not os.isfile(specfile) then
+ local specfile_template = path.join(os.programdir(), "scripts", "xpack", "srpm", "srpm.spec")
+ os.cp(specfile_template, specfile)
+ end
+
+ -- replace variables in specfile
+ local specvars = _get_specvars(package)
+ local pattern = package:extraconf("specfile", "pattern") or "%${([^\n]-)}"
+ io.gsub(specfile, "(" .. pattern .. ")", function(_, name)
+ name = name:trim()
+ local value = specvars[name]
+ if type(value) == "function" then
+ value = value()
+ end
+ if value ~= nil then
+ dprint(" > replace %s -> %s", name, value)
+ end
+ if type(value) == "table" then
+ dprint("invalid variable value", value)
+ end
+ return value
+ end)
+
+ -- archive source files
+ local srcfiles, dstfiles = package:sourcefiles()
+ for idx, srcfile in ipairs(srcfiles) do
+ os.vcp(srcfile, dstfiles[idx])
+ end
+ for _, component in table.orderpairs(package:components()) do
+ if component:get("default") ~= false then
+ local srcfiles, dstfiles = component:sourcefiles()
+ for idx, srcfile in ipairs(srcfiles) do
+ os.vcp(srcfile, dstfiles[idx])
+ end
+ end
+ end
+
+ -- generate the setup.sh script
+ --[[
+ local sourcedir = package:sourcedir()
+ local setupfile = path.join(sourcedir, "__setup__.sh")
+ os.cp(path.join(os.programdir(), "scripts", "xpack", "srpm", "setup.sh"), setupfile)
+ local scriptfile = io.open(setupfile, "a+")
+ if scriptfile then
+ _write_installcmds(package, scriptfile, batchcmds.get_installcmds(package):cmds())
+ for _, component in table.orderpairs(package:components()) do
+ if component:get("default") ~= false then
+ _write_installcmds(package, scriptfile, batchcmds.get_installcmds(component):cmds())
+ end
+ end
+ scriptfile:close()
+ end]]
+
+end
+
function main(package)
if not is_host("linux") then
@@ -63,6 +129,8 @@ function main(package)
-- get rpmbuild
local rpmbuild, oldenvs = _get_rpmbuild()
+ -- pack srpm package
+ _pack_srpm(rpmbuild.program, package)
-- done
os.setenvs(oldenvs)
diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua
index 67216b928..4f9f01ad2 100644
--- a/xmake/plugins/pack/xpack.lua
+++ b/xmake/plugins/pack/xpack.lua
@@ -359,7 +359,9 @@ end
-- get the specfile path
function xpack:specfile()
local extensions = {
- nsis = ".nsi"
+ nsis = ".nsi",
+ srpm = ".spec",
+ runself = ".lsm"
}
local extension = extensions[self:format()] or ".spec"
return self:get("specfile") or path.join(self:buildir(), self:basename() .. extension)