diff options
| -rw-r--r-- | xmake/core/base/os.lua | 55 |
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 |
