diff options
| author | ruki <[email protected]> | 2016-07-10 16:07:52 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-07-10 16:07:52 +0800 |
| commit | e281ea26c19103dcbc7f951a8592eeb6a1ff63a3 (patch) | |
| tree | b2ef3ea44478ad5d7ec5cf3f1a11e65213fd379b /xmake/core | |
| parent | fd39adb3d959e605370098a72ec7e92b462fce62 (diff) | |
parse includes from cl.exe
Diffstat (limited to 'xmake/core')
| -rw-r--r-- | xmake/core/base/os.lua | 128 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/compiler.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 34 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 4 |
4 files changed, 88 insertions, 82 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index a25dcbdc0..61e19cd84 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -256,22 +256,10 @@ end function os.run(cmd) -- make temporary log file - local log = path.join(os.tmpdir(), "xmake.os.run.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, status = process.wait(p, -1) - - -- close process - process.close(p) + local log = os.tmpfile() - -- ok? - local ok = utils.ifelse(waitok > 0, status, -1) + -- execute it + local ok = os.exec(cmd, log, log) if ok ~= 0 then -- make errors @@ -295,7 +283,7 @@ end function os.runv(shellname, argv) -- make temporary log file - local log = path.join(os.tmpdir(), "xmake.os.runv.log") + local log = os.tmpfile() -- execute it local ok = os.execv(shellname, table.wrap(argv), log, log) @@ -327,7 +315,21 @@ function os.exec(cmd, outfile, errfile) if proc ~= nil then -- wait process - local waitok, status = process.wait(proc, -1) + local waitok = -1 + local status = -1 + if coroutine.running() then + repeat + -- poll it + waitok, status = process.wait(proc, 0) + if waitok == 0 then + coroutine.yield() + end + until waitok ~= 0 + else + waitok, status = process.wait(proc, -1) + end + + -- get status if waitok > 0 then ok = status end @@ -349,7 +351,21 @@ function os.execv(shellname, argv, outfile, errfile) if proc ~= nil then -- wait process - local waitok, status = process.wait(proc, -1) + local waitok = -1 + local status = -1 + if coroutine.running() then + repeat + -- poll it + waitok, status = process.wait(prpoc, 0) + if waitok == 0 then + coroutine.yield() + end + until waitok ~= 0 + else + waitok, status = process.wait(proc, -1) + end + + -- get status if waitok > 0 then ok = status end @@ -362,72 +378,48 @@ function os.execv(shellname, argv, outfile, errfile) return ok end --- run shell with io +-- run shell and return output and error data function os.iorun(cmd) - -- make temporary data file - local datafile = path.join(os.tmpdir(), "xmake.os.iorun.data") + -- make temporary output and error file + local outfile = os.tmpfile() + local errfile = os.tmpfile() -- run command - local ok = os.exec(cmd, datafile, datafile) + local ok = os.exec(cmd, outfile, errfile) - -- get results - local results = io.readall(datafile) + -- get output and error data + local outdata = io.readall(outfile) + local errdata = io.readall(errfile) - -- remove the temporary data file - os.rm(datafile) + -- remove the temporary output and error file + os.rm(outfile) + os.rm(errfile) -- ok? - return ok == 0, results + return ok == 0, outdata, errdata end --- run shell with coroutine -function os.corun(cmd) +-- run shell with arguments and return output and error data +function os.iorunv(shellname, argv) - -- make temporary log file - local log = os.tmpfile() - - -- open command - local p = process.open(cmd, log, log) - if nil == p then - return false, string.format("cannot run %s", cmd) - end + -- make temporary output and error file + local outfile = os.tmpfile() + local errfile = os.tmpfile() - -- wait process - local waitok = -1 - local status = -1 - repeat - - -- poll it - waitok, status = process.wait(p, 0) - if waitok == 0 then - coroutine.yield() - end + -- run command + local ok = os.execv(shellname, argv, outfile, errfile) - until waitok ~= 0 + -- get output and error data + local outdata = io.readall(outfile) + local errdata = io.readall(errfile) - -- close process - process.close(p) + -- remove the temporary output and error file + os.rm(outfile) + os.rm(errfile) -- 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 + return ok == 0, outfile, errdata end -- raise an exception and abort the current script diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua index 340b32734..779bfe696 100644 --- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua +++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua @@ -42,7 +42,7 @@ function sandbox_core_tool_compiler.compcmd(sourcefile, objectfile, target) end -- compile source file -function sandbox_core_tool_compiler.compile(sourcefile, objectfile, incdepfile, target, multitasking) +function sandbox_core_tool_compiler.compile(sourcefile, objectfile, incdepfile, target) -- get the compiler instance local instance, errors = compiler.load(compiler.kind_of_file(sourcefile)) @@ -51,7 +51,7 @@ function sandbox_core_tool_compiler.compile(sourcefile, objectfile, incdepfile, end -- compile it - local ok, errors = instance:compile(sourcefile, objectfile, incdepfile, target, multitasking) + local ok, errors = instance:compile(sourcefile, objectfile, incdepfile, target) if not ok then raise(errors) end diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index f4d6efb6e..7486e5d25 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -166,6 +166,17 @@ function sandbox_os.tmpdir() return tmpdir end +-- get the temporary file +function sandbox_os.tmpfile() + + -- get it + local tmpfile = os.tmpfile() + assert(tmpfile) + + -- ok + return tmpfile +end + -- get the tools directory function sandbox_os.toolsdir() @@ -221,33 +232,36 @@ function sandbox_os.runv(shellname, argv) end end --- run shell with io +-- run shell and return output and error data function sandbox_os.iorun(cmd, ...) -- make command cmd = vformat(cmd, ...) -- run it - local ok, results = os.iorun(cmd) + local ok, outdata, errdata = os.iorun(cmd) if not ok then - os.raise(results) + os.raise(errdata) end -- ok - return results + return outdata, errdata end --- run shell with coroutine -function sandbox_os.corun(cmd, ...) +-- run shell and return output and error data +function sandbox_os.iorunv(shellname, argv) - -- make command - cmd = vformat(cmd, ...) + -- make shellname + shellname = vformat(shellname) -- run it - local ok, errors = os.corun(cmd) + local ok, outdata, errdata = os.iorunv(shellname, argv) if not ok then - os.raise(errors) + os.raise(errdata) end + + -- ok + return outdata, errdata end -- execute shell diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index a523af449..7b8e1b909 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -399,7 +399,7 @@ function compiler:get(name) end -- compile the source file -function compiler:compile(sourcefile, objectfile, incdepfile, target, multitasking) +function compiler:compile(sourcefile, objectfile, incdepfile, target) -- get flags local flags = nil @@ -408,7 +408,7 @@ function compiler:compile(sourcefile, objectfile, incdepfile, target, multitaski end -- compile it - return sandbox.load(self:_tool().compile, sourcefile, objectfile, incdepfile, flags or "", multitasking) + return sandbox.load(self:_tool().compile, sourcefile, objectfile, incdepfile, flags or "") end -- get the compile command |
