summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-06-11 23:12:20 +0800
committerruki <[email protected]>2022-06-11 23:12:20 +0800
commit308f947985956e0fb8e97ac28240be646d0e2963 (patch)
tree61c014e291ba2d0a7ee91ca53a48f708bcebb914
parentced36fb1ccfaf8196dc28b49aa4a949040a0ab75 (diff)
improve cl
-rw-r--r--xmake/modules/core/tools/cl.lua13
1 files changed, 11 insertions, 2 deletions
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index 1b0be7948..1e7556808 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -470,12 +470,21 @@ function _preprocess(program, argv, opt)
if linemarkers == false then
table.insert(cppflags, "-EP")
else
+ -- we cannot use `/P`, @see https://github.com/xmake-io/xmake/issues/2445
table.insert(cppflags, "-E")
end
table.insert(cppflags, sourcefile)
return try{ function()
- local outdata, errdata = os.iorunv(program, winos.cmdargv(cppflags), opt)
- io.writefile(cppfile, outdata or "")
+ local outfile = os.tmpfile() .. ".i.out"
+ local errfile = os.tmpfile() .. ".i.err"
+ os.execv(program, winos.cmdargv(cppflags), table.join(opt, {stdout = outfile, stderr = errfile}))
+ local errdata
+ if os.isfile(errfile) then
+ errdata = io.readfile(errfile)
+ end
+ os.cp(outfile, cppfile)
+ os.tryrm(errfile)
+ os.tryrm(outfile)
-- includes information will be output to stderr instead of stdout now
return {outdata = errdata, errdata = errdata,
sourcefile = sourcefile, objectfile = objectfile, cppfile = cppfile, cppflags = flags,