summaryrefslogtreecommitdiff
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
parent966e75a551a01d5058edd1b4aa7cbb15f03b6a90 (diff)
run task
-rw-r--r--xmake/core/base/main.lua47
-rw-r--r--xmake/core/base/task.lua56
2 files changed, 71 insertions, 32 deletions
diff --git a/xmake/core/base/main.lua b/xmake/core/base/main.lua
index e8f687e5d..560d14525 100644
--- a/xmake/core/base/main.lua
+++ b/xmake/core/base/main.lua
@@ -29,7 +29,6 @@ local path = require("base/path")
local task = require("base/task")
local utils = require("base/utils")
local option = require("base/option")
-local action = require("base/action")
-- init the option menu
local menu =
@@ -46,14 +45,10 @@ local menu =
}
-- done help
-function main._done_help()
-
- -- the options
- local options = option.options()
- assert(options)
+function main._help()
-- done help
- if options.help then
+ if option.get("help") then
-- print menu
option.print_menu(option.task())
@@ -62,16 +57,16 @@ function main._done_help()
return true
-- done version
- elseif options.version then
+ elseif option.get("version") then
-- print title
- if option._MENU.title then
- print(option._MENU.title)
+ if menu.title then
+ print(menu.title)
end
-- print copyright
- if option._MENU.copyright then
- print(option._MENU.copyright)
+ if menu.copyright then
+ print(menu.copyright)
end
-- ok
@@ -79,22 +74,6 @@ function main._done_help()
end
end
--- done option
-function main._done_option()
-
- -- the options
- local options = option.options()
- assert(options)
-
- -- done help?
- if main._done_help() then
- return true
- end
-
- -- done action
- return action.done(option.task() or "build")
-end
-
-- the init function for main
function main._init()
@@ -120,8 +99,6 @@ end
-- the main function
function main.done()
- task.tasks()
-
-- init
main._init()
@@ -130,8 +107,14 @@ function main.done()
return -1
end
- -- done option
- if not main._done_option() then
+ -- run help?
+ if main._help() then
+ return 1
+ end
+
+ -- run task
+ local ok = task.run(option.task() or "build")
+ if not ok then
return -1
end
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()