summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-08-20 22:32:12 +0800
committerruki <[email protected]>2019-08-20 09:13:18 +0800
commit0970525b07224b26c1b10b5a771fec2715cac7c0 (patch)
tree027ba5372f3238a1fbdce68528bc604ebb0b8832
parent803f85a9d3c6ba7429479239c52f67210e778c08 (diff)
add ramdisk for tmpdir
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/core/base/os.lua28
2 files changed, 28 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 05b3ac348..c6c527b8c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@
### Changes
* [#257](https://github.com/xmake-io/xmake/issues/257): Lock the whole project to avoid other process to access.
+* Attempt to enable /dev/shm for the os.tmpdir
## v2.2.7
@@ -630,6 +631,7 @@
### 改进
* [#257](https://github.com/xmake-io/xmake/issues/257): 锁定当前正在构建的工程,避免其他xmake进度同时对其操作
+* 尝试采用/dev/shm作为os.tmpdir去改善构建过程中临时文件的读写效率
## v2.2.7
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 06ee3a837..506cd7da2 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -131,6 +131,30 @@ function os._rm(filedir)
return true
end
+-- get the ramdisk root directory
+function os._ramdir()
+
+ -- get root ramdir
+ local ramdir_root = os._ROOT_RAMDIR
+ if ramdir_root == nil then
+ ramdir_root = os.getenv("XMAKE_RAMDIR")
+ end
+ if ramdir_root == nil then
+ if os.host() == "linux" and os.isdir("/dev/shm") then
+ ramdir_root = "/dev/shm"
+ elseif os.host() == "macosx" and os.isdir("/Volumes/RAM") then
+ -- @note we need the user to execute the command to create it.
+ -- diskutil partitionDisk `hdiutil attach -nomount ram://8388608` GPT APFS "RAM" 0
+ ramdir_root = "/Volumes/RAM"
+ end
+ if ramdir_root == nil then
+ ramdir_root = false
+ end
+ os._ROOT_RAMDIR = ramdir_root
+ end
+ return ramdir_root or nil
+end
+
-- translate arguments for wildcard
function os.argw(argv)
@@ -494,7 +518,7 @@ function os.tmpdir()
-- get root tmpdir
if os._ROOT_TMPDIR == nil then
- os._ROOT_TMPDIR = (os.getenv("XMAKE_TMPDIR") or os.getenv("TMPDIR") or os._tmpdir()):trim()
+ os._ROOT_TMPDIR = (os.getenv("XMAKE_TMPDIR") or os._ramdir() or os.getenv("TMPDIR") or os._tmpdir()):trim()
end
local tmpdir_root = os._ROOT_TMPDIR
@@ -513,7 +537,7 @@ end
-- generate the temporary file path
function os.tmpfile(key)
- return path.join(os.tmpdir(), "_" .. (hash.uuid(key):gsub("-", "")))
+ return path.join(os.tmpdir(), "_" .. (hash.uuid(key):gsub("-", "")))
end
-- run command