diff options
| author | ruki <[email protected]> | 2020-11-11 23:56:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-11-11 23:56:06 +0800 |
| commit | fc26a75e9566e93c70d9d0bd0340f60d266f5dbd (patch) | |
| tree | 1d9c0373081bd119837506ebbe386a6c44d44bba | |
| parent | 1c0b961dc0c2fd50be0c5d2676d362a5d38b0cf2 (diff) | |
support to find and install pacman package
| -rw-r--r-- | xmake/modules/package/manager/find_package.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/package/manager/pacman/find_package.lua | 70 | ||||
| -rw-r--r-- | xmake/modules/package/manager/pacman/install_package.lua | 2 |
3 files changed, 77 insertions, 1 deletions
diff --git a/xmake/modules/package/manager/find_package.lua b/xmake/modules/package/manager/find_package.lua index 11159ba85..879a9a6e9 100644 --- a/xmake/modules/package/manager/find_package.lua +++ b/xmake/modules/package/manager/find_package.lua @@ -22,6 +22,7 @@ import("core.base.semver") import("core.base.option") import("core.project.config") +import("lib.detect.find_tool") -- find package with the builtin rule -- @@ -55,6 +56,11 @@ function _find_package_with_builtin_rule(package_name, opt) -- only support the current sub-host platform and sub-architecture, e.g. linux, macosx, or msys (subsystem) if opt.plat == os.subhost() and opt.arch == os.subarch() then + -- find it from pacman + if is_subhost("linux", "msys") and find_tool("pacman") then + table.insert(managers, "pacman") + end + -- find it from pkg-config table.insert(managers, "pkg_config") diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua new file mode 100644 index 000000000..b2d211d53 --- /dev/null +++ b/xmake/modules/package/manager/pacman/find_package.lua @@ -0,0 +1,70 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_package.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_tool") +import("package.manager.pkg_config.find_package", {alias = "find_package_from_pkgconfig"}) + +-- find package from the system directories +-- +-- @param name the package name +-- @param opt the options, e.g. {verbose = true, version = "1.12.x") +-- +function main(name, opt) + + -- init options + opt = opt or {} + + -- find pacman + local pacman = find_tool("pacman") + if not pacman then + return + end + + -- get package files list + local list = try { function() return os.iorunv(pacman.program, {"-Q", "-l", name}) end } + if not list then + return + end + + -- parse package files list + local pkgconfig_dir = nil + local pkgconfig_name = nil + local linkdirs = {} + for _, line in ipairs(list:split('\n', {plain = true})) do + line = line:trim():split('%s+')[2] + if not pkgconfig_dir and line:find("/pkgconfig/", 1, true) and line:endswith(".pc") then + pkgconfig_dir = path.directory(line) + pkgconfig_name = path.basename(line) + end + if line:endswith(".so") or line:endswith(".a") or line:endswith(".lib") then + table.insert(linkdirs, path.directory(line)) + end + end + + -- find package + local result = nil + if pkgconfig_dir then + linkdirs = table.unique(linkdirs) + result = find_package_from_pkgconfig(pkgconfig_name or name, {configdirs = pkgconfig_dir, linkdirs = linkdirs}) + end + return result +end diff --git a/xmake/modules/package/manager/pacman/install_package.lua b/xmake/modules/package/manager/pacman/install_package.lua index a699a7622..941759a90 100644 --- a/xmake/modules/package/manager/pacman/install_package.lua +++ b/xmake/modules/package/manager/pacman/install_package.lua @@ -42,7 +42,7 @@ function main(name, opt) end -- init argv - local argv = {"-Sy", "--noconfirm", "--needed", opt.pacman or name} + local argv = {"-Sy", "--noconfirm", "--needed", "--disable-download-timeout", opt.pacman or name} if opt.verbose or option.get("verbose") then table.insert(argv, "--verbose") end |
