summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-11-22 22:35:37 +0800
committerruki <[email protected]>2024-11-22 22:35:37 +0800
commit6f0b864cc68820f4b2500e1b82c21fb7a5619860 (patch)
treed367d2d4f3bca886f7542bd3ce26dbd30cf1f769
parent75d4f150fb9fddef4672a7793152b6fb2bbe621b (diff)
improve pacman package name
-rw-r--r--xmake/modules/package/manager/pacman/find_package.lua27
-rw-r--r--xmake/modules/package/manager/pacman/get_package_name.lua54
-rw-r--r--xmake/modules/package/manager/pacman/install_package.lua31
3 files changed, 60 insertions, 52 deletions
diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua
index a6362b1a3..d939192ec 100644
--- a/xmake/modules/package/manager/pacman/find_package.lua
+++ b/xmake/modules/package/manager/pacman/find_package.lua
@@ -24,6 +24,7 @@ import("core.project.target")
import("lib.detect.find_tool")
import("private.core.base.is_cross")
import("package.manager.pkgconfig.find_package", {alias = "find_package_from_pkgconfig"})
+import("get_package_name")
-- find package from list of file inside pacman package
function _find_package_from_list(list, name, pacman, opt)
@@ -158,7 +159,6 @@ end
--
function main(name, opt)
opt = opt or {}
- local configs = opt.configs or {}
if is_cross(opt.plat, opt.arch) then
return
end
@@ -169,29 +169,8 @@ function main(name, opt)
return
end
- -- for msys2
- if is_subhost("msys") then
- local msystem = configs.msystem
- if not msystem and opt.plat == "mingw" then
- msystem = "mingw"
- end
- -- mingw? mingw-w64-[i686|x86_64]-xxx
- if msystem == "mingw" then
- -- try to get the package prefix from the environment first
- -- https://www.msys2.org/docs/package-naming/
- local prefix = "mingw-w64-"
- local arch = (opt.arch == "x86_64" and "x86_64-" or "i686-")
- local msystem_env = os.getenv("MSYSTEM")
- if msystem_env and not msystem_env:startswith("MINGW") then
- local i, j = msystem_env:find("%D+")
- name = prefix .. msystem_env:sub(i, j):lower() .. "-" .. arch .. name
- else
- name = prefix .. arch .. name
- end
- else
- -- TODO other msystem, e.g. clang, msys, ucrt, ...
- end
- end
+ -- get package name
+ name = get_package_name(name, opt)
-- get package files list
local list = name and try { function() return os.iorunv(pacman.program, {"-Q", "-l", name}) end }
diff --git a/xmake/modules/package/manager/pacman/get_package_name.lua b/xmake/modules/package/manager/pacman/get_package_name.lua
new file mode 100644
index 000000000..b3a595f86
--- /dev/null
+++ b/xmake/modules/package/manager/pacman/get_package_name.lua
@@ -0,0 +1,54 @@
+--!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 get_package_name.lua
+--
+
+function main(name, opt)
+ opt = opt or {}
+ local configs = opt.configs or {}
+
+ -- https://www.msys2.org/docs/package-naming/
+ if is_subhost("msys") then
+ local msystem = configs.msystem
+ if not msystem and opt.plat == "mingw" then
+ msystem = "mingw"
+ end
+ if msystem == "mingw" or msystem == "ucrt" or msystem == "clang" then
+ local prefix = "mingw-w64-"
+ local arch = opt.arch
+ if arch == "x86" or arch == "i386" then
+ arch = "i686"
+ elseif arch == "x64" then
+ arch = "x86_64"
+ elseif arch == "arm64" then
+ arch = "aarch64"
+ end
+ local msystem_env = os.getenv("MSYSTEM")
+ if msystem_env and not msystem_env:startswith("MINGW") then
+ local i, j = msystem_env:find("%D+")
+ name = prefix .. msystem_env:sub(i, j):lower() .. "-" .. arch .. "-" .. name
+ else
+ name = prefix .. arch .. "-" .. name
+ end
+ else
+ -- msys packages, no prefix
+ end
+ end
+ return name
+end
+
diff --git a/xmake/modules/package/manager/pacman/install_package.lua b/xmake/modules/package/manager/pacman/install_package.lua
index 179fe1156..b1cb95937 100644
--- a/xmake/modules/package/manager/pacman/install_package.lua
+++ b/xmake/modules/package/manager/pacman/install_package.lua
@@ -22,6 +22,7 @@
import("core.base.option")
import("lib.detect.find_tool")
import("privilege.sudo")
+import("get_package_name")
-- install package
--
@@ -31,40 +32,14 @@ import("privilege.sudo")
-- @return true or false
--
function main(name, opt)
-
- -- get configs
opt = opt or {}
- local configs = opt.configs or {}
-
- -- find pacman
local pacman = find_tool("pacman")
if not pacman then
raise("pacman not found!")
end
- -- for msys2
- if is_subhost("msys") then
- local msystem = configs.msystem
- if not msystem and opt.plat == "mingw" then
- msystem = "mingw"
- end
- -- mingw? mingw-w64-[i686|x86_64]-xxx
- if msystem == "mingw" then
- -- try to get the package prefix from the environment first
- -- https://www.msys2.org/docs/package-naming/
- local prefix = "mingw-w64-"
- local arch = (opt.arch == "x86_64" and "x86_64-" or "i686-")
- local msystem_env = os.getenv("MSYSTEM")
- if msystem_env and not msystem_env:startswith("MINGW") then
- local i, j = msystem_env:find("%D+")
- name = prefix .. msystem_env:sub(i, j):lower() .. "-" .. arch .. name
- else
- name = prefix .. arch .. name
- end
- else
- -- TODO other msystem, e.g. clang, msys, ucrt, ...
- end
- end
+ -- get package name
+ name = get_package_name(name, opt)
-- init argv
local argv = {"-Sy", "--noconfirm", "--needed", "--disable-download-timeout", name}