summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-07-02 00:52:56 +0800
committerruki <[email protected]>2019-07-01 23:17:41 +0800
commitdb0b2ae6096ea05dc990ac7d975e194cca75035e (patch)
tree88935df3bda858f45f328405da09ea83398e4263
parent1d703c1e2a2bf70284c045650fb7883cb40e055c (diff)
fix os.nuldev()
-rw-r--r--xmake/core/base/os.lua55
1 files changed, 26 insertions, 29 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 631276fca..2d9de3ca8 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -788,39 +788,36 @@ end
-- get the system null device
function os.nuldev(input)
- if os.host() == "windows" then
- -- init the output nuldev
- if xmake._NULDEV_OUTPUT == nil then
- xmake._NULDEV_OUTPUT = os.tmpfile()
+ if input then
+ if os.host() == "windows" then
+ -- init the input nuldev
+ if xmake._NULDEV_INPUT == nil then
+ -- create an empty file
+ --
+ -- for fix issue on mingw:
+ -- $ gcc -fopenmp -S -o nul -xc nul
+ -- gcc: fatal error:input file 'nul' is the same as output file
+ --
+ local inputfile = os.tmpfile()
+ io.writefile(inputfile, "")
+ xmake._NULDEV_INPUT = inputfile
+ end
else
- os.rm(xmake._NULDEV_OUTPUT)
- end
- -- init the input nuldev
- if xmake._NULDEV_INPUT == nil then
- -- create an empty file
- --
- -- for fix issue on mingw:
- -- $ gcc -fopenmp -S -o nul -xc nul
- -- gcc: fatal error:input file ‘nul’ is the same as output file
- --
- local inputfile = os.tmpfile()
- io.writefile(inputfile, "")
- xmake._NULDEV_INPUT = inputfile
- end
- else
- if xmake._NULDEV_OUTPUT == nil then
- xmake._NULDEV_OUTPUT = "/dev/null"
- end
- if xmake._NULDEV_INPUT == nil then
- xmake._NULDEV_INPUT = "/dev/null"
+ if xmake._NULDEV_INPUT == nil then
+ xmake._NULDEV_INPUT = "/dev/null"
+ end
end
- end
-
- -- get nuldev
- if input then
return xmake._NULDEV_INPUT
else
- return xmake._NULDEV_OUTPUT
+ if os.host() == "windows" then
+ -- @note cannot cache this file path to avoid multi-processes writing to the same file at the same time
+ return os.tmpfile()
+ else
+ if xmake._NULDEV_OUTPUT == nil then
+ xmake._NULDEV_OUTPUT = "/dev/null"
+ end
+ return xmake._NULDEV_OUTPUT
+ end
end
end