summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-05-03 10:18:09 +0800
committerruki <[email protected]>2016-05-03 10:18:09 +0800
commit33cd1abcf4aa733ac68f619dac0183f547d787c3 (patch)
tree2c8f669eb26b8484654aa39efeea26d9ec84282f
parent6acc7c9d410f46d804a8f278badf14e7e99ea1be (diff)
fix find tool bug
-rw-r--r--xmake/core/base/interpreter.lua48
-rw-r--r--xmake/core/project/project.lua24
-rw-r--r--xmake/core/project/task.lua20
-rw-r--r--xmake/core/tool/tool.lua15
4 files changed, 86 insertions, 21 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 47b4d02a7..066acf5d9 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -756,6 +756,54 @@ function interpreter:api_register_on_script(scope_kind, prefix, ...)
self:_api_register_xxx_values(scope_kind, "on", prefix, implementation, ...)
end
+-- register api for before_script
+function interpreter:api_register_before_script(scope_kind, prefix, ...)
+
+ -- check
+ assert(self)
+
+ -- define implementation
+ local implementation = function (self, scope, name, script)
+
+ -- make sandbox instance with the given script
+ local instance, errors = sandbox.new(script, self:filter(), self:rootdir())
+ if not instance then
+ os.raise("before_%s(): %s", name, errors)
+ end
+
+ -- update script?
+ scope[name] = {}
+ table.insert(scope[name], instance:script())
+ end
+
+ -- register implementation
+ self:_api_register_xxx_values(scope_kind, "before", prefix, implementation, ...)
+end
+
+-- register api for after_script
+function interpreter:api_register_after_script(scope_kind, prefix, ...)
+
+ -- check
+ assert(self)
+
+ -- define implementation
+ local implementation = function (self, scope, name, script)
+
+ -- make sandbox instance with the given script
+ local instance, errors = sandbox.new(script, self:filter(), self:rootdir())
+ if not instance then
+ os.raise("after_%s(): %s", name, errors)
+ end
+
+ -- update script?
+ scope[name] = {}
+ table.insert(scope[name], instance:script())
+ end
+
+ -- register implementation
+ self:_api_register_xxx_values(scope_kind, "after", prefix, implementation, ...)
+end
+
-- register api for set_keyvalues
function interpreter:api_register_set_keyvalues(scope_kind, prefix, ...)
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index cc9072369..9c286aa40 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -379,6 +379,30 @@ function project._interpreter()
, "linkdirs"
, "includedirs")
+
+ -- register api: on_action() for target
+ interp.api_register_on_script(interp, "target", nil, "run"
+ , "build"
+ , "clean"
+ , "package"
+ , "install"
+ , "uninstall")
+
+ -- register api: before_action() for target
+ interp.api_register_before_script(interp, "target", nil, "run"
+ , "build"
+ , "clean"
+ , "package"
+ , "install"
+ , "uninstall")
+
+ -- register api: after_action() for target
+ interp.api_register_after_script(interp, "target", nil, "run"
+ , "build"
+ , "clean"
+ , "package"
+ , "install"
+ , "uninstall")
-- register api: set_option_values() for option
interp:api_register_set_values("option", "option", "enable"
diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua
index f095772b1..d695c9c83 100644
--- a/xmake/core/project/task.lua
+++ b/xmake/core/project/task.lua
@@ -382,24 +382,8 @@ function task.run(name)
return false, string.format("task(\"%s\"): no run script, please call on_task_run() first!", name)
end
- -- run on_before, on_run, on_after
- local on_scripts = {taskinfo.before, taskinfo.run, taskinfo.after}
- for i = 1, 3 do
-
- -- get script
- local on_script = on_scripts[i]
- if on_script then
-
- -- call it in the sandbox
- local ok, errors = sandbox.load(on_script)
- if not ok then
- return false, errors
- end
- end
- end
-
- -- ok
- return true
+ -- run task
+ return sandbox.load(taskinfo.run)
end
-- the menu
diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua
index 94a11f7ef..177df273c 100644
--- a/xmake/core/tool/tool.lua
+++ b/xmake/core/tool/tool.lua
@@ -54,9 +54,6 @@ function tool._match(name, toolname)
-- match the last word? ok
if name:find(toolname .. "$") then return 80 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 30 end
@@ -79,6 +76,18 @@ function tool._find(root, name)
-- remove arguments: -xxx or --xxx
name = (name:gsub("%s%-+%w+", " "))
+ -- get the last name by ' ': xxx xxx toolname
+ local names = name:split("%s+")
+ if #names > 0 then
+ name = names[#names]
+ end
+
+ -- get the last name by '-': xxx-xxx-toolname
+ local names = name:split("%-")
+ if #names > 0 then
+ name = names[#names]
+ end
+
-- remove suffix: ".xxx"
name = (name:gsub("%.%w+", ""))