summaryrefslogtreecommitdiff
path: root/xmake/modules/lib/detect/find_toolname.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-02-19 22:30:38 +0800
committerruki <[email protected]>2022-02-19 22:30:38 +0800
commit005a664f5b3ef7b833ab7b4afdb41583d56b6811 (patch)
tree8080d7acdc672cccbe428020c1e56dea2dcfb35a /xmake/modules/lib/detect/find_toolname.lua
parent43af40334dae383707c15ec731d515cd3ac6b834 (diff)
improve zig cc
Diffstat (limited to 'xmake/modules/lib/detect/find_toolname.lua')
-rw-r--r--xmake/modules/lib/detect/find_toolname.lua52
1 files changed, 31 insertions, 21 deletions
diff --git a/xmake/modules/lib/detect/find_toolname.lua b/xmake/modules/lib/detect/find_toolname.lua
index b7201ead8..912f0ee8a 100644
--- a/xmake/modules/lib/detect/find_toolname.lua
+++ b/xmake/modules/lib/detect/find_toolname.lua
@@ -21,14 +21,42 @@
-- imports
import("core.sandbox.module")
--- find tool name from the given program
-function _find(program)
+-- find the the whole name
+function _find_with_whole_name(program)
-- attempt to find it directly first
if module.find("detect.tools.find_" .. program) then
return program
end
+ -- find the the whole name with spaces, e.g. "zig cc" -> zig_cc
+ local partnames = {}
+ local names = path.filename(program):lower():split("%s")
+ 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")
+ -- skip -arguments
+ if not name:startswith("-") then
+ table.insert(partnames, name)
+ end
+ end
+ local toolname = table.concat(partnames, "_")
+ if module.find("detect.tools.find_" .. toolname) then
+ return toolname
+ end
+end
+
+-- find tool name from the given program
+function _find(program)
+
+ -- find whole name first
+ local toolname = _find_with_whole_name(program)
+ if toolname then
+ return toolname
+ end
+
-- get file name first
name = path.filename(program):lower()
@@ -43,7 +71,7 @@ function _find(program)
-- remove suffix: ".xxx"
name = name:gsub("%.%w+", "")
- local toolname = name:gsub("[%+%-]", function (ch) return (ch == "+" and "x" or "_") end)
+ toolname = name:gsub("[%+%-]", function (ch) return (ch == "+" and "x" or "_") end)
if module.find("detect.tools.find_" .. toolname) then
return toolname
end
@@ -60,24 +88,6 @@ function _find(program)
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 = {}
- names = path.filename(program):lower():split("%s")
- 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")
- -- skip -arguments
- if not name:startswith("-") then
- table.insert(partnames, name)
- end
- end
- toolname = table.concat(partnames, "_")
- if module.find("detect.tools.find_" .. toolname) then
- return toolname
- end
end
-- find tool name