diff options
| author | ruki <[email protected]> | 2022-11-25 22:52:30 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-11-25 22:52:30 +0800 |
| commit | 6aea0d82f240f27d500ee16701eb8d253533cf16 (patch) | |
| tree | 25dc076978067f5b40875c1a0d6069a666caf06f | |
| parent | 4b3232ce7d067f5ec760b80c16978f261918ffe1 (diff) | |
improve to run cl.exe
| m--------- | core/src/tbox/tbox | 0 | ||||
| -rw-r--r-- | xmake/core/base/winos.lua | 12 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/winos.lua | 15 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 14 |
4 files changed, 31 insertions, 10 deletions
diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox -Subproject 5832d9d3eb26f4472de8f1f4de33a3367642c9e +Subproject 5b62232dce4302e512a659ecb2403c312e0b9cb diff --git a/xmake/core/base/winos.lua b/xmake/core/base/winos.lua index f8b45288a..b0ea7331d 100644 --- a/xmake/core/base/winos.lua +++ b/xmake/core/base/winos.lua @@ -359,5 +359,17 @@ function winos.registry_values(keypath) end end +-- inherit handles in CreateProcess safely? +-- https://github.com/xmake-io/xmake/issues/2902#issuecomment-1326934902 +-- +function winos.inherit_handles_safely() + local inherit_handles_safely = winos._INHERIT_HANDLES_SAFELY + if inherit_handles_safely == nil then + inherit_handles_safely = winos.version():ge("win7") or false + winos._INHERIT_HANDLES_SAFELY = inherit_handles_safely + end + return inherit_handles_safely +end + -- return module: winos return winos diff --git a/xmake/core/sandbox/modules/winos.lua b/xmake/core/sandbox/modules/winos.lua index 6bc5ce0c4..cb1e5b588 100644 --- a/xmake/core/sandbox/modules/winos.lua +++ b/xmake/core/sandbox/modules/winos.lua @@ -26,13 +26,14 @@ local raise = require("sandbox/modules/raise") local sandbox_winos = sandbox_winos or {} -- inherit some builtin interfaces -sandbox_winos.oem_cp = winos.oem_cp -sandbox_winos.ansi_cp = winos.ansi_cp -sandbox_winos.cp_info = winos.cp_info -sandbox_winos.console_cp = winos.console_cp -sandbox_winos.console_output_cp = winos.console_output_cp -sandbox_winos.logical_drives = winos.logical_drives -sandbox_winos.cmdargv = winos.cmdargv +sandbox_winos.oem_cp = winos.oem_cp +sandbox_winos.ansi_cp = winos.ansi_cp +sandbox_winos.cp_info = winos.cp_info +sandbox_winos.console_cp = winos.console_cp +sandbox_winos.console_output_cp = winos.console_output_cp +sandbox_winos.logical_drives = winos.logical_drives +sandbox_winos.cmdargv = winos.cmdargv +sandbox_winos.inherit_handles_safely = winos.inherit_handles_safely -- get windows system version function sandbox_winos.version() diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index a20e4d85b..12b1be79c 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -500,16 +500,24 @@ function _preprocess(program, argv, opt) end table.insert(cppflags, sourcefile) return try{ function() - local outfile = os.tmpfile() .. ".i.out" + -- https://github.com/xmake-io/xmake/issues/2902#issuecomment-1326934902 + local outfile = cppfile local errfile = os.tmpfile() .. ".i.err" + local inherit_handles_safely = true + if not winos.inherit_handles_safely() then + outfile = os.tmpfile() .. ".i.out" + inherit_handles_safely = false + end 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) + if not inherit_handles_safely then + os.cp(outfile, cppfile) + os.tryrm(outfile) + end -- includes information will be output to stderr instead of stdout now return {outdata = errdata, errdata = errdata, sourcefile = sourcefile, objectfile = objectfile, cppfile = cppfile, cppflags = flags, |
