summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-02-23 21:19:38 +0800
committerruki <[email protected]>2016-02-23 21:19:38 +0800
commitbd2b7e61c8053041aae4f54537641529d6c10d49 (patch)
tree1e34a5f3c4ca553ae116882b2b2f84be90609577
parent133ff2563a68b8265fafedb006bf07fce5ae280f (diff)
load tasks
-rw-r--r--xmake/core/base/interpreter.lua6
-rw-r--r--xmake/core/base/main.lua3
-rw-r--r--xmake/core/base/task.lua62
-rwxr-xr-xxmake/plugins/doxygen.lua2
-rwxr-xr-xxmake/plugins/macro.lua2
5 files changed, 66 insertions, 9 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 6b5abf568..e415bd590 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -347,7 +347,11 @@ function interpreter._make(self, scope_kind, remove_repeat, enable_filter)
-- the scopes
local scopes = self._PRIVATE._SCOPES
- assert(scopes and scopes._ROOT)
+
+ -- empty scope?
+ if not scopes or not scopes._ROOT then
+ return nil, string.format("the scope %s() is empty!", scope_kind)
+ end
-- make results
local results = {}
diff --git a/xmake/core/base/main.lua b/xmake/core/base/main.lua
index ad521700b..54008aa21 100644
--- a/xmake/core/base/main.lua
+++ b/xmake/core/base/main.lua
@@ -26,6 +26,7 @@ local main = main or {}
-- load modules
local os = require("base/os")
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")
@@ -158,6 +159,8 @@ end
-- the main function
function main.done()
+ task.tasks()
+
-- init
main._init()
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
diff --git a/xmake/plugins/doxygen.lua b/xmake/plugins/doxygen.lua
index d749ef674..69e2907b1 100755
--- a/xmake/plugins/doxygen.lua
+++ b/xmake/plugins/doxygen.lua
@@ -1,3 +1,5 @@
-- define task
task("doxygen")
+ -- set menu
+ set_task_menu({})
diff --git a/xmake/plugins/macro.lua b/xmake/plugins/macro.lua
index de96afa84..cebb468e4 100755
--- a/xmake/plugins/macro.lua
+++ b/xmake/plugins/macro.lua
@@ -1,3 +1,5 @@
-- define task
task("macro")
+ -- set menu
+ set_task_menu({})