diff options
| author | ruki <[email protected]> | 2022-02-10 00:33:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-02-10 00:33:18 +0800 |
| commit | 763c2455abcde109ae9e9a8cbc8d0b81bbc68543 (patch) | |
| tree | 48ed436814d578e76525e229872c65e8b291b82e /xmake/core/tool/toolchain.lua | |
| parent | 6efa53d991361c262f514246db0f1d808d3b297a (diff) | |
save and load toolchain
Diffstat (limited to 'xmake/core/tool/toolchain.lua')
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index f4a511f0f..b20479c61 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -29,6 +29,7 @@ local utils = require("base/utils") local table = require("base/table") local global = require("base/global") local option = require("base/option") +local scopeinfo = require("base/scopeinfo") local interpreter = require("base/interpreter") local config = require("project/config") local memcache = require("cache/memcache") @@ -38,13 +39,14 @@ local sandbox = require("sandbox/sandbox") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance -function _instance.new(name, info, cachekey, configs) - local instance = table.inherit(_instance) - instance._NAME = name - instance._INFO = info - instance._CACHE = toolchain._localcache() - instance._CACHEKEY = cachekey - instance._CONFIGS = instance._CACHE:get(cachekey) or {} +function _instance.new(name, info, cachekey, is_builtin, configs) + local instance = table.inherit(_instance) + instance._NAME = name + instance._INFO = info + instance._IS_BUILTIN = is_builtin + instance._CACHE = toolchain._localcache() + instance._CACHEKEY = cachekey + instance._CONFIGS = instance._CACHE:get(cachekey) or {} for k, v in pairs(configs) do instance._CONFIGS[k] = v end @@ -162,6 +164,11 @@ function _instance:is_global() return self:config("__global") end +-- is builtin toolchain? it's not from local project +function _instance:is_builtin() + return self._IS_BUILTIN +end + -- get the run environments function _instance:runenvs() local runenvs = self._RUNENVS @@ -292,6 +299,11 @@ function _instance:packages() return packages or nil end +-- save toolchain to file +function _instance:savefile(filepath) + return io.save(filepath, self:info():info()) +end + -- on check (builtin) function _instance:_on_check() local on_check = self:info():get("check") @@ -603,7 +615,7 @@ function toolchain.load(name, opt) end -- save instance to the cache - instance = _instance.new(name, result, cachekey, opt) + instance = _instance.new(name, result, cachekey, true, opt) cache:set(cachekey, instance) return instance end @@ -630,11 +642,23 @@ function toolchain.load_withinfo(name, info, opt) end -- save instance to the cache - instance = _instance.new(name, info, cachekey, opt) + instance = _instance.new(name, info, cachekey, false, opt) cache:set(cachekey, instance) return instance end +-- load toolchain from file +function toolchain.load_fromfile(name, filepath, opt) + local fileinfo, errors = io.load(filepath) + if not fileinfo then + return nil, errors + end + local scope_opt = {interpreter = toolchain._interpreter(), deduplicate = true, enable_filter = true} + local info = scopeinfo.new("toolchain", fileinfo, scope_opt) + return toolchain.load_withinfo(name, info, opt) +end + + -- get the program and name of the given tool kind function toolchain.tool(toolchains, toolkind, opt) |
