summaryrefslogtreecommitdiff
path: root/xmake/modules/lib/detect/find_toolname.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-01-25 22:39:15 +0800
committerruki <[email protected]>2021-01-25 22:39:15 +0800
commit22e78e33f6c3567228a1b8b4e1837171498ccab3 (patch)
treee33a88e9e8d2d2a12ab1564c46f57ed08121679a /xmake/modules/lib/detect/find_toolname.lua
parentfa171c502d6b20431af22321005024e593d4170d (diff)
support zig cc/c++
Diffstat (limited to 'xmake/modules/lib/detect/find_toolname.lua')
-rw-r--r--xmake/modules/lib/detect/find_toolname.lua32
1 files changed, 21 insertions, 11 deletions
diff --git a/xmake/modules/lib/detect/find_toolname.lua b/xmake/modules/lib/detect/find_toolname.lua
index 21b424fb7..d58010670 100644
--- a/xmake/modules/lib/detect/find_toolname.lua
+++ b/xmake/modules/lib/detect/find_toolname.lua
@@ -35,7 +35,7 @@ function _find(program)
-- remove arguments: " -xxx" or " --xxx"
name = name:gsub("%s%-+%w+", " ")
- -- get the last name by ' ': xxx xxx toolname
+ -- try the last name by ' ': xxx xxx toolname
local names = name:split("%s")
if #names > 0 then
name = names[#names]
@@ -43,14 +43,12 @@ function _find(program)
-- remove suffix: ".xxx"
name = name:gsub("%.%w+", "")
-
- -- find_toolname.lua exists? found
- local toolname = name:gsub("[%+%-]", function (ch) return ifelse(ch == "+", "x", "_") end)
+ local toolname = name:gsub("[%+%-]", function (ch) return (ch == "+" and "x" or "_") end)
if module.find("detect.tools.find_" .. toolname) then
return toolname
end
- -- get the last valid name: xxx-xxx-toolname-5
+ -- try last valid name: xxx-xxx-toolname-5
local partnames = {}
for partname in name:gmatch("([%a%+]+)") do
table.insert(partnames, partname)
@@ -58,18 +56,32 @@ function _find(program)
if #partnames > 0 then
name = partnames[#partnames]
end
-
- -- find_toolname.lua exists? found
toolname = name:gsub("%+", "x")
if module.find("detect.tools.find_" .. toolname) then
return toolname
end
+
+ -- try the the whole name with spaces, e.g. "zig cc" -> zig_cc
+ partnames = {}
+ for _, name in ipairs(names) do
+ -- remove suffix: ".exe", e.g. "zig.exe cc"
+ name = name:gsub("%.%w+", "")
+ -- "zig c++" -> zig_cxx
+ name = name:gsub("%+", "x")
+ table.insert(partnames, name)
+ end
+ toolname = table.concat(partnames, "_")
+ if module.find("detect.tools.find_" .. toolname) then
+ return toolname
+ end
end
-- find tool name
--
-- e.g.
-- "xcrun -sdk macosx clang": clang
+-- "zig cc": zig_cc
+-- "zig.exe c++": zig_c++
-- "/usr/bin/arm-linux-gcc": gcc
-- "link.exe -lib": link
-- "gcc-5": gcc
@@ -88,16 +100,14 @@ function main(program)
-- get it from the cache first
local toolname = toolnames[program]
if toolname ~= nil then
- return ifelse(toolname, toolname, nil)
+ return toolname and toolname or nil
end
-- find the tool name
toolname = _find(program)
-- save result to cache
- toolnames[program] = ifelse(toolname, toolname, false)
+ toolnames[program] = toolname and toolname or false
_g._TOOLNAMES = toolnames
-
- -- found?
return toolname
end