summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-01-22 00:47:46 +0800
committerruki <[email protected]>2019-01-21 22:46:42 +0800
commitc92d87e3b872cd303356112a22190d4858a9fcb3 (patch)
tree2548a9efce857780c854a769239ab68249a6c792
parent8adc05268ed172871aef4a1b3c97dc8f2dcbd8f2 (diff)
cache find package result
-rw-r--r--xmake/core/sandbox/modules/dprint.lua27
-rw-r--r--xmake/core/sandbox/modules/dprintf.lua27
-rw-r--r--xmake/core/sandbox/modules/utils.lua14
-rw-r--r--xmake/modules/package/manager/find_package.lua67
-rw-r--r--xmake/modules/package/manager/install_package.lua7
5 files changed, 134 insertions, 8 deletions
diff --git a/xmake/core/sandbox/modules/dprint.lua b/xmake/core/sandbox/modules/dprint.lua
new file mode 100644
index 000000000..3d487a82e
--- /dev/null
+++ b/xmake/core/sandbox/modules/dprint.lua
@@ -0,0 +1,27 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file dprint.lua
+--
+
+-- load module
+return require("sandbox/modules/utils").dprint
+
diff --git a/xmake/core/sandbox/modules/dprintf.lua b/xmake/core/sandbox/modules/dprintf.lua
new file mode 100644
index 000000000..c1165f7bc
--- /dev/null
+++ b/xmake/core/sandbox/modules/dprintf.lua
@@ -0,0 +1,27 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file dprintf.lua
+--
+
+-- load module
+return require("sandbox/modules/utils").dprintf
+
diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua
index 3ed48f59f..c665ad072 100644
--- a/xmake/core/sandbox/modules/utils.lua
+++ b/xmake/core/sandbox/modules/utils.lua
@@ -157,6 +157,20 @@ function sandbox_utils.vprintf(format, ...)
end
end
+-- print the diagnosis information
+function sandbox_utils.dprint(format, ...)
+ if option.get("diagnosis") then
+ sandbox_utils.print(format, ...)
+ end
+end
+
+-- print the diagnosis information without newline
+function sandbox_utils.dprintf(format, ...)
+ if option.get("diagnosis") then
+ sandbox_utils.printf(format, ...)
+ end
+end
+
-- assert
function sandbox_utils.assert(value, format, ...)
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
diff --git a/xmake/modules/package/manager/install_package.lua b/xmake/modules/package/manager/install_package.lua
index aca5e9758..46eabf28c 100644
--- a/xmake/modules/package/manager/install_package.lua
+++ b/xmake/modules/package/manager/install_package.lua
@@ -23,7 +23,7 @@
--
-- install package
-function _install(manager_name, package_name, opt)
+function _install_package(manager_name, package_name, opt)
-- get managers
local managers = {}
@@ -45,7 +45,7 @@ function _install(manager_name, package_name, opt)
-- find package from the given package manager
for _, manager_name in ipairs(managers) do
- vprint("installing %s from %s ..", package_name, manager_name)
+ dprint("installing %s from %s ..", package_name, manager_name)
if import("package.manager." .. manager_name .. ".install_package", {anonymous = true})(package_name, opt) then
break
end
@@ -77,6 +77,5 @@ function main(name, opt)
opt.version = require_version or opt.version
-- do install package
- _install(manager_name, package_name, opt)
-
+ _install_package(manager_name, package_name, opt)
end