diff options
| author | ruki <[email protected]> | 2020-06-13 14:29:57 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-06-13 14:29:57 +0800 |
| commit | d1f1fd32aeddf73071b06fbcab23856925a0017f (patch) | |
| tree | 3f7ee6d6f5127144a5acb64bab1a68fb720bfb79 | |
| parent | 531799191430f540502de732635f97879541cf3c (diff) | |
improve toolchain environment
| -rw-r--r-- | xmake/core/platform/environment.lua | 25 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 3 |
2 files changed, 28 insertions, 0 deletions
diff --git a/xmake/core/platform/environment.lua b/xmake/core/platform/environment.lua index f76568cb7..d3ff0a0fd 100644 --- a/xmake/core/platform/environment.lua +++ b/xmake/core/platform/environment.lua @@ -86,6 +86,18 @@ end -- enter the environment for the current platform function environment.enter(name) + + -- need enter? + local entered = environment._ENTERED or {} + environment._ENTERED = entered + if entered[name] then + entered[name] = entered[name] + 1 + return true + else + entered[name] = 1 + end + + -- do enter local maps = {toolchains = environment._enter_toolchains, run = environment._enter_run} local func = maps[name] if func then @@ -99,6 +111,19 @@ end -- leave the environment for the current platform function environment.leave(name) + + -- need leave? + local entered = environment._ENTERED or {} + if entered[name] then + entered[name] = entered[name] - 1 + end + if entered[name] == 0 then + entered[name] = nil + else + return true + end + + -- do leave local maps = {toolchains = environment._leave_toolchains, run = environment._leave_run} local func = maps[name] if func then diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 7ec19ca4a..fa400b5dd 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -39,6 +39,7 @@ local tool = require("tool/tool") local linker = require("tool/linker") local compiler = require("tool/compiler") local platform = require("platform/platform") +local environment = require("platform/environment") local language = require("language/language") local sandbox = require("sandbox/sandbox") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") @@ -1708,12 +1709,14 @@ function _instance:tool(toolkind) -- get program from target/toolchains if not program then local toolchains = self:toolchains() + environment.enter("toolchains") for idx, toolchain_inst in ipairs(toolchains) do program, toolname = toolchain_inst:tool(toolkind) if program then break end end + environment.leave("toolchains") end -- contain toolname? parse it, e.g. '[email protected]' |
