Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve to pass toolchain in tools.xmake #3774 #3778

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading