summaryrefslogtreecommitdiff
path: root/xmake/core/base
diff options
context:
space:
mode:
authorruki <[email protected]>2016-05-19 15:47:46 +0800
committerruki <[email protected]>2016-05-19 15:47:46 +0800
commitf3ab20418a0b06f84c6afa22ecfebf7965fd646b (patch)
tree91f7d98b3c4a5631897af10eda485f58a430724f /xmake/core/base
parent3f36fc0bee466691f3d0400ae7b4d8259870a15a (diff)
impl multi-jobs for builder
Diffstat (limited to 'xmake/core/base')
-rw-r--r--xmake/core/base/os.lua52
1 files changed, 51 insertions, 1 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index a165e4b34..cdf8dcdfc 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -232,7 +232,7 @@ function os.cd(dir)
end
-- run shell
-function os.run(cmd, ...)
+function os.run(cmd)
-- make temporary log file
local log = path.join(os.tmpdir(), "xmake.os.run.log")
@@ -257,6 +257,56 @@ function os.run(cmd, ...)
return true
end
+-- run shell with coroutine
+function os.corun(cmd)
+
+ -- FIXME
+ -- make temporary log file
+ local log = path.join(os.tmpdir(), "xmake.os.corun.log")
+
+ -- open command
+ local p = process.open(cmd, log, log)
+ if nil == p then
+ return false, string.format("cannot run %s", cmd)
+ end
+
+ -- wait process
+ local waitok = -1
+ local status = -1
+ repeat
+
+ -- poll it
+ waitok, status = process.wait(p, 0)
+ if waitok == 0 then
+ coroutine.yield()
+ end
+
+ until waitok ~= 0
+
+ -- close process
+ process.close(p)
+
+ -- ok?
+ local ok = utils.ifelse(waitok > 0, status, -1)
+ if ok ~= 0 then
+
+ -- make errors
+ local errors = io.readall(log)
+
+ -- remove the temporary log file
+ os.rm(log)
+
+ -- failed
+ return false, errors
+ end
+
+ -- remove the temporary log file
+ os.rm(log)
+
+ -- ok
+ return true
+end
+
-- raise an exception and abort the current script
--
-- the parent function will capture it if we uses pcall or xpcall