diff options
Diffstat (limited to 'xmake/core/main.lua')
| -rw-r--r-- | xmake/core/main.lua | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/xmake/core/main.lua b/xmake/core/main.lua index 87e94c824..95202b04c 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -258,6 +258,33 @@ function main._limit_root() return not option.get("root") and os.getenv("XMAKE_ROOT") ~= 'y' and os.host() ~= 'haiku' end +-- run task +function main._run_task(taskname) + local taskinst = task.task(taskname) or project.task(taskname) + if not taskinst then + return main._exit(false, string.format("do unknown task(%s)!", taskname)) + end + + scheduler:co_start_named("xmake " .. taskname, function () + local ok, errors = taskinst:run() + if not ok then + os.raise(errors) + end + end) +end + +-- run thread +function main._run_thread(callinfo_str) + local callinfo, errors = string.deserialize(callinfo_str) + if not callinfo then + return main._exit(false, string.format("invalid thread callinfo, %s!", errors or "unknown")) + end + local callback = callinfo.callback + if callback then + callback(callinfo.argv) + end +end + -- the main entry function function main.entry() @@ -314,22 +341,18 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily. localcache.save("history") end - -- get task instance - local taskname = option.taskname() or "build" - local taskinst = task.task(taskname) or project.task(taskname) - if not taskinst then - return main._exit(false, string.format("do unknown task(%s)!", taskname)) - end - - -- run task + -- enable scheduler scheduler:enable(true) - scheduler:co_start_named("xmake " .. taskname, function () - local ok, errors = taskinst:run() - if not ok then - os.raise(errors) - end - end) + -- run task or thread + local thread_callinfo = xmake._THREAD_CALLINFO + if thread_callinfo then + main._run_thread(thread_callinfo) + else + main._run_task(option.taskname() or "build") + end + + -- start runloop ok, errors = scheduler:runloop() if not ok then return main._exit(ok, errors) |
