summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-11-25 12:18:12 +0800
committerGitHub <[email protected]>2022-11-25 12:18:12 +0800
commita64cea90e22dd80dfec90701549cddf812cfa357 (patch)
treed7dd6b10214bca72413d35cad193932762722ac2
parent4b3232ce7d067f5ec760b80c16978f261918ffe1 (diff)
parentca378b2af611a9851f05b51919b562f2be053f08 (diff)
Merge pull request #3101 from xmake-io/cl
Fix files or directories not access by another process occupied
-rw-r--r--CHANGELOG.md2
m---------core/src/tbox/tbox0
-rw-r--r--scripts/rpmbuild/SPECS/xmake.spec2
-rw-r--r--xmake/core/base/winos.lua12
-rw-r--r--xmake/core/sandbox/modules/winos.lua15
-rw-r--r--xmake/modules/core/tools/cl.lua14
6 files changed, 34 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 280fbc0d6..9958eb190 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@
* [#3082](https://github.com/xmake-io/xmake/issues/3082): Fix build.ninja generator
* [#3092](https://github.com/xmake-io/xmake/issues/3092): Fix xrepo add-repo error handing
* [#3013](https://github.com/xmake-io/xmake/issues/3013): Fix and support windows UNC path
+* [#2902](https://github.com/xmake-io/xmake/issues/2902): Fix file not access by another process occupied
## v2.7.3
@@ -1468,6 +1469,7 @@
* [#3082](https://github.com/xmake-io/xmake/issues/3082): 修复 build.ninja 生成器
* [#3092](https://github.com/xmake-io/xmake/issues/3092): 修复 xrepo add-repo 添加失败逻辑
* [#3013](https://github.com/xmake-io/xmake/issues/3013): 修复支持 windows UNC 路径
+* [#2902](https://github.com/xmake-io/xmake/issues/2902): 修复文件被其他子进程占用问题
## v2.7.3
diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox
-Subproject 5832d9d3eb26f4472de8f1f4de33a3367642c9e
+Subproject 5b62232dce4302e512a659ecb2403c312e0b9cb
diff --git a/scripts/rpmbuild/SPECS/xmake.spec b/scripts/rpmbuild/SPECS/xmake.spec
index f2a026373..9ec52c961 100644
--- a/scripts/rpmbuild/SPECS/xmake.spec
+++ b/scripts/rpmbuild/SPECS/xmake.spec
@@ -1,5 +1,5 @@
%define xmake_revision 6d8887c94b4777fe191f7a4c17a7dc00b10f1670
-%define tbox_revision 22ed6483f2de73f42ab1b5aab77a44673ff94d6a
+%define tbox_revision 5b62232dce4302e512a659ecb2403c312e0b9cb7
%define sv_revision 035262773da0500367cb88e6f30197908159a348
%define lua_cjson_revision ddcecf3b24b71421e7b4a2962f1fbcc0297e0c1e
%define luajit_revision e9af1abec542e6f9851ff2368e7f196b6382a44c
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,