diff options
| author | ruki <[email protected]> | 2017-06-29 14:53:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-06-29 14:53:25 +0800 |
| commit | dffe2441960d670eb8c7cc2e85a8106feb6ec86b (patch) | |
| tree | c7eaa188ac5d630d28a835e12952243dd4f9a7a0 /xmake/modules/lib/detect/has_flags.lua | |
| parent | fddddbc77525dd924117863c74f665ef53ed4663 (diff) | |
improve has_flags cache
Diffstat (limited to 'xmake/modules/lib/detect/has_flags.lua')
| -rw-r--r-- | xmake/modules/lib/detect/has_flags.lua | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua index f159e3103..f307fc40f 100644 --- a/xmake/modules/lib/detect/has_flags.lua +++ b/xmake/modules/lib/detect/has_flags.lua @@ -43,8 +43,17 @@ function _has_flag(name, flag, opt) -- init cache and key local key = tool.program .. "_" .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. "_" .. flag - local results = _g._RESULTS or {} + _g._RESULTS = _g._RESULTS or {} + local results = _g._RESULTS + -- @note avoid detect the same program in the same time if running in the coroutine (.e.g ccache) + local coroutine_running = coroutine.running() + if coroutine_running then + while _g._checking ~= nil and _g._checking == key do + coroutine.yield() + end + end + -- get result from the cache first local result = results[key] if result ~= nil then @@ -52,6 +61,7 @@ function _has_flag(name, flag, opt) end -- detect.tools.xxx.has_flag(flag, opt)? + _g._checking = ifelse(coroutine_running, key, nil) if os.isfile(path.join(os.programdir(), "modules", "detect", "tools", tool.name, "has_flag.lua")) then local hasflag = import("detect.tools." .. tool.name .. ".has_flag") if hasflag then @@ -60,15 +70,15 @@ function _has_flag(name, flag, opt) else result = try { function () os.runv(tool.program, {flag}); return true end } end + _g._checking = nil -- trace if option.get("verbose") or opt.verbose then - cprint("checking for the flags %s ... %s", flag, ifelse(result, "${green}ok", "${red}no")) + cprint("checking for the flags(%s) %s ... %s", path.filename(tool.program), flag, ifelse(result, "${green}ok", "${red}no")) end -- save result to cache results[key] = ifelse(result, result, false) - _g._RESULTS = results -- ok? return result |
