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 | |
| parent | fddddbc77525dd924117863c74f665ef53ed4663 (diff) | |
improve has_flags cache
| -rw-r--r-- | xmake/modules/detect/tools/gcc/has_flag.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/has_flags.lua | 16 |
2 files changed, 15 insertions, 5 deletions
diff --git a/xmake/modules/detect/tools/gcc/has_flag.lua b/xmake/modules/detect/tools/gcc/has_flag.lua index 8b1f691ef..396c460e4 100644 --- a/xmake/modules/detect/tools/gcc/has_flag.lua +++ b/xmake/modules/detect/tools/gcc/has_flag.lua @@ -38,7 +38,7 @@ function _islinker(flag, opt) return toolkind == "ld" or toolkind == "sh" or toolkind:endswith("-ld") or toolkind:endswith("-sh") end --- attempt to check it from the argument list of gcc +-- attempt to check it from the argument list function _check_from_arglist(flag, opt, islinker) -- only for compiler @@ -108,7 +108,7 @@ function main(flag, opt) -- is linker? local islinker = _islinker(flag, opt) - -- attempt to check it from the argument list of gcc + -- attempt to check it from the argument list if _check_from_arglist(flag, opt, islinker) then return true end 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 |
