summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-02-14 09:27:05 +0800
committerruki <[email protected]>2021-02-14 09:27:05 +0800
commitd22832a1eaf691db8aae20d0d08f08a98a19d23b (patch)
tree62e380ec8212d918086334387b64a5649bcc2b8e
parentd99e19ac256c00f965b4f39c8f4243844393e256 (diff)
switch package toolchain
-rw-r--r--xmake/core/package/package.lua44
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua12
2 files changed, 54 insertions, 2 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 8aa492e40..ccb4fd9e0 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -35,6 +35,7 @@ local hashset = require("base/hashset")
local scopeinfo = require("base/scopeinfo")
local interpreter = require("base/interpreter")
local memcache = require("cache/memcache")
+local toolchain = require("tool/toolchain")
local sandbox = require("sandbox/sandbox")
local config = require("project/config")
local platform = require("platform/platform")
@@ -569,10 +570,10 @@ function _instance:build_envs(lazy_loading)
setmetatable(build_envs, { __index = function (tbl, key)
local value = config.get(key)
if value == nil then
- value = platform.toolconfig(key, self:plat())
+ value = self:toolconfig(key)
end
if value == nil then
- value = platform.tool(key, self:plat())
+ value = self:tool(key)
end
value = table.unique(table.join(table.wrap(value), self:config(key)))
if #value > 0 then
@@ -600,6 +601,45 @@ function _instance:build_envs(lazy_loading)
return build_envs
end
+-- get toolchains
+function _instance:toolchains()
+ local toolchains = self._TOOLCHAINS
+ if toolchains == nil then
+ for _, name in ipairs(table.wrap(self:config("toolchains"))) do
+ local toolchain_opt = {plat = self:plat(), arch = self:arch()}
+ local toolchain_inst, errors = toolchain.load(name, toolchain_opt)
+ if not toolchain_inst and os.isfile(os.projectfile()) then
+ toolchain_inst = require("base/project").toolchain(name, toolchain_opt)
+ end
+ if not toolchain_inst then
+ os.raise(errors)
+ end
+ toolchains = toolchains or {}
+ table.insert(toolchains, toolchain_inst)
+ end
+ self._TOOLCHAINS = toolchains or false
+ end
+ return toolchains or nil
+end
+
+-- get the program and name of the given tool kind
+function _instance:tool(toolkind)
+ if self:toolchains() then
+ return toolchain.tool(self:toolchains(), toolkind, {cachekey = "package", plat = self:plat(), arch = self:arch()})
+ else
+ return platform.tool(toolkind, self:plat(), self:arch())
+ end
+end
+
+-- get tool configuration from the toolchains
+function _instance:toolconfig(name)
+ if self:toolchains() then
+ return toolchain.toolconfig(self:toolchains(), name, {cachekey = "package", plat = self:plat(), arch = self:arch()})
+ else
+ return platform.toolconfig(name, self:plat(), self:arch())
+ end
+end
+
-- get the user private data
function _instance:data(name)
return self._DATA and self._DATA[name] or nil
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua
index a9a46d49b..f8ce349d9 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -91,6 +91,15 @@ function _patch_pkgconfig(package)
end
end
+-- check package toolchains
+function _check_package_toolchains(package)
+ for _, toolchain_inst in pairs(package:toolchains()) do
+ if not toolchain_inst:check() then
+ raise("toolchain(\"%s\"): not found!", toolchain_inst:name())
+ end
+ end
+end
+
-- install the given package
function main(package)
@@ -155,6 +164,9 @@ function main(package)
dep:envs_enter()
end
+ -- check package toolchains
+ _check_package_toolchains(package)
+
-- download package resources
download_resources(package)