diff options
| author | ruki <[email protected]> | 2016-05-28 20:53:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-05-28 20:53:15 +0800 |
| commit | a686ee37d66f509ba01dbe10c2999c32e96c59db (patch) | |
| tree | 923949cbbd12ed5c99d54e83526fa9174b5da9ce | |
| parent | 7a0445c0612e9065461c1dff3eab6e992d742e4d (diff) | |
load tasks from project
| -rwxr-xr-x | xmake/actions/build/builder.lua | 2 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 1 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 36 | ||||
| -rw-r--r-- | xmake/core/project/task.lua | 16 |
4 files changed, 50 insertions, 5 deletions
diff --git a/xmake/actions/build/builder.lua b/xmake/actions/build/builder.lua index 33a1e47d2..bec34df86 100755 --- a/xmake/actions/build/builder.lua +++ b/xmake/actions/build/builder.lua @@ -223,7 +223,7 @@ function _make_target(target) for i = 1, 3 do local script = scripts[i] if script ~= nil then - return script(target) + script(target) end end end diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 89384dfb4..1152aee97 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -912,7 +912,6 @@ function interpreter:api_register_set_keyvalues(scope_kind, ...) -- update keyvalues? scope[name] = {} table.insert(scope[name], {...}) - end -- register implementation diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index a0114e730..a76756d08 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -330,8 +330,8 @@ function project._interpreter() -- set root scope interp:rootscope_set("target") - -- register api: target() and option() - interp:api_register_scope("target", "option") + -- register api: target(), option() and task() + interp:api_register_scope("target", "option", "task") -- register api: set_values() to target interp:api_register_set_values("target", "kind" @@ -445,6 +445,17 @@ function project._interpreter() -- register api: add_cxxfuncs() to target interp:api_register("target", "add_cxxfuncs", project._api_add_cxxfuncs) + -- register api: set_category() + -- + -- category: main, action, plugin, task (default) + interp:api_register_set_values("task", "category") + + -- register api: set_menu() + interp:api_register_set_values("task", "menu") + + -- register api: on_run() + interp:api_register_on_script("task", "run") + -- register api: is_xxx() to root interp:api_register(nil, "is_os", project._api_is_os) interp:api_register(nil, "is_kind", project._api_is_kind) @@ -680,7 +691,28 @@ function project.options(enable_filter) -- ok? return options +end + +-- get tasks +function project.tasks() + + -- get interpreter + local interp = project._interpreter() + assert(interp) + -- the project file is not found? + if not os.isfile(xmake._PROJECT_FILE) then + return {} + end + + -- load the tasks from the the project file + local results, errors = interp:load(xmake._PROJECT_FILE, "task", true, true) + if not results then + return nil, errors + end + + -- ok? + return results end -- get the mtimes diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua index 2bdc7c353..dd7eabf2c 100644 --- a/xmake/core/project/task.lua +++ b/xmake/core/project/task.lua @@ -33,6 +33,7 @@ local interpreter = require("base/interpreter") local sandbox = require("sandbox/sandbox") local global = require("project/global") local config = require("project/config") +local project = require("project/project") -- the directories of tasks function task._directories() @@ -164,7 +165,7 @@ function task._interpreter() -- register api: set_category() -- - -- category: main, action, plugin + -- category: main, action, plugin, task (default) interp:api_register_set_values("task", "category") -- register api: set_menu() @@ -346,7 +347,20 @@ function task.tasks() end end end + end + -- merge project tasks if exists + local projectasks, errors = project.tasks() + if projectasks then + for taskname, taskinfo in pairs(projectasks) do + if tasks[taskname] == nil then + tasks[taskname] = taskinfo + else + utils.warning("task(\"%s\") has been defined!", taskname) + end + end + else + os.raise(errors) end -- save it |
