summaryrefslogtreecommitdiff
path: root/xmake/scripts/tools
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-11 21:56:03 +0800
committerruki <[email protected]>2015-06-11 21:56:03 +0800
commitc2e614548b92821c8396e2a2e9f06afeb97cc7bd (patch)
treeea54e043c6f065fce7a778e459440d138a075b54 /xmake/scripts/tools
parent5198147b0b71e43883f4454eaabecfec9b8f9c74 (diff)
optimizate to find tool script
Diffstat (limited to 'xmake/scripts/tools')
-rw-r--r--xmake/scripts/tools/make.lua4
-rw-r--r--xmake/scripts/tools/tools.lua31
2 files changed, 24 insertions, 11 deletions
diff --git a/xmake/scripts/tools/make.lua b/xmake/scripts/tools/make.lua
index 3927aedb5..9deeebd2f 100644
--- a/xmake/scripts/tools/make.lua
+++ b/xmake/scripts/tools/make.lua
@@ -44,9 +44,9 @@ function make.main(self, mkfile, target)
-- make command
local cmd = nil
if mkfile and os.isfile(mkfile) then
- cmd = string.format("%s -j4 -f %s %s VERBOSE=%s 2> %s", self.name, mkfile, target or "", self._VERBOSE, xmake._NULDEV)
+ cmd = string.format("%s -f %s %s VERBOSE=%s 2> %s", self.name, mkfile, target or "", self._VERBOSE, xmake._NULDEV)
else
- cmd = string.format("%s -j4 %s VERBOSE=%s 2> %s", self.name, target or "", self._VERBOSE, xmake._NULDEV)
+ cmd = string.format("%s %s VERBOSE=%s 2> %s", self.name, target or "", self._VERBOSE, xmake._NULDEV)
end
-- done
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)