summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2021-05-12 06:14:58 +0800
committerGitHub <[email protected]>2021-05-12 06:14:58 +0800
commit29cf1854c5dd3ceedc4d89aa35ac6b100fd56571 (patch)
tree015571c7303b6659f69c5b37212f56f9f4a9f5c5 /xmake/modules
parent1a1b4ddb49c43103f3c498d74dbee267a210fad7 (diff)
parent2ddca09514cc56f66b1b6ede127c6284a6dade1b (diff)
Merge pull request #1405 from Phate6660/dev
add portage support
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/package/manager/find_package.lua5
-rw-r--r--xmake/modules/package/manager/install_package.lua1
-rw-r--r--xmake/modules/package/manager/portage/find_package.lua84
-rw-r--r--xmake/modules/package/manager/portage/install_package.lua74
4 files changed, 164 insertions, 0 deletions
diff --git a/xmake/modules/package/manager/find_package.lua b/xmake/modules/package/manager/find_package.lua
index 5d4307911..0f8013b9c 100644
--- a/xmake/modules/package/manager/find_package.lua
+++ b/xmake/modules/package/manager/find_package.lua
@@ -61,6 +61,11 @@ function _find_package_with_builtin_rule(package_name, opt)
table.insert(managers, "pacman")
end
+ -- find it from portage
+ if is_subhost("linux", "msys") and not is_plat("windows") and find_tool("emerge") then
+ table.insert(managers, "portage")
+ end
+
-- find it from pkg-config
table.insert(managers, "pkgconfig")
diff --git a/xmake/modules/package/manager/install_package.lua b/xmake/modules/package/manager/install_package.lua
index 735c4651f..1c5d5ab07 100644
--- a/xmake/modules/package/manager/install_package.lua
+++ b/xmake/modules/package/manager/install_package.lua
@@ -38,6 +38,7 @@ function _install_package(manager_name, package_name, opt)
table.insert(managers, "apt")
table.insert(managers, "yum")
table.insert(managers, "pacman")
+ table.insert(managers, "portage")
table.insert(managers, "brew")
elseif is_host("macosx") then
table.insert(managers, "vcpkg")
diff --git a/xmake/modules/package/manager/portage/find_package.lua b/xmake/modules/package/manager/portage/find_package.lua
new file mode 100644
index 000000000..f4b08a482
--- /dev/null
+++ b/xmake/modules/package/manager/portage/find_package.lua
@@ -0,0 +1,84 @@
+--!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 find_package.lua
+--
+
+-- imports
+import("core.base.option")
+import("lib.detect.find_tool")
+import("package.manager.pkgconfig.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 equery
+ local equery = find_tool("equery")
+ if not equery then
+ return
+ end
+
+ -- for msys2/mingw? mingw-w64-[i686|x86_64]-xxx
+ if opt.plat == "mingw" then
+ name = "mingw64-runtime" -- there is only one package for mingw
+ end
+
+ -- get package files list
+ -- gentoolkit package is required until I can do what it does in pure lua
+ local list = try { function() return os.iorunv(equery.program, {"f", name}) end }
+ if not list then
+ return
+ end
+
+ -- parse package files list
+ local pkgconfig_dir = nil
+ local pkgconfig_name = nil
+ local linkdirs = {}
+ local has_includes = false
+ for _, line in ipairs(list:split('\n', {plain = true})) do
+ line = line:trim():split('%s+')[1]
+ 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))
+ elseif line:find("/include/", 1, true) and (line:endswith(".h") or line:endswith(".hpp")) then
+ has_includes = true
+ end
+ end
+
+ -- find package
+ local result = nil
+ if pkgconfig_dir then
+ linkdirs = table.unique(linkdirs)
+ includedirs = table.unique(includedirs)
+ result = find_package_from_pkgconfig(pkgconfig_name or name, {configdirs = pkgconfig_dir, linkdirs = linkdirs})
+ if not result and has_includes then
+ -- header only and hidden /usr/include? we need only return empty {}
+ result = {}
+ end
+ end
+ return result
+end
diff --git a/xmake/modules/package/manager/portage/install_package.lua b/xmake/modules/package/manager/portage/install_package.lua
new file mode 100644
index 000000000..88b2aa61e
--- /dev/null
+++ b/xmake/modules/package/manager/portage/install_package.lua
@@ -0,0 +1,74 @@
+--!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 install_package.lua
+--
+
+-- imports
+import("core.base.option")
+import("lib.detect.find_tool")
+import("privilege.sudo")
+
+-- install package
+--
+-- @param name the package name
+-- @param opt the options, e.g. {verbose = true, emerge = "the package name"}
+--
+-- @return true or false
+--
+function main(name, opt)
+
+ -- init options
+ opt = opt or {}
+
+ -- find emerge
+ local emerge = find_tool("emerge")
+ if not emerge then
+ raise("emerge not found!")
+ end
+
+ -- for msys2/mingw? mingw-w64-[i686|x86_64]-xxx
+ if opt.plat == "mingw" then
+ name = "mingw64-runtime"
+ end
+
+ -- init argv
+ -- ask for confirmation, view tree of packages, verbose
+ -- it is set this way because Portage compiles from source
+ -- therefore it's better to have more info and ask for confirmation
+ -- that way the user can ensure they installed the package with the correct USE flags
+ local argv = {"-a", "-t", "-v", opt.emerge or name}
+ if opt.verbose or option.get("verbose") then
+ table.insert(argv, "-v")
+ end
+
+ -- install package directly if the current user is root
+ if is_subhost("msys") or os.isroot() then
+ os.vrunv(emerge.program, argv)
+ -- install with administrator permission?
+ elseif sudo.has() then
+
+ -- install it if be confirmed
+ local description = format("try installing %s with administrator permission", name)
+ local confirm = utils.confirm({default = true, description = description})
+ if confirm then
+ sudo.vrunv(emerge.program, argv)
+ end
+ else
+ raise("cannot get administrator permission!")
+ end
+end