diff options
| author | ruki <[email protected]> | 2019-01-22 00:47:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-01-21 22:46:42 +0800 |
| commit | c92d87e3b872cd303356112a22190d4858a9fcb3 (patch) | |
| tree | 2548a9efce857780c854a769239ab68249a6c792 /xmake/modules/package/manager/find_package.lua | |
| parent | 8adc05268ed172871aef4a1b3c97dc8f2dcbd8f2 (diff) | |
cache find package result
Diffstat (limited to 'xmake/modules/package/manager/find_package.lua')
| -rw-r--r-- | xmake/modules/package/manager/find_package.lua | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/xmake/modules/package/manager/find_package.lua b/xmake/modules/package/manager/find_package.lua index 3cf608ee3..bcade1f95 100644 --- a/xmake/modules/package/manager/find_package.lua +++ b/xmake/modules/package/manager/find_package.lua @@ -24,11 +24,12 @@ -- imports import("core.base.semver") +import("core.base.option") import("core.project.config") import("lib.detect.cache") -- find package -function _find(manager_name, package_name, opt) +function _find_package(manager_name, package_name, opt) -- get managers local managers = {} @@ -45,7 +46,7 @@ function _find(manager_name, package_name, opt) -- find package from the given package manager for _, manager_name in ipairs(managers) do - vprint("finding %s from %s ..", package_name, manager_name) + dprint("finding %s from %s ..", package_name, manager_name) local result = import("package.manager." .. manager_name .. ".find_package", {anonymous = true})(package_name, opt) if result then return result @@ -56,13 +57,29 @@ end -- find package using the package manager -- -- @param name the package name, e.g. zlib 1.12.x (try all), XMAKE::zlib 1.12.x, BREW::zlib, VCPKG::zlib, CONAN::OpenSSL/1.0.2n@conan/stable --- @param opt the options, .e.g {verbose = true, version = "1.12.x") +-- @param opt the options +-- e.g. { verbose = false, force = false, plat = "iphoneos", arch = "arm64", mode = "debug", version = "1.0.x", +-- linkdirs = {"/usr/lib"}, includedirs = "/usr/include", links = {"ssl"}, includes = {"ssl.h"} +-- packagedirs = {"/tmp/packages"}, system = true, cachekey = "xxxx"} -- +-- @return {links = {"ssl", "crypto", "z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} +-- +-- @code +-- +-- local package = find_package("openssl") +-- local package = find_package("openssl", {version = "1.0.*"}) +-- local package = find_package("openssl", {plat = "iphoneos"}) +-- local package = find_package("openssl", {linkdirs = {"/usr/lib", "/usr/local/lib"}, includedirs = "/usr/local/include", version = "1.0.1"}) +-- local package = find_package("openssl", {linkdirs = {"/usr/lib", "/usr/local/lib", links = {"ssl", "crypto"}, includes = {"ssl.h"}}) +-- +-- @endcode -- function main(name, opt) -- get the copied options opt = table.copy(opt) + opt.plat = opt.plat or config.get("plat") or os.host() + opt.arch = opt.arch or config.get("arch") or os.arch() -- get package manager name local manager_name, package_name = unpack(name:split("::", true)) @@ -78,6 +95,48 @@ function main(name, opt) package_name, require_version = unpack(package_name:trim():split("%s+")) opt.version = require_version or opt.version + -- init cache key + local key = "find_package_" .. opt.plat .. "_" .. opt.arch + if opt.version then + key = key .. "_" .. opt.version + end + if opt.cachekey then + key = key .. "_" .. opt.cachekey + end + if opt.mode then + key = key .. "_" .. opt.mode + end + + -- attempt to get result from cache first + local cacheinfo = cache.load(key) + local result = cacheinfo[package_name] + if result ~= nil and not opt.force then + return result and result or nil + end + + -- find package + result = _find_package(manager_name, package_name, opt) + + -- match version? + if opt.version and result then + if not result.version or not semver.satisfies(result.version, opt.version) then + result = nil + end + end + + -- cache result + cacheinfo[package_name] = result and result or false + cache.save(key, cacheinfo) + + -- trace + if opt.verbose or option.get("verbose") then + if result then + cprint("checking for the %s ... ${color.success}%s", package_name, result.version and result.version or "${text.success}") + else + cprint("checking for the %s ... ${color.nothing}${text.nothing}", package_name) + end + end - _find(manager_name, package_name, opt) + -- ok? + return result end |
