summaryrefslogtreecommitdiff
path: root/xmake/core/base/task.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2016-02-28 20:19:07 +0800
committerruki <[email protected]>2016-02-28 20:19:07 +0800
commita69f2cbab10ea8adaea09a5e883188cbd083707a (patch)
tree8f8ebda0766691629c67da3629e13ff61e426909 /xmake/core/base/task.lua
parent966e75a551a01d5058edd1b4aa7cbb15f03b6a90 (diff)
run task
Diffstat (limited to 'xmake/core/base/task.lua')
-rw-r--r--xmake/core/base/task.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua
index 3c29a13fd..abdd40569 100644
--- a/xmake/core/base/task.lua
+++ b/xmake/core/base/task.lua
@@ -167,6 +167,62 @@ function task.tasks()
return tasks
end
+-- run task with given name
+function task.run(name)
+
+ -- check
+ assert(name)
+
+ -- load tasks
+ local tasks = task.tasks()
+ assert(tasks)
+
+ -- the interpreter
+ local interp = task._interpreter()
+ assert(interp)
+
+ -- get the task info
+ local taskinfo = tasks[name]
+ if not taskinfo then
+ utils.error("unknown task: %s", name)
+ return false
+ end
+
+ -- run on_before, on_run, on_after
+ local ok = true
+ 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
+ ok, errors = task._call(on_script)
+ if not ok then
+ utils.error(errors)
+ break
+ end
+ end
+ end
+
+ -- run on_failure if be failed?
+ if not ok and taskinfo.failure then
+
+ -- call it in the sandbox
+ ok, errors = task._call(taskinfo.failure)
+ if not ok then
+ utils.error(errors)
+ end
+
+ -- failed
+ ok = false
+ end
+
+ -- ok?
+ return ok
+end
+
-- the menu
function task.menu()