diff options
| author | ruki <[email protected]> | 2016-02-23 21:19:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-02-23 21:19:38 +0800 |
| commit | bd2b7e61c8053041aae4f54537641529d6c10d49 (patch) | |
| tree | 1e34a5f3c4ca553ae116882b2b2f84be90609577 /xmake/core/base/task.lua | |
| parent | 133ff2563a68b8265fafedb006bf07fce5ae280f (diff) | |
load tasks
Diffstat (limited to 'xmake/core/base/task.lua')
| -rw-r--r-- | xmake/core/base/task.lua | 62 |
1 files changed, 54 insertions, 8 deletions
diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua index d520e9a68..573d8d0d5 100644 --- a/xmake/core/base/task.lua +++ b/xmake/core/base/task.lua @@ -24,6 +24,7 @@ local task = task or {} -- load modules +local os = require("base/os") local table = require("base/table") local utils = require("base/utils") local string = require("base/string") @@ -64,25 +65,70 @@ function task._interpreter() return interp end --- load the given task from the given directory -function task._load_from(dir, taskname) - - -- the file path - local filepath = path.join(dir, taskname .. ".lua") +-- load the given task script file +function task._load(filepath) -- get interpreter local interp = task._interpreter() assert(interp) -- load task - local results, errors = interp:load(filepath, nil, true, true) - if not results then + local results, errors = interp:load(filepath, "task", true, true) + if not results and os.isfile(filepath) then -- trace utils.error(errors) - utils.abort() end + + -- is plugin? mark it + if path.basename(path.directory(filepath)) == "plugins" then + for _, v in pairs(results) do + v.plugin = true + end + end + + -- ok? + return results end +-- get all tasks +function task.tasks() + + -- return it directly if exists + if task._TASKS then + return task._TASKS + end + + -- load tasks + local tasks = {} + local dirs = task._directories() + for _, dir in ipairs(dirs) do + + -- get files + local files = os.match(path.join(dir, "*.lua")) + if files then + for _, filepath in ipairs(files) do + + -- load it + local results = task._load(filepath) + if results then + table.join2(tasks, results) + end + end + end + + end + + -- save it + task._TASKS = tasks + + -- ok? + return tasks +end + +-- the menu +function task.menu() + +end -- return module: task return task |
