From 5704354222571b0ad4af27365ba57c1bd32d0112 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 21 Nov 2024 23:54:29 +0800 Subject: improve pacman packages --- .../package/manager/pacman/configurations.lua | 27 ++++++++++++++++++ .../package/manager/pacman/install_package.lua | 33 ++++++++++++++-------- 2 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 xmake/modules/package/manager/pacman/configurations.lua 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/install_package.lua b/xmake/modules/package/manager/pacman/install_package.lua index a97df30ca..046a37f51 100644 --- a/xmake/modules/package/manager/pacman/install_package.lua +++ b/xmake/modules/package/manager/pacman/install_package.lua @@ -32,8 +32,9 @@ import("privilege.sudo") -- function main(name, opt) - -- init options + -- get configs opt = opt or {} + local configs = opt.configs or {} -- find pacman local pacman = find_tool("pacman") @@ -42,22 +43,30 @@ function main(name, opt) 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 + if is_subhost("msys") then + local msystem = configs.msystem + if not msystem and opt.plat == "mingw" then + msystem = "mingw" + end + 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 - name = prefix .. arch .. name + -- TODO other msystem, e.g. clang, msys, ucrt, ... end end -- 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 -- cgit v1.3.1 From 75d4f150fb9fddef4672a7793152b6fb2bbe621b Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 Nov 2024 22:33:39 +0800 Subject: fix pacman.find_package --- .../package/manager/pacman/find_package.lua | 32 ++++++++++++++-------- .../package/manager/pacman/install_package.lua | 3 +- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua index 2a8244ff3..a6362b1a3 100644 --- a/xmake/modules/package/manager/pacman/find_package.lua +++ b/xmake/modules/package/manager/pacman/find_package.lua @@ -158,6 +158,7 @@ end -- function main(name, opt) opt = opt or {} + local configs = opt.configs or {} if is_cross(opt.plat, opt.arch) then return end @@ -168,18 +169,27 @@ 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 + -- 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 - name = prefix .. arch .. name + -- TODO other msystem, e.g. clang, msys, ucrt, ... end end diff --git a/xmake/modules/package/manager/pacman/install_package.lua b/xmake/modules/package/manager/pacman/install_package.lua index 046a37f51..179fe1156 100644 --- a/xmake/modules/package/manager/pacman/install_package.lua +++ b/xmake/modules/package/manager/pacman/install_package.lua @@ -42,12 +42,13 @@ function main(name, opt) raise("pacman not found!") end - -- for msys2/mingw? mingw-w64-[i686|x86_64]-xxx + -- 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/ -- cgit v1.3.1 From 6f0b864cc68820f4b2500e1b82c21fb7a5619860 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 Nov 2024 22:35:37 +0800 Subject: improve pacman package name --- .../package/manager/pacman/find_package.lua | 27 ++--------- .../package/manager/pacman/get_package_name.lua | 54 ++++++++++++++++++++++ .../package/manager/pacman/install_package.lua | 31 ++----------- 3 files changed, 60 insertions(+), 52 deletions(-) create mode 100644 xmake/modules/package/manager/pacman/get_package_name.lua 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} -- cgit v1.3.1 From 7179682bed77d41936266527145276afc5562503 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 Nov 2024 22:36:25 +0800 Subject: improve pacman package name again --- xmake/modules/package/manager/pacman/get_package_name.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/xmake/modules/package/manager/pacman/get_package_name.lua b/xmake/modules/package/manager/pacman/get_package_name.lua index b3a595f86..7c24c6bb6 100644 --- a/xmake/modules/package/manager/pacman/get_package_name.lua +++ b/xmake/modules/package/manager/pacman/get_package_name.lua @@ -38,10 +38,8 @@ function main(name, opt) 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 + if msystem ~= "mingw" then + name = prefix .. msystem .. "-" .. arch .. "-" .. name else name = prefix .. arch .. "-" .. name end -- cgit v1.3.1