diff options
| author | ruki <[email protected]> | 2024-11-22 11:13:30 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-11-22 11:13:30 +0800 |
| commit | 9b75cbbca9898bf38651bef1feb8caaaf56aaf7d (patch) | |
| tree | 9738f365524831048d74dfd10c32195c896b5135 /xmake/modules | |
| parent | 1047e8771aecbd210ad6c9106416bd80349fd7db (diff) | |
| parent | 7179682bed77d41936266527145276afc5562503 (diff) | |
Merge pull request #5855 from xmake-io/pacman
improve pacman packages
Diffstat (limited to 'xmake/modules')
4 files changed, 86 insertions, 33 deletions
diff --git a/xmake/modules/package/manager/pacman/configurations.lua b/xmake/modules/package/manager/pacman/configurations.lua new file mode 100644 index 000000000..a4930b9e3 --- /dev/null +++ b/xmake/modules/package/manager/pacman/configurations.lua @@ -0,0 +1,27 @@ +--!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 configurations.lua +-- + +-- get configurations +function main() + return { + msystem = {description = "Install pacman packages from the given msystem on msys2.", values = {"msys", "ucrt", "clang", "mingw"}} + } +end + diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua index 2a8244ff3..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) @@ -168,20 +169,8 @@ function main(name, opt) return end - -- for msys2/mingw? mingw-w64-[i686|x86_64]-xxx - if is_subhost("msys") and opt.plat == "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 = os.getenv("MSYSTEM") - if msystem and not msystem:startswith("MINGW") then - local i, j = msystem:find("%D+") - name = prefix .. msystem:sub(i, j):lower() .. "-" .. arch .. name - else - name = prefix .. arch .. name - 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..7c24c6bb6 --- /dev/null +++ b/xmake/modules/package/manager/pacman/get_package_name.lua @@ -0,0 +1,52 @@ +--!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 + if msystem ~= "mingw" then + name = prefix .. msystem .. "-" .. 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 a97df30ca..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,33 +32,17 @@ import("privilege.sudo") -- @return true or false -- function main(name, opt) - - -- init options opt = opt or {} - - -- find pacman local pacman = find_tool("pacman") if not pacman then raise("pacman not found!") end - -- for msys2/mingw? mingw-w64-[i686|x86_64]-xxx - if is_subhost("msys") and opt.plat == "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 = os.getenv("MSYSTEM") - if msystem and not msystem:startswith("MINGW") then - local i, j = msystem:find("%D+") - name = prefix .. msystem:sub(i, j):lower() .. "-" .. arch .. name - else - name = prefix .. arch .. name - end - end + -- get package name + name = get_package_name(name, opt) -- init argv - local argv = {"-Sy", "--noconfirm", "--needed", "--disable-download-timeout", opt.pacman or name} + local argv = {"-Sy", "--noconfirm", "--needed", "--disable-download-timeout", name} if opt.verbose or option.get("verbose") then table.insert(argv, "--verbose") end |
