diff options
| author | ruki <[email protected]> | 2021-02-21 18:06:12 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-02-21 18:06:12 +0800 |
| commit | 8f3845eb923737c9cb52b12adc79e8dded86e829 (patch) | |
| tree | 969e302966276ef98895a78b5881ac69f6628526 | |
| parent | 923489f49a9a83a5f1325ef84b48bb6e15d9972f (diff) | |
| parent | 7994b41cc05c77ceb7c26594b68e9dff9ac626c3 (diff) | |
Merge pull request #1248 from xmake-io/package
Improve find_package from external package sources
| -rw-r--r-- | xmake/core/package/package.lua | 53 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/pkgconfig.lua (renamed from xmake/modules/lib/detect/pkg_config.lua) | 24 | ||||
| -rw-r--r-- | xmake/modules/package/manager/brew/find_package.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/package/manager/find_package.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/package/manager/pacman/find_package.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/package/manager/pkgconfig/find_package.lua (renamed from xmake/modules/package/manager/pkg_config/find_package.lua) | 6 | ||||
| -rw-r--r-- | xmake/modules/package/manager/system/find_package.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/install_packages.lua | 16 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/install.lua | 16 |
9 files changed, 90 insertions, 41 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 7ea6461bb..745473bcd 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -198,6 +198,12 @@ function _instance:alias() end end +-- get external package sources, e.g. pkgconfig::xxx, system::xxx, conan::xxx +-- we can use it to improve self:fetch() for find_package +function _instance:extsources() + return self:get("extsources") +end + -- get urls function _instance:urls() return self._URLS or table.wrap(self:get("urls")) @@ -1063,11 +1069,18 @@ function _instance:fetch(opt) -- fetch it from the system directories if not fetchinfo and system ~= false then - fetchinfo = self._find_tool(self:name(), {cachekey = "fetch_package_system", - require_version = require_ver, - force = opt.force}) - if fetchinfo then - isSys = true + local fetchnames = {self:name()} + if not self:is3rd() then + table.join2(fetchnames, self:extsources()) + end + for _, fetchname in ipairs(fetchnames) do + fetchinfo = self._find_tool(fetchname, {cachekey = "fetch_package_system", + require_version = require_ver, + force = opt.force}) + if fetchinfo then + isSys = true + break + end end end else @@ -1088,18 +1101,25 @@ function _instance:fetch(opt) end end - -- fetch it from the system directories + -- fetch it from the system and external package sources if not fetchinfo and system ~= false then - fetchinfo = self._find_package(self:name(), {force = opt.force, - require_version = require_ver, - mode = self:mode(), - pkgconfigs = self:configs(), - buildhash = self:is3rd() and self:buildhash(), -- only for 3rd package manager, e.g. go:: .. - cachekey = "fetch_package_system", - external = external, - system = true}) - if fetchinfo then - isSys = true + local fetchnames = {self:name()} + if not self:is3rd() then + table.join2(fetchnames, self:extsources()) + end + for _, fetchname in ipairs(fetchnames) do + fetchinfo = self._find_package(fetchname, {force = opt.force, + require_version = require_ver, + mode = self:mode(), + pkgconfigs = self:configs(), + buildhash = self:is3rd() and self:buildhash(), -- only for 3rd package manager, e.g. go:: .. + cachekey = "fetch_package_system", + external = external, + system = true}) + if fetchinfo then + isSys = true + break + end end end end @@ -1511,6 +1531,7 @@ function package.apis() , "package.add_urls" , "package.add_imports" , "package.add_configs" + , "package.add_extsources" } , script = { diff --git a/xmake/modules/lib/detect/pkg_config.lua b/xmake/modules/lib/detect/pkgconfig.lua index f9e1e9aeb..98f9eae68 100644 --- a/xmake/modules/lib/detect/pkg_config.lua +++ b/xmake/modules/lib/detect/pkgconfig.lua @@ -15,7 +15,7 @@ -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki --- @file pkg_config.lua +-- @file pkgconfig.lua -- -- imports @@ -34,8 +34,8 @@ import("detect.tools.find_pkg_config") function version(name, opt) -- attempt to add search paths from pkg-config - local pkg_config = find_pkg_config() - if not pkg_config then + local pkgconfig = find_pkgconfig() + if not pkgconfig then return end @@ -50,7 +50,7 @@ function version(name, opt) end -- get version - local version = try { function() return os.iorunv(pkg_config, {"--modversion", name}) end } + local version = try { function() return os.iorunv(pkgconfig, {"--modversion", name}) end } if version then version = version:trim() end @@ -73,8 +73,8 @@ end function variables(name, variables, opt) -- attempt to add search paths from pkg-config - local pkg_config = find_pkg_config() - if not pkg_config then + local pkgconfig = find_pkgconfig() + if not pkgconfig then return end @@ -92,7 +92,7 @@ function variables(name, variables, opt) local result = nil if variables then for _, variable in ipairs(table.wrap(variables)) do - local value = try { function () return os.iorunv(pkg_config, {"--variable=" .. variable, name}) end } + local value = try { function () return os.iorunv(pkgconfig, {"--variable=" .. variable, name}) end } if value ~= nil then result = result or {} result[variable] = value:trim() @@ -118,15 +118,15 @@ end -- -- @code -- --- local libinfo = pkg_config.libinfo("openssl") +-- local libinfo = pkgconfig.libinfo("openssl") -- -- @endcode -- function libinfo(name, opt) -- attempt to add search paths from pkg-config - local pkg_config = find_pkg_config() - if not pkg_config then + local pkgconfig = find_pkg_config() + if not pkgconfig then return end @@ -142,7 +142,7 @@ function libinfo(name, opt) -- get libs and cflags local result = nil - local flags = try { function () return os.iorunv(pkg_config, {"--libs", "--cflags", name}) end } + local flags = try { function () return os.iorunv(pkgconfig, {"--libs", "--cflags", name}) end } if flags then -- init result @@ -172,7 +172,7 @@ function libinfo(name, opt) end -- get version - local version = try { function() return os.iorunv(pkg_config, {"--modversion", name}) end } + local version = try { function() return os.iorunv(pkgconfig, {"--modversion", name}) end } if version then result = result or {} result.version = version:trim() diff --git a/xmake/modules/package/manager/brew/find_package.lua b/xmake/modules/package/manager/brew/find_package.lua index df0737a06..f3677282a 100644 --- a/xmake/modules/package/manager/brew/find_package.lua +++ b/xmake/modules/package/manager/brew/find_package.lua @@ -22,7 +22,7 @@ import("lib.detect.find_tool") import("lib.detect.find_file") import("lib.detect.find_path") -import("lib.detect.pkg_config") +import("lib.detect.pkgconfig") import("core.project.target") import("package.manager.find_package") @@ -79,13 +79,13 @@ function main(name, opt) end if pcfile then opt.configdirs = path.directory(pcfile) - result = find_package("pkg_config::" .. pcname, opt) + result = find_package("pkgconfig::" .. pcname, opt) if not result then -- attempt to get includedir variable from pkg-config/xx.pc - local varinfo = pkg_config.variables(pcname, "includedir", opt) + local varinfo = pkgconfig.variables(pcname, "includedir", opt) if varinfo and varinfo.includedir then result = result or {} - result.version = pkg_config.version(pcname, opt) + result.version = pkgconfig.version(pcname, opt) result.includedirs = varinfo.includedir end end diff --git a/xmake/modules/package/manager/find_package.lua b/xmake/modules/package/manager/find_package.lua index 0f98106aa..f188d92d1 100644 --- a/xmake/modules/package/manager/find_package.lua +++ b/xmake/modules/package/manager/find_package.lua @@ -62,7 +62,7 @@ function _find_package_with_builtin_rule(package_name, opt) end -- find it from pkg-config - table.insert(managers, "pkg_config") + table.insert(managers, "pkgconfig") -- find it from system table.insert(managers, "system") diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua index b34f8eff0..ba5b58c21 100644 --- a/xmake/modules/package/manager/pacman/find_package.lua +++ b/xmake/modules/package/manager/pacman/find_package.lua @@ -21,7 +21,7 @@ -- imports import("core.base.option") import("lib.detect.find_tool") -import("package.manager.pkg_config.find_package", {alias = "find_package_from_pkgconfig"}) +import("package.manager.pkgconfig.find_package", {alias = "find_package_from_pkgconfig"}) -- find package from the system directories -- diff --git a/xmake/modules/package/manager/pkg_config/find_package.lua b/xmake/modules/package/manager/pkgconfig/find_package.lua index 752307e34..a7dbf377a 100644 --- a/xmake/modules/package/manager/pkg_config/find_package.lua +++ b/xmake/modules/package/manager/pkgconfig/find_package.lua @@ -19,7 +19,7 @@ -- -- imports -import("lib.detect.pkg_config") +import("lib.detect.pkgconfig") import("lib.detect.find_library") import("package.manager.system.find_package", {alias = "find_package_from_system"}) @@ -34,10 +34,10 @@ function main(name, opt) opt = opt or {} -- get library info - local libinfo = pkg_config.libinfo(name, opt) + local libinfo = pkgconfig.libinfo(name, opt) if not libinfo and name:startswith("lib") then -- libxxx? attempt to find xxx without `lib` prefix - libinfo = pkg_config.libinfo(name:sub(4), opt) + libinfo = pkgconfig.libinfo(name:sub(4), opt) end if not libinfo then return diff --git a/xmake/modules/package/manager/system/find_package.lua b/xmake/modules/package/manager/system/find_package.lua index 1298a3e5d..9bb04566d 100644 --- a/xmake/modules/package/manager/system/find_package.lua +++ b/xmake/modules/package/manager/system/find_package.lua @@ -22,7 +22,7 @@ import("lib.detect.find_file") import("lib.detect.find_path") import("lib.detect.find_library") -import("lib.detect.pkg_config") +import("lib.detect.pkgconfig") import("detect.sdks.find_xcode") import("core.project.config") @@ -148,7 +148,7 @@ function main(name, opt) local version = nil local links = table.wrap(opt.links) if #links == 0 then - pkginfo = pkg_config.libinfo(name) + pkginfo = pkgconfig.libinfo(name) if pkginfo then links = table.wrap(pkginfo.links) version = pkginfo.version diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index b7adf5400..08b54a80d 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -402,6 +402,20 @@ function _get_package_installdeps(packages) return installdeps end +-- should install? +function _should_install(instance) + if instance:parents() then + -- if all the packages that depend on it already exist, then there is no need to install it + for _, parent in ipairs(instance:parents()) do + if not parent:exists() then + return true + end + end + else + return not instance:exists() + end +end + -- install packages function main(requires, opt) @@ -437,7 +451,7 @@ function main(requires, opt) local packages_download = {} local packages_unsupported = {} for _, instance in ipairs(packages) do - if not instance:exists() then + if _should_install(instance) then if instance:supported() then if #instance:urls() > 0 then packages_download[tostring(instance)] = instance diff --git a/xmake/modules/private/action/require/install.lua b/xmake/modules/private/action/require/install.lua index 5750f4b0e..b93bc02fe 100644 --- a/xmake/modules/private/action/require/install.lua +++ b/xmake/modules/private/action/require/install.lua @@ -27,6 +27,20 @@ import("private.action.require.impl.environment") import("private.action.require.impl.install_packages") import("private.action.require.impl.utils.get_requires") +-- should install? +function _should_install(instance) + if instance:parents() then + -- if all the packages that depend on it already exist, then there is no need to install it + for _, parent in ipairs(instance:parents()) do + if not parent:exists() then + return true + end + end + else + return not instance:exists() + end +end + -- check missing packages function _check_missing_packages(packages) @@ -34,7 +48,7 @@ function _check_missing_packages(packages) local packages_missing = {} local optional_missing = {} for _, instance in ipairs(packages) do - if not instance:exists() then + if _should_install(instance) then if instance:optional() then optional_missing[instance:name()] = instance else |
