summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorImperatorS79 <[email protected]>2021-08-21 14:42:30 +0200
committerGitHub <[email protected]>2021-08-21 14:42:30 +0200
commitb525616516d318aef0f7282528f848b4e1cc673f (patch)
tree3be2e9e93bdd54a5f5a6be9ddb250d4656a97056
parenta735ccb009c12980748b6ec497266dd03738795e (diff)
Update find_package.lua
-rw-r--r--xmake/modules/package/manager/pacman/find_package.lua65
1 files changed, 34 insertions, 31 deletions
diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua
index 21340171b..848dec0ae 100644
--- a/xmake/modules/package/manager/pacman/find_package.lua
+++ b/xmake/modules/package/manager/pacman/find_package.lua
@@ -24,7 +24,7 @@ import("lib.detect.find_tool")
import("package.manager.pkgconfig.find_package", {alias = "find_package_from_pkgconfig"})
-- get result from list of file inside pacman package
-function _find_package_from_list(list, opt, cygpath)
+function _find_package_from_list(list, opt, name, pacman)
local result = {
includedirs = {},
linkdirs = {},
@@ -32,15 +32,24 @@ function _find_package_from_list(list, opt, cygpath)
version = nil
}
+ local cygpath = nil
+ -- mingw + pacman = cygpath available
+ if is_subhost("msys") and opt.plat == "mingw" then
+ cygpath = find_tool("cygpath")
+ if not cygpath then
+ return nil
+ end
+ end
+
-- iterate over each file path inside the pacman package
for _, line in ipairs(list:split('\n', {plain = true})) do -- on msys cygpath should be used to convert local path to windows path
line = line:trim():split('%s+')[2]
if line:find("/include/", 1, true) and (line:endswith(".h") or line:endswith(".hpp")) then
local hpath = line
- if opt.plat == "mingw" then
+ if is_subhost("msys") and opt.plat == "mingw" then
hpath = os.iorunv(cygpath.program, {"--windows", line})
- if(opt.arch == "x86_64") then
+ if opt.arch == "x86_64" then
local basehpath = os.iorunv(cygpath.program, {"--windows", "/mingw64/include"})
table.insert(result.includedirs, basehpath)
else
@@ -68,7 +77,7 @@ function _find_package_from_list(list, opt, cygpath)
table.insert(result.links, apath:sub(1, apath:len() - 4))
elseif line:endswith(".a") then
local apath = line
- if opt.plat == "mingw" then
+ if is_subhost("msys") and opt.plat == "mingw" then
apath = os.iorunv(cygpath.program, {"--windows", line})
end
table.insert(result.linkdirs, path.directory(apath))
@@ -79,15 +88,18 @@ function _find_package_from_list(list, opt, cygpath)
table.insert(result.links, apath:sub(1, apath:len() - 3))
end
end
-
+
result.includedirs = table.unique(result.includedirs)
result.linkdirs = table.unique(result.linkdirs)
result.links = table.unique(result.links)
-
+
-- use pacman package version as version
local pacmanversion = try { function() return os.iorunv(pacman.program, {"-Q", name}) end }
if pacmanversion then
- result.version = pacmanversion:trim():split('%s+')[2]
+ pacmanversion = pacmanversion:trim():split('%s+')[2]
+ result.version = pacmanversion:split('-')[1]
+ else
+ result = nil
end
return result
@@ -110,23 +122,16 @@ function main(name, opt)
end
-- for msys2/mingw? mingw-w64-[i686|x86_64]-xxx
- local cygpath = nil
- if opt.plat == "mingw" then
+ if is_subhost("msys") and opt.plat == "mingw" then
name = (opt.arch == "x86_64" and "mingw-w64-x86_64-" or "mingw-w64-i686-") .. name
-
- -- mingw + pacman = cygpath available
- cygpath = find_tool("cygpath")
- if not cygpath then
- return
- end
end
-- get package files list
local list = try { function() return os.iorunv(pacman.program, {"-Q", "-l", name}) end }
if not list then
- return
+ return nil
end
-
+
-- parse package files list
local linkdirs = {}
local has_includes = false
@@ -150,45 +155,43 @@ function main(name, opt)
links = {},
version = nil
}
-
- local foundPC = false
-
+
+ local foundpc = false
+
for key, file in pairs(pkgconfig_files) do
- pkgconfig_file = file
+ local pkgconfig_file = file
local pkgconfig_dir = path.directory(pkgconfig_file)
local pkgconfig_name = path.basename(pkgconfig_file)
linkdirs = table.unique(linkdirs)
- includedirs = table.unique(includedirs)
- local pcresult = {}
- pcresult = find_package_from_pkgconfig(pkgconfig_name, {configdirs = pkgconfig_dir, linkdirs = linkdirs})
+ local pcresult = find_package_from_pkgconfig(pkgconfig_name, {configdirs = pkgconfig_dir, linkdirs = linkdirs})
-- the pkgconfig file has been parse successfully
if pcresult ~= nil then
- for _, locincludedir in pairs(pcresult.includedirs) do
+ for _, locincludedir in ipairs(pcresult.includedirs) do
table.insert(result.includedirs, locincludedir)
end
- for _, loclinkdir in pairs(pcresult.linkdirs) do
+ for _, loclinkdir in ipairs(pcresult.linkdirs) do
table.insert(result.linkdirs, loclinkdir)
end
- for _, loclink in pairs(pcresult.links) do
+ for _, loclink in ipairs(pcresult.links) do
table.insert(result.links, loclink)
end
-- version should be the same if a pacman package contains multiples .pc
result.version = pcresult.version
- foundPC = true
+ foundpc = true
end
end
-
- if foundPC == true then
+
+ if foundpc == true then
result.includedirs = table.unique(result.includedirs)
result.linkdirs = table.unique(result.linkdirs)
result.links = table.unique(result.links)
else -- if there is no .pc, we parse the package content to obtain the data we want
- result = _find_package_from_list(list, opt, cygpath)
+ result = _find_package_from_list(list, opt, name, pacman)
end
return result