summaryrefslogtreecommitdiff
path: root/xmake/plugins/pack/srpm/main.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2023-12-15 23:56:05 +0800
committerruki <[email protected]>2023-12-15 23:56:05 +0800
commitbd85dc661e4cc386d27aa9cd855b91096b5b203c (patch)
treeeca01fc5eebe661f09dc4da6a1f4dd211ecb9d41 /xmake/plugins/pack/srpm/main.lua
parent86739912c5630ad7033b1d7f4c206489b6d201b0 (diff)
add srpm
Diffstat (limited to 'xmake/plugins/pack/srpm/main.lua')
-rw-r--r--xmake/plugins/pack/srpm/main.lua69
1 files changed, 69 insertions, 0 deletions
diff --git a/xmake/plugins/pack/srpm/main.lua b/xmake/plugins/pack/srpm/main.lua
new file mode 100644
index 000000000..e5368d2be
--- /dev/null
+++ b/xmake/plugins/pack/srpm/main.lua
@@ -0,0 +1,69 @@
+--!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("core.base.option")
+import("core.base.semver")
+import("lib.detect.find_tool")
+import("private.action.require.impl.packagenv")
+import("private.action.require.impl.install_packages")
+import(".batchcmds")
+
+-- get the rpmbuild
+function _get_rpmbuild()
+
+ -- enter the environments of rpmbuild
+ local oldenvs = packagenv.enter("rpm")
+
+ -- find rpmbuild
+ local packages = {}
+ local rpmbuild = find_tool("rpmbuild")
+ if not rpmbuild then
+ table.join2(packages, install_packages("rpm"))
+ end
+
+ -- enter the environments of installed packages
+ for _, instance in ipairs(packages) do
+ instance:envs_enter()
+ end
+
+ -- we need to force detect and flush detect cache after loading all environments
+ if not rpmbuild then
+ rpmbuild = find_tool("rpmbuild", {force = true})
+ end
+ assert(rpmbuild, "rpmbuild not found!")
+ return rpmbuild, oldenvs
+end
+
+function main(package)
+
+ if not is_host("linux") then
+ return
+ end
+
+ cprint("packing %s", package:outputfile())
+
+ -- get rpmbuild
+ local rpmbuild, oldenvs = _get_rpmbuild()
+
+
+ -- done
+ os.setenvs(oldenvs)
+end