summaryrefslogtreecommitdiff
path: root/xmake/core/main.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-04-18 22:42:48 +0800
committerruki <[email protected]>2025-08-28 11:35:53 +0800
commitad77d170e407fc7d346df32a88683aae050bf36b (patch)
treee1ae2f06dc31a84ae42b4dd6086cb570ef88b95b /xmake/core/main.lua
parent6eccd1efa540d634e35eb29cf923025e0667aa0c (diff)
run thread
Diffstat (limited to 'xmake/core/main.lua')
-rw-r--r--xmake/core/main.lua51
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)