summaryrefslogtreecommitdiff
path: root/xmake/scripts/tools/tools.lua
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/scripts/tools/tools.lua')
-rw-r--r--xmake/scripts/tools/tools.lua31
1 files changed, 22 insertions, 9 deletions
diff --git a/xmake/scripts/tools/tools.lua b/xmake/scripts/tools/tools.lua
index 9b5c457e2..9add7310c 100644
--- a/xmake/scripts/tools/tools.lua
+++ b/xmake/scripts/tools/tools.lua
@@ -34,16 +34,16 @@ local platform = require("platform/platform")
function tools._match(name, toolname)
-- match full? ok
- if name == toolname then return true end
+ if name == toolname then return 100 end
- -- match the full word? ok
- if name:find("^" .. toolname .. "$") then return true end
+ -- match the partial word? ok
+ if name:find("%-" .. toolname) then return 60 end
-- contains it? ok
- if name:find(toolname, 1, true) then return true end
+ if name:find(toolname, 1, true) then return 30 end
-- not matched
- return false
+ return 0
end
-- find tool from the given root directory and name
@@ -59,6 +59,8 @@ function tools._find_from(root, name)
name = name:lower()
-- get all tool files
+ local file_ok = nil
+ local score_maxn = 0
local files = os.match(string.format("%s/*.lua", root))
for _, file in ipairs(files) do
@@ -66,11 +68,24 @@ function tools._find_from(root, name)
local toolname = path.basename(file)
-- found it?
- if toolname and toolname ~= "tools" and tools._match(name, toolname:lower()) then
- return file
+ if toolname and toolname ~= "tools" then
+
+ -- match score
+ local score = tools._match(name, toolname:lower())
+
+ -- ok?
+ if score >= 100 then return file end
+
+ -- select the file with the max score
+ if score > score_maxn then
+ file_ok = file
+ score_maxn = score
+ end
end
end
+ -- ok?
+ return file_ok
end
-- probe it's absolute path if exists from the given tool name and root directory
@@ -89,8 +104,6 @@ function tools._probe(root, name)
end
end
-
-
-- find tool from the given name and directory (optional)
function tools.find(name, root)