diff options
| author | ruki <[email protected]> | 2023-05-26 11:01:35 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-26 11:01:35 +0800 |
| commit | 12013f5eedc80d81dc4f7225a69e9a3cee807004 (patch) | |
| tree | d8d40c34fd258d4e9987b16a7b50322f71f2a02e | |
| parent | 3bc1882be93ab58f774322b74d19d2fe92bd09e5 (diff) | |
| parent | d0c5ff95b69965b3ef51d5f54544bd6d81e0d5f8 (diff) | |
Merge pull request #3778 from xmake-io/toolchain
improve to pass toolchain in tools.xmake #3774
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 20 | ||||
| -rw-r--r-- | xmake/modules/package/tools/xmake.lua | 19 |
2 files changed, 31 insertions, 8 deletions
diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 87a28cb69..b230bf674 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -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) @@ -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) @@ -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 diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index 0018128ef..e4a501b30 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -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 |
