From dc4752465dfbfacb977f0fdcb459a1b077e940d6 Mon Sep 17 00:00:00 2001 From: ImperatorS79 Date: Thu, 19 Aug 2021 19:21:26 +0200 Subject: Update find_package.lua to handle multiple .pc files and no .pc files --- .../package/manager/pacman/find_package.lua | 131 ++++++++++++++++++--- 1 file changed, 113 insertions(+), 18 deletions(-) diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua index 4b2be0403..a31f4787a 100644 --- a/xmake/modules/package/manager/pacman/find_package.lua +++ b/xmake/modules/package/manager/pacman/find_package.lua @@ -40,8 +40,15 @@ function main(name, opt) end -- for msys2/mingw? mingw-w64-[i686|x86_64]-xxx + local cygpath = nil if 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 @@ -49,7 +56,7 @@ function main(name, opt) if not list then return end - + -- parse package files list local linkdirs = {} local has_includes = false @@ -65,28 +72,116 @@ function main(name, opt) has_includes = true end end - - -- get pkgconfig file - local pkgconfig_file = pkgconfig_files[name] - if not pkgconfig_file then - for _, file in pairs(pkgconfig_files) do - pkgconfig_file = file - break - end - end - - -- find package - local result = nil - if pkgconfig_file then + + -- we iterate over each pkgconfig file to extract the required data + local result = {} + local myIncludedirs = {} + local myLinkdirs = {} + local myLinks = {} + myVersion = "0" + local foundPC = false + for key, file in pairs(pkgconfig_files) do + 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) - result = find_package_from_pkgconfig(pkgconfig_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 = {} + local myResult = {} + myResult = find_package_from_pkgconfig(pkgconfig_name, {configdirs = pkgconfig_dir, linkdirs = linkdirs}) + + -- the pkgconfig file has been parse successfully + if myResult ~= nil then + for _, locIncludeDir in pairs(myResult.includedirs) do + table.insert(myIncludedirs, locIncludeDir) + end + + for _, locLinkDir in pairs(myResult.linkdirs) do + table.insert(myLinkdirs, locLinkDir) + end + + for _, locLink in pairs(myResult.links) do + table.insert(myLinks, locLink) + end + + -- version should be the same if a pacman package contains multiples .pc + myVersion = myResult.version + + foundPC = true + end + end + + if foundPC == true then + myIncludedirs = table.unique(myIncludedirs) + myLinkdirs = table.unique(myLinkdirs) + myLinks = table.unique(myLinks) + + result.includedirs = myIncludedirs + result.linkdirs = myLinkdirs + result.links = myLinks + result.version = myVersion + else -- if there is no .pc, we parse the package content to obtain the data we want + for _, line in ipairs(list:split('\n', {plain = true})) do -- on msys cygpath should be use 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 + hPath = os.iorunv(cygpath.program, {"--windows", line}) + end + table.insert(myIncludedirs, path.directory(hPath)) + if(opt.arch == "x86_64") then + local baseHPath = os.iorunv(cygpath.program, {"--windows", "/mingw64/include"}) + table.insert(myIncludedirs, baseHPath) + else + local baseHPath = os.iorunv(cygpath.program, {"--windows", "/mingw32/include"}) + table.insert(myIncludedirs, baseHPath) + end + -- revove lib and .a, .dll.a and .so to have the links + elseif line:endswith(".dll.a") then + local aPath = os.iorunv(cygpath.program, {"--windows", line}) + table.insert(myLinkdirs, path.directory(aPath)) + aPath = path.filename(aPath) + if aPath:startswith("lib") then + aPath = aPath:sub(4, aPath:len()) + end + table.insert(myLinks, aPath:sub(1, aPath:len() - 7)) + elseif line:endswith(".so") then + local aPath = line + table.insert(myLinkdirs, path.directory(aPath)) + aPath = path.filename(aPath) + if aPath:startswith("lib") then + aPath = aPath:sub(4, aPath:len()) + end + table.insert(myLinks, aPath:sub(1, aPath:len() - 4)) + elseif line:endswith(".a") then + local aPath = line + if opt.plat == "mingw" then + aPath = os.iorunv(cygpath.program, {"--windows", line}) + end + aPath = path.filename(aPath) + if aPath:startswith("lib") then + aPath = aPath:sub(4, aPath:len()) + end + table.insert(myLinks, aPath:sub(1, aPath:len() - 3)) + end end + + myLinkdirs = table.unique(myLinkdirs) + myLinks = table.unique(myLinks) + myIncludedirs = table.unique(myIncludedirs) + + -- use pacman package version as version + local myVersion = "0" + local nameVersion = try { function() return os.iorunv(pacman.program, {"-Q", name}) end } + if nameVersion then + myVersion = nameVersion:trim():split('%s+')[2] + end + + result = {} + result.includedirs = myIncludedirs + result.linkdirs = myLinkdirs + result.links = myLinks + result.version = myVersion end + return result end -- cgit v1.3.1 From a735ccb009c12980748b6ec497266dd03738795e Mon Sep 17 00:00:00 2001 From: ImperatorS79 Date: Fri, 20 Aug 2021 18:33:49 +0200 Subject: Update find_package.lua --- .../package/manager/pacman/find_package.lua | 178 +++++++++++---------- 1 file changed, 93 insertions(+), 85 deletions(-) diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua index a31f4787a..21340171b 100644 --- a/xmake/modules/package/manager/pacman/find_package.lua +++ b/xmake/modules/package/manager/pacman/find_package.lua @@ -23,6 +23,76 @@ import("core.base.option") 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) + local result = { + includedirs = {}, + linkdirs = {}, + links = {}, + version = nil + } + + -- 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 + hpath = os.iorunv(cygpath.program, {"--windows", line}) + + if(opt.arch == "x86_64") then + local basehpath = os.iorunv(cygpath.program, {"--windows", "/mingw64/include"}) + table.insert(result.includedirs, basehpath) + else + local basehpath = os.iorunv(cygpath.program, {"--windows", "/mingw32/include"}) + table.insert(result.includedirs, basehpath) + end + end + table.insert(result.includedirs, path.directory(hpath)) + -- revove lib and .a, .dll.a and .so to have the links + elseif line:endswith(".dll.a") then -- only for mingw + local apath = os.iorunv(cygpath.program, {"--windows", line}) + table.insert(result.linkdirs, path.directory(apath)) + apath = path.filename(apath) + if apath:startswith("lib") then + apath = apath:sub(4, apath:len()) + end + table.insert(result.links, apath:sub(1, apath:len() - 7)) + elseif line:endswith(".so") then + local apath = line + table.insert(result.linkdirs, path.directory(apath)) + apath = path.filename(apath) + if apath:startswith("lib") then + apath = apath:sub(4, apath:len()) + end + table.insert(result.links, apath:sub(1, apath:len() - 4)) + elseif line:endswith(".a") then + local apath = line + if opt.plat == "mingw" then + apath = os.iorunv(cygpath.program, {"--windows", line}) + end + table.insert(result.linkdirs, path.directory(apath)) + apath = path.filename(apath) + if apath:startswith("lib") then + apath = apath:sub(4, apath:len()) + end + 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] + end + + return result +end + -- find package from the system directories -- -- @param name the package name @@ -56,7 +126,7 @@ function main(name, opt) if not list then return end - + -- parse package files list local linkdirs = {} local has_includes = false @@ -74,113 +144,51 @@ function main(name, opt) end -- we iterate over each pkgconfig file to extract the required data - local result = {} - local myIncludedirs = {} - local myLinkdirs = {} - local myLinks = {} - myVersion = "0" + local result = { + includedirs = {}, + linkdirs = {}, + links = {}, + version = nil + } + local foundPC = false + for key, file in pairs(pkgconfig_files) do 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 myResult = {} - myResult = find_package_from_pkgconfig(pkgconfig_name, {configdirs = pkgconfig_dir, linkdirs = linkdirs}) + local pcresult = {} + pcresult = find_package_from_pkgconfig(pkgconfig_name, {configdirs = pkgconfig_dir, linkdirs = linkdirs}) -- the pkgconfig file has been parse successfully - if myResult ~= nil then - for _, locIncludeDir in pairs(myResult.includedirs) do - table.insert(myIncludedirs, locIncludeDir) + if pcresult ~= nil then + for _, locincludedir in pairs(pcresult.includedirs) do + table.insert(result.includedirs, locincludedir) end - for _, locLinkDir in pairs(myResult.linkdirs) do - table.insert(myLinkdirs, locLinkDir) + for _, loclinkdir in pairs(pcresult.linkdirs) do + table.insert(result.linkdirs, loclinkdir) end - for _, locLink in pairs(myResult.links) do - table.insert(myLinks, locLink) + for _, loclink in pairs(pcresult.links) do + table.insert(result.links, loclink) end -- version should be the same if a pacman package contains multiples .pc - myVersion = myResult.version + result.version = pcresult.version foundPC = true end end if foundPC == true then - myIncludedirs = table.unique(myIncludedirs) - myLinkdirs = table.unique(myLinkdirs) - myLinks = table.unique(myLinks) - - result.includedirs = myIncludedirs - result.linkdirs = myLinkdirs - result.links = myLinks - result.version = myVersion + 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 - for _, line in ipairs(list:split('\n', {plain = true})) do -- on msys cygpath should be use 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 - hPath = os.iorunv(cygpath.program, {"--windows", line}) - end - table.insert(myIncludedirs, path.directory(hPath)) - if(opt.arch == "x86_64") then - local baseHPath = os.iorunv(cygpath.program, {"--windows", "/mingw64/include"}) - table.insert(myIncludedirs, baseHPath) - else - local baseHPath = os.iorunv(cygpath.program, {"--windows", "/mingw32/include"}) - table.insert(myIncludedirs, baseHPath) - end - -- revove lib and .a, .dll.a and .so to have the links - elseif line:endswith(".dll.a") then - local aPath = os.iorunv(cygpath.program, {"--windows", line}) - table.insert(myLinkdirs, path.directory(aPath)) - aPath = path.filename(aPath) - if aPath:startswith("lib") then - aPath = aPath:sub(4, aPath:len()) - end - table.insert(myLinks, aPath:sub(1, aPath:len() - 7)) - elseif line:endswith(".so") then - local aPath = line - table.insert(myLinkdirs, path.directory(aPath)) - aPath = path.filename(aPath) - if aPath:startswith("lib") then - aPath = aPath:sub(4, aPath:len()) - end - table.insert(myLinks, aPath:sub(1, aPath:len() - 4)) - elseif line:endswith(".a") then - local aPath = line - if opt.plat == "mingw" then - aPath = os.iorunv(cygpath.program, {"--windows", line}) - end - aPath = path.filename(aPath) - if aPath:startswith("lib") then - aPath = aPath:sub(4, aPath:len()) - end - table.insert(myLinks, aPath:sub(1, aPath:len() - 3)) - end - end - - myLinkdirs = table.unique(myLinkdirs) - myLinks = table.unique(myLinks) - myIncludedirs = table.unique(myIncludedirs) - - -- use pacman package version as version - local myVersion = "0" - local nameVersion = try { function() return os.iorunv(pacman.program, {"-Q", name}) end } - if nameVersion then - myVersion = nameVersion:trim():split('%s+')[2] - end - - result = {} - result.includedirs = myIncludedirs - result.linkdirs = myLinkdirs - result.links = myLinks - result.version = myVersion + result = _find_package_from_list(list, opt, cygpath) end return result -- cgit v1.3.1 From b525616516d318aef0f7282528f848b4e1cc673f Mon Sep 17 00:00:00 2001 From: ImperatorS79 Date: Sat, 21 Aug 2021 14:42:30 +0200 Subject: Update find_package.lua --- .../package/manager/pacman/find_package.lua | 65 +++++++++++----------- 1 file 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 -- cgit v1.3.1 From 8142e3e202f2d6152282eaf39f71fda0ca8ca64e Mon Sep 17 00:00:00 2001 From: ImperatorS79 Date: Sat, 21 Aug 2021 15:13:16 +0200 Subject: Update find_package.lua --- .../package/manager/pacman/find_package.lua | 29 ++++++---------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua index 848dec0ae..3429866fd 100644 --- a/xmake/modules/package/manager/pacman/find_package.lua +++ b/xmake/modules/package/manager/pacman/find_package.lua @@ -25,19 +25,14 @@ import("package.manager.pkgconfig.find_package", {alias = "find_package_from_pkg -- get result from list of file inside pacman package function _find_package_from_list(list, opt, name, pacman) - local result = { - includedirs = {}, - linkdirs = {}, - links = {}, - version = nil - } + local result = {includedirs = {}, linkdirs = {}, links = {}} 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 + return end end @@ -50,7 +45,7 @@ function _find_package_from_list(list, opt, name, pacman) hpath = os.iorunv(cygpath.program, {"--windows", line}) if opt.arch == "x86_64" then - local basehpath = os.iorunv(cygpath.program, {"--windows", "/mingw64/include"}) + local basehpath = os.iorunv(cygpath.program, {"--windows", "/mingw64/include"}) table.insert(result.includedirs, basehpath) else local basehpath = os.iorunv(cygpath.program, {"--windows", "/mingw32/include"}) @@ -147,34 +142,26 @@ function main(name, opt) has_includes = true end end + linkdirs = table.unique(linkdirs) -- we iterate over each pkgconfig file to extract the required data - local result = { - includedirs = {}, - linkdirs = {}, - links = {}, - version = nil - } + local result = {includedirs = {}, linkdirs = {}, links = {}} local foundpc = false - for key, file in pairs(pkgconfig_files) do - local pkgconfig_file = file + for key, pkgconfig_file in pairs(pkgconfig_files) do local pkgconfig_dir = path.directory(pkgconfig_file) local pkgconfig_name = path.basename(pkgconfig_file) - linkdirs = table.unique(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 + if pcresult then for _, locincludedir in ipairs(pcresult.includedirs) do table.insert(result.includedirs, locincludedir) - end - + end for _, loclinkdir in ipairs(pcresult.linkdirs) do table.insert(result.linkdirs, loclinkdir) end - for _, loclink in ipairs(pcresult.links) do table.insert(result.links, loclink) end -- cgit v1.3.1 From d75ef94efae5127831c7719308d6b1d9c3a49eb8 Mon Sep 17 00:00:00 2001 From: ImperatorS79 Date: Sat, 21 Aug 2021 15:18:33 +0200 Subject: FIx spelling --- xmake/modules/package/manager/pacman/find_package.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua index 3429866fd..5a9094a7f 100644 --- a/xmake/modules/package/manager/pacman/find_package.lua +++ b/xmake/modules/package/manager/pacman/find_package.lua @@ -53,7 +53,7 @@ function _find_package_from_list(list, opt, name, pacman) end end table.insert(result.includedirs, path.directory(hpath)) - -- revove lib and .a, .dll.a and .so to have the links + -- remove lib and .a, .dll.a and .so to have the links elseif line:endswith(".dll.a") then -- only for mingw local apath = os.iorunv(cygpath.program, {"--windows", line}) table.insert(result.linkdirs, path.directory(apath)) -- cgit v1.3.1