Skip to content

Commit

Permalink
Merge pull request #4515 from xmake-io/rpm
Browse files Browse the repository at this point in the history
Support to pack srpm package
  • Loading branch information
waruqi authored Dec 21, 2023
2 parents 1597b1a + 16271a7 commit b9bcacc
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 7 deletions.
6 changes: 4 additions & 2 deletions tests/plugins/pack/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ target("foo")
add_packages("zlib")

xpack("test")
set_formats("nsis", "zip", "targz", "srczip", "srctargz", "runself")
set_formats("nsis", "srpm", "zip", "targz", "srczip", "srctargz", "runself")
set_title("hello")
set_author("ruki")
set_description("A test installer.")
set_homepage("https://xmake.io")
set_license("Apache-2.0")
set_licensefile("LICENSE.md")
add_targets("test", "foo")
add_installfiles("src/(assets/*.png)", {prefixdir = "images"})
add_sourcefiles("(src/**)")
add_sourcefiles("xmake.lua")
set_iconfile("src/assets/xmake.ico")
add_components("LongPath")

Expand All @@ -40,7 +42,7 @@ xpack("test")
end)

after_installcmd(function (package, batchcmds)
if package:from_source() then
if package:format() == "runself" then
batchcmds:runv("echo", {"hello"})
else
batchcmds:mkdir(package:installdir("resources"))
Expand Down
12 changes: 11 additions & 1 deletion xmake/includes/xpack/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ local apis = {
"xpack.set_copyright",
-- set company name
"xpack.set_company",
-- set package formats, e.g. nsis, deb, rpm, targz, zip, srctargz, srczip, runself, ...
-- set package formats, e.g. nsis, deb, srpm, targz, zip, srctargz, srczip, runself, ...
-- we can also add custom formats
"xpack.set_formats",
-- set the base name of the output file
Expand All @@ -65,6 +65,8 @@ local apis = {
"xpack.set_includedir",
-- set prefix directory, e.g. prefixdir/bin, prefixdir/lib ..
"xpack.set_prefixdir",
-- add build requires for source inputkind
"xpack.add_buildrequires",
-- set nsis display icon
"xpack.set_nsis_displayicon",
-- set package component title
Expand All @@ -79,6 +81,8 @@ local apis = {
"xpack.set_specfile",
-- set icon file path, e.g foo.ico
"xpack.set_iconfile",
-- set package license
"xpack.set_license",
-- set package license file, we will also get them from target
"xpack.set_licensefile",
-- add source files
Expand All @@ -99,6 +103,12 @@ local apis = {
"xpack.on_package",
-- add custom package script after packing package
"xpack.after_package",
-- add custom build commands script before building, it's only for source inputkind
"xpack.before_buildcmd",
-- add custom build commands script, it's only for source inputkind
"xpack.on_buildcmd",
-- add custom build commands script after building, it's only for source inputkind
"xpack.after_buildcmd",
-- add custom commands script before installing
"xpack.before_installcmd",
-- add custom commands script before uninstalling
Expand Down
68 changes: 68 additions & 0 deletions xmake/plugins/pack/batchcmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ function _on_target_installcmd_headeronly(target, batchcmds_, opt)
_install_headers(target, batchcmds_, includedir)
end

-- on build target command
function _on_target_buildcmd(target, batchcmds_, opt)
local package = opt.package
batchcmds_:vrunv("xmake", {"build", target:name()})
end

-- on install target command
function _on_target_installcmd(target, batchcmds_, opt)
local package = opt.package
Expand Down Expand Up @@ -295,6 +301,39 @@ function _on_target_uninstallcmd(target, batchcmds_, opt)
end
end

-- get build commands from targets
function _get_target_buildcmds(target, batchcmds_, opt)

-- call script to get build commands
local scripts = {
target:script("buildcmd_before"), -- TODO unused
function (target)
for _, r in ipairs(target:orderules()) do
local before_buildcmd = r:script("buildcmd_before")
if before_buildcmd then
before_buildcmd(target, batchcmds_, opt)
end
end
end,
target:script("buildcmd", _on_target_buildcmd), -- TODO unused
function (target)
for _, r in ipairs(target:orderules()) do
local after_buildcmd = r:script("buildcmd_after")
if after_buildcmd then
after_buildcmd(target, batchcmds_, opt)
end
end
end,
target:script("buildcmd_after") -- TODO unused
}
for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target, batchcmds_, opt)
end
end
end

-- get install commands from targets
function _get_target_installcmds(target, batchcmds_, opt)

Expand Down Expand Up @@ -361,6 +400,16 @@ function _get_target_uninstallcmds(target, batchcmds_, opt)
end
end

-- on build command
function _on_buildcmd(package, batchcmds_)
if not package:from_source() then
return
end
for _, target in ipairs(package:targets()) do
_get_target_buildcmds(target, batchcmds_, {package = package})
end
end

-- on install command
function _on_installcmd(package, batchcmds_)
if not package:from_binary() then
Expand Down Expand Up @@ -389,6 +438,25 @@ function _on_uninstallcmd(package, batchcmds_)
end
end

-- get build commands
function get_buildcmds(package)
local batchcmds_ = batchcmds.new()

-- call script to get build commands
local scripts = {
package:script("buildcmd_before"),
package:script("buildcmd", _on_buildcmd),
package:script("buildcmd_after")
}
for i = 1, 3 do
local script = scripts[i]
if script ~= nil then
script(package, batchcmds_)
end
end
return batchcmds_
end

-- get install commands
function get_installcmds(package)
local batchcmds_ = batchcmds.new()
Expand Down
Loading

0 comments on commit b9bcacc

Please sign in to comment.