Skip to content

Commit

Permalink
Merge pull request #3778 from xmake-io/toolchain
Browse files Browse the repository at this point in the history
improve to pass toolchain in tools.xmake #3774
  • Loading branch information
waruqi committed May 26, 2023
2 parents 3bc1882 + d0c5ff9 commit 12013f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
20 changes: 19 additions & 1 deletion xmake/core/tool/toolchain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ function _instance:check()
return checkok
end

-- do load manually, it will call on_load()
function _instance:load()
self:_load()
end

-- check cross toolchain
function _instance:check_cross_toolchain()
return sandbox_module.import("toolchains.cross.check", {rootdir = os.programdir(), anonymous = true})(self)
Expand Down Expand Up @@ -311,7 +316,15 @@ end

-- save toolchain to file
function _instance:savefile(filepath)
return io.save(filepath, {name = self:name(), info = self:info():info(), cachekey = self:cachekey(), configs = self._CONFIGS})
if not self:_is_loaded() then
os.raise("we can only save toolchain(%s) after it has been loaded!", self:name())
end
-- we strip on_load/on_check scripts to solve some issues
-- @see https://github.com/xmake-io/xmake/issues/3774
local info = table.clone(self:info():info())
info.load = nil
info.check = nil
return io.save(filepath, {name = self:name(), info = info, cachekey = self:cachekey(), configs = self._CONFIGS})
end

-- on check (builtin)
Expand Down Expand Up @@ -349,6 +362,11 @@ function _instance:_load()
end
end

-- is loaded?
function _instance:_is_loaded()
return self:info():get("__loaded")
end

-- get the tool description from the tool kind
function _instance:_description(toolkind)
local descriptions = self._DESCRIPTIONS
Expand Down
19 changes: 12 additions & 7 deletions xmake/modules/package/tools/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,19 @@ function _get_package_toolchains_envs(package, opt)

-- pass custom toolchains definition in project
for _, toolchain_inst in ipairs(toolchains_custom) do
local toolchains_file = os.tmpfile()
dprint("passing toolchain(%s) to %s", toolchain_inst:name(), toolchains_file)
local ok, errors = toolchain_inst:savefile(toolchains_file)
if not ok then
raise("save toolchain failed, %s", errors or "unknown")
-- we must load it first
-- @see https://github.com/xmake-io/xmake/issues/3774
if toolchain_inst:check() then
toolchain_inst:load()
local toolchains_file = os.tmpfile()
dprint("passing toolchain(%s) to %s", toolchain_inst:name(), toolchains_file)
local ok, errors = toolchain_inst:savefile(toolchains_file)
if not ok then
raise("save toolchain failed, %s", errors or "unknown")
end
envs.XMAKE_TOOLCHAIN_DATAFILES = envs.XMAKE_TOOLCHAIN_DATAFILES or {}
table.insert(envs.XMAKE_TOOLCHAIN_DATAFILES, toolchains_file)
end
envs.XMAKE_TOOLCHAIN_DATAFILES = envs.XMAKE_TOOLCHAIN_DATAFILES or {}
table.insert(envs.XMAKE_TOOLCHAIN_DATAFILES, toolchains_file)
end
end
return envs
Expand Down

0 comments on commit 12013f5

Please sign in to comment.