summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-12-22 12:29:35 +0800
committerGitHub <[email protected]>2023-12-22 12:29:35 +0800
commit59d2e638b29858f34647de156ac8a699196acb64 (patch)
tree7f3d725b78ffc0486e7fc02e429be143cbbb9b6c
parent17733b58e60dbc2729de94c17aedf48d6495136c (diff)
parent80937fbe6cf18a5372cdadb012a92ffc3985719b (diff)
Merge pull request #4529 from xmake-io/srpm
pack xmake install to srpm
-rw-r--r--core/xpack.lua2
-rw-r--r--tests/plugins/pack/xmake.lua2
-rw-r--r--xmake/includes/xpack/xmake.lua2
-rw-r--r--xmake/plugins/pack/batchcmds.lua27
-rw-r--r--xmake/plugins/pack/rpm/main.lua26
-rw-r--r--xmake/plugins/pack/srpm/main.lua22
-rw-r--r--xmake/plugins/pack/xmake.lua2
-rw-r--r--xmake/plugins/pack/xpack.lua7
8 files changed, 75 insertions, 15 deletions
diff --git a/core/xpack.lua b/core/xpack.lua
index f8a1726cc..94e21f7a2 100644
--- a/core/xpack.lua
+++ b/core/xpack.lua
@@ -127,6 +127,6 @@ xpack("xmakesrc")
if format == "runself" then
batchcmds:runv("./scripts/get.sh", {"__local__"})
elseif format == "srpm" then
- batchcmds:runv("make", {"install", "PREFIX=%{buildroot}"})
+ batchcmds:runv("make", {"install", path(package:install_rootdir(), function (p) return "PREFIX=" .. p end)})
end
end)
diff --git a/tests/plugins/pack/xmake.lua b/tests/plugins/pack/xmake.lua
index fc45c7fad..1ce179b33 100644
--- a/tests/plugins/pack/xmake.lua
+++ b/tests/plugins/pack/xmake.lua
@@ -19,7 +19,7 @@ target("foo")
add_packages("zlib")
xpack("test")
- set_formats("nsis", "srpm", "zip", "targz", "srczip", "srctargz", "runself")
+ set_formats("nsis", "srpm", "rpm", "zip", "targz", "srczip", "srctargz", "runself")
set_title("hello")
set_author("ruki")
set_description("A test installer.")
diff --git a/xmake/includes/xpack/xmake.lua b/xmake/includes/xpack/xmake.lua
index 5b8580172..83731fcd2 100644
--- a/xmake/includes/xpack/xmake.lua
+++ b/xmake/includes/xpack/xmake.lua
@@ -46,7 +46,7 @@ local apis = {
"xpack.set_copyright",
-- set company name
"xpack.set_company",
- -- set package formats, e.g. nsis, deb, srpm, targz, zip, srctargz, srczip, runself, ...
+ -- set package formats, e.g. nsis, deb, srpm, rpm, targz, zip, srctargz, srczip, runself, ...
-- we can also add custom formats
"xpack.set_formats",
-- set the base name of the output file
diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua
index 2403b5bca..3d9229cce 100644
--- a/xmake/plugins/pack/batchcmds.lua
+++ b/xmake/plugins/pack/batchcmds.lua
@@ -183,15 +183,25 @@ function _on_target_installcmd_headeronly(target, batchcmds_, opt)
_install_headers(target, batchcmds_, includedir)
end
+-- on install source target command
+function _on_target_installcmd_source(target, batchcmds_, opt)
+ local package = opt.package
+ batchcmds_:vrunv("xmake", {"install", "-o", path(package:install_rootdir()), target:name()})
+end
+
-- on build target command
function _on_target_buildcmd(target, batchcmds_, opt)
local package = opt.package
- batchcmds_:vrunv("xmake", {"build", target:name()})
+ batchcmds_:vrunv("xmake", {"build", "-y", target:name()})
end
-- on install target command
function _on_target_installcmd(target, batchcmds_, opt)
local package = opt.package
+ if package:from_source() then
+ _on_target_installcmd_source(target, batchcmds_, opt)
+ return
+ end
-- install target binaries
local scripts = {
@@ -278,9 +288,18 @@ function _on_target_uninstallcmd_headeronly(target, batchcmds_, opt)
_uninstall_headers(target, batchcmds_, includedir)
end
+-- on uninstall source target command
+function _on_target_uninstallcmd_source(target, batchcmds_, opt)
+ -- TODO
+end
+
-- on uninstall target command
function _on_target_uninstallcmd(target, batchcmds_, opt)
local package = opt.package
+ if package:from_source() then
+ _on_target_uninstallcmd_source(target, batchcmds_, opt)
+ return
+ end
-- uninstall target binaries
local scripts = {
@@ -412,9 +431,6 @@ end
-- on install command
function _on_installcmd(package, batchcmds_)
- if not package:from_binary() then
- return
- end
local srcfiles, dstfiles = package:installfiles()
for idx, srcfile in ipairs(srcfiles) do
batchcmds_:cp(srcfile, dstfiles[idx])
@@ -426,9 +442,6 @@ end
-- on uninstall command
function _on_uninstallcmd(package, batchcmds_)
- if not package:from_binary() then
- return
- end
local _, dstfiles = package:installfiles()
for _, dstfile in ipairs(dstfiles) do
batchcmds_:rm(dstfile, {emptydirs = true})
diff --git a/xmake/plugins/pack/rpm/main.lua b/xmake/plugins/pack/rpm/main.lua
new file mode 100644
index 000000000..39b5a172e
--- /dev/null
+++ b/xmake/plugins/pack/rpm/main.lua
@@ -0,0 +1,26 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file main.lua
+--
+
+-- imports
+import(".srpm")
+
+function main(package)
+ srpm(package)
+end
diff --git a/xmake/plugins/pack/srpm/main.lua b/xmake/plugins/pack/srpm/main.lua
index 2c9a0cb1b..b6b5467c8 100644
--- a/xmake/plugins/pack/srpm/main.lua
+++ b/xmake/plugins/pack/srpm/main.lua
@@ -23,6 +23,7 @@ import("core.base.option")
import("core.base.semver")
import("core.base.hashset")
import("lib.detect.find_tool")
+import("lib.detect.find_file")
import("utils.archive")
import("private.action.require.impl.packagenv")
import("private.action.require.impl.install_packages")
@@ -99,7 +100,16 @@ function _get_customcmd(package, installcmds, cmd)
local dir = _translate_filepath(package, cmd.dir)
table.insert(installcmds, string.format("mkdir -p \"%s\"", dir))
elseif cmd.program then
- table.insert(installcmds, string.format("%s", os.args(table.join(cmd.program, cmd.argv))))
+ local argv = {}
+ for _, arg in ipairs(cmd.argv) do
+ if path.instance_of(arg) then
+ arg = arg:clone():set(_translate_filepath(package, arg:rawstr())):str()
+ elseif path.is_absolute(arg) then
+ arg = _translate_filepath(package, arg)
+ end
+ table.insert(argv, arg)
+ end
+ table.insert(installcmds, string.format("%s", os.args(table.join(cmd.program, argv))))
end
end
@@ -239,11 +249,19 @@ function _pack_srpm(rpmbuild, package)
os.tryrm(archivefile)
archive.archive(archivefile, archivefiles, {curdir = rootdir, compress = "best"})
- -- do pack
+ -- pack srpm package
os.vrunv(rpmbuild, {"-bs", specfile,
"--define", "_topdir " .. package:buildir(),
"--define", "_sourcedir " .. package:buildir(),
"--define", "_srcrpmdir " .. package:outputdir()})
+
+ -- pack rpm package
+ if package:format() == "rpm" then
+ local srpmfile = find_file("*.src.rpm", package:outputdir())
+ if srpmfile then
+ os.vrunv(rpmbuild, {"--rebuild", srpmfile, "--define", "_rpmdir " .. package:outputdir()})
+ end
+ end
end
function main(package)
diff --git a/xmake/plugins/pack/xmake.lua b/xmake/plugins/pack/xmake.lua
index 6ed3b6d3f..0afa83cff 100644
--- a/xmake/plugins/pack/xmake.lua
+++ b/xmake/plugins/pack/xmake.lua
@@ -32,7 +32,7 @@ task("pack")
"e.g.",
" - xmake pack -f nsis,deb,rpm",
"values:",
- values = {"nsis", "deb", "srpm", "runself", "targz", "zip", "srctargz", "srczip"}},
+ values = {"nsis", "deb", "srpm", "rpm", "runself", "targz", "zip", "srctargz", "srczip"}},
{},
{nil, "packages", "vs", nil, "The package names."}
}
diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua
index 5cf5f24f4..0eae84a7a 100644
--- a/xmake/plugins/pack/xpack.lua
+++ b/xmake/plugins/pack/xpack.lua
@@ -237,7 +237,8 @@ function xpack:inputkind()
srctargz = "source",
runself = "source",
deb = "source",
- srpm = "source"
+ srpm = "source",
+ rpm = "source"
}
inputkind = inputkinds[self:format()] or "binary"
end
@@ -362,6 +363,7 @@ function xpack:specfile()
local extensions = {
nsis = ".nsi",
srpm = ".spec",
+ rpm = ".spec",
runself = ".lsm"
}
local extension = extensions[self:format()] or ".spec"
@@ -380,7 +382,8 @@ function xpack:extension()
srctargz = ".tar.gz",
runself = ".gz.run",
deb = ".deb",
- srpm = ".src.rpm"
+ srpm = ".src.rpm",
+ rpm = ".rpm"
}
extension = extensions[self:format()] or ""
end