summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-07-10 16:07:52 +0800
committerruki <[email protected]>2016-07-10 16:07:52 +0800
commite281ea26c19103dcbc7f951a8592eeb6a1ff63a3 (patch)
treeb2ef3ea44478ad5d7ec5cf3f1a11e65213fd379b
parentfd39adb3d959e605370098a72ec7e92b462fce62 (diff)
parse includes from cl.exe
-rwxr-xr-xxmake/actions/build/kinds/object.lua2
-rw-r--r--xmake/core/base/os.lua128
-rw-r--r--xmake/core/sandbox/modules/import/core/tool/compiler.lua4
-rw-r--r--xmake/core/sandbox/modules/os.lua34
-rw-r--r--xmake/core/tool/compiler.lua4
-rwxr-xr-xxmake/plugins/macro/macros/package.lua6
-rwxr-xr-xxmake/tools/cl.lua22
-rwxr-xr-xxmake/tools/gcc.lua17
-rw-r--r--xmake/tools/swiftc.lua8
9 files changed, 121 insertions, 104 deletions
diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua
index a1adb5d0f..ed4806822 100755
--- a/xmake/actions/build/kinds/object.lua
+++ b/xmake/actions/build/kinds/object.lua
@@ -120,7 +120,7 @@ function _build(target, g, index)
end
-- complie it and enable multitasking
- compiler.compile(sourcefile, objectfile, incdepfile, target, true)
+ compiler.compile(sourcefile, objectfile, incdepfile, target)
end
-- build objects for the given target
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
diff --git a/xmake/plugins/macro/macros/package.lua b/xmake/plugins/macro/macros/package.lua
index 04947c6d8..ee7e5ca72 100755
--- a/xmake/plugins/macro/macros/package.lua
+++ b/xmake/plugins/macro/macros/package.lua
@@ -55,13 +55,13 @@ function main(argv)
for _, arch in ipairs(platform.archs(plat)) do
-- config it
- os.exec("xmake f -p %s -a %s %s -c", plat, arch, args.config or "")
+ os.exec("xmake f -p %s -a %s %s -c %s", plat, arch, args.config or "", ifelse(option.get("verbose"), "-v", ""))
-- package it
if args.outputdir then
- os.exec("xmake p -o %s", args.outputdir)
+ os.exec("xmake p -o %s %s", args.outputdir, ifelse(option.get("verbose"), "-v", ""))
else
- os.exec("xmake p")
+ os.exec("xmake p %s", ifelse(option.get("verbose"), "-v", ""))
end
end
diff --git a/xmake/tools/cl.lua b/xmake/tools/cl.lua
index 30d30a6f3..faba74124 100755
--- a/xmake/tools/cl.lua
+++ b/xmake/tools/cl.lua
@@ -112,16 +112,28 @@ function compcmd(sourcefile, objectfile, flags)
end
-- complie the source file
-function compile(sourcefile, objectfile, incdepfile, flags, multitasking)
+function compile(sourcefile, objectfile, incdepfile, flags)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
+ -- generate includes file
+ if incdepfile then
+ flags = (flags or "") .. " -showIncludes"
+ end
+
-- compile it
- if multitasking then
- os.corun(compcmd(sourcefile, objectfile, flags))
- else
- os.run(compcmd(sourcefile, objectfile, flags))
+ local outdata = os.iorun(compcmd(sourcefile, objectfile, flags))
+ if incdepfile and outdata then
+
+ -- translate it
+ local results = {}
+ for includefile in string.gmatch(outdata, "including file:%s*(.-%.[h|hpp])") do
+ table.insert(results, includefile)
+ end
+
+ -- update it
+ io.save(incdepfile, results)
end
end
diff --git a/xmake/tools/gcc.lua b/xmake/tools/gcc.lua
index 85bc7a379..68c7c9100 100755
--- a/xmake/tools/gcc.lua
+++ b/xmake/tools/gcc.lua
@@ -142,32 +142,35 @@ function link(objectfiles, targetfile, flags)
end
-- complie the source file
-function compile(sourcefile, objectfile, incdepfile, flags, multitasking)
+function compile(sourcefile, objectfile, incdepfile, flags)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
- -- run function
- local run = ifelse(multitasking, os.corun, os.run)
-
-- compile it
- run(compcmd(sourcefile, objectfile, flags))
+ os.run(compcmd(sourcefile, objectfile, flags))
-- generate includes file
if incdepfile then
+ -- the temporary file
+ local tmpfile = os.tmpfile()
+
-- generate it
- run(compcmd(sourcefile, incdepfile, flags .. " -MM"))
+ os.run(compcmd(sourcefile, tmpfile, (flags or "") .. " -MM"))
-- translate it
local results = {}
- local incdeps = io.read(incdepfile)
+ local incdeps = io.read(tmpfile)
for includefile in string.gmatch(incdeps, "([%w|/|%.|%-|%+|_|%$]-%.[h|hpp])") do
table.insert(results, includefile)
end
-- update it
io.save(incdepfile, results)
+
+ -- remove the temporary file
+ os.rm(tmpfile)
end
end
diff --git a/xmake/tools/swiftc.lua b/xmake/tools/swiftc.lua
index 49b9476b2..eb304e420 100644
--- a/xmake/tools/swiftc.lua
+++ b/xmake/tools/swiftc.lua
@@ -94,17 +94,13 @@ function compcmd(sourcefile, objectfile, flags)
end
-- complie the source file
-function compile(sourcefile, objectfile, incdepfile, flags, multitasking)
+function compile(sourcefile, objectfile, incdepfile, flags)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
- if multitasking then
- os.corun(compcmd(sourcefile, objectfile, flags))
- else
- os.run(compcmd(sourcefile, objectfile, flags))
- end
+ os.run(compcmd(sourcefile, objectfile, flags))
end
-- make the includedir flag