diff options
| author | ruki <[email protected]> | 2023-12-20 23:59:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-12-20 23:59:20 +0800 |
| commit | 1976625c2296c156511922d6792df6f2da8a1b23 (patch) | |
| tree | c3bdcbb69c75402508dca7a8755797111aa49d8b | |
| parent | 496c749bc97222b3c2607540407f4b617d02de38 (diff) | |
add buildcmds for srpm
| -rw-r--r-- | xmake/includes/xpack/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/plugins/pack/batchcmds.lua | 68 | ||||
| -rw-r--r-- | xmake/plugins/pack/srpm/main.lua | 17 | ||||
| -rw-r--r-- | xmake/scripts/xpack/srpm/srpm.spec | 1 |
4 files changed, 90 insertions, 2 deletions
diff --git a/xmake/includes/xpack/xmake.lua b/xmake/includes/xpack/xmake.lua index ad26db9c4..76df1a7b6 100644 --- a/xmake/includes/xpack/xmake.lua +++ b/xmake/includes/xpack/xmake.lua @@ -101,6 +101,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 diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua index af55cc707..2403b5bca 100644 --- a/xmake/plugins/pack/batchcmds.lua +++ b/xmake/plugins/pack/batchcmds.lua @@ -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 @@ -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) @@ -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 @@ -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() diff --git a/xmake/plugins/pack/srpm/main.lua b/xmake/plugins/pack/srpm/main.lua index 2b67ce40c..a65f3b4f6 100644 --- a/xmake/plugins/pack/srpm/main.lua +++ b/xmake/plugins/pack/srpm/main.lua @@ -64,7 +64,7 @@ function _translate_filepath(package, filepath) end -- get install command -function _get_installcmd(package, installcmds, cmd) +function _get_customcmd(package, installcmds, cmd) local opt = cmd.opt or {} local kind = cmd.kind if kind == "cp" then @@ -102,10 +102,17 @@ function _get_installcmd(package, installcmds, cmd) end end +-- get build commands +function _get_buildcmds(package, buildcmds, cmds) + for _, cmd in ipairs(cmds) do + _get_customcmd(package, buildcmds, cmd) + end +end + -- get install commands function _get_installcmds(package, installcmds, cmds) for _, cmd in ipairs(cmds) do - _get_installcmd(package, installcmds, cmd) + _get_customcmd(package, installcmds, cmd) end end @@ -132,6 +139,12 @@ function _get_specvars(package) package:set("prefixdir", prefixdir) return table.concat(installcmds, "\n") end + specvars.PACKAGE_BUILDCMDS = function () + local buildcmds = {} + _get_buildcmds(package, buildcmds, batchcmds.get_buildcmds(package):cmds()) + return table.concat(buildcmds, "\n") + end + return specvars end diff --git a/xmake/scripts/xpack/srpm/srpm.spec b/xmake/scripts/xpack/srpm/srpm.spec index 7c85eed34..d32052900 100644 --- a/xmake/scripts/xpack/srpm/srpm.spec +++ b/xmake/scripts/xpack/srpm/srpm.spec @@ -23,6 +23,7 @@ ${PACKAGE_DESCRIPTION} %autosetup -n ${PACKAGE_PREFIXDIR} -p1 %build +${PACKAGE_BUILDCMDS} %install ${PACKAGE_INSTALLCMDS} |
