diff options
| author | ruki <[email protected]> | 2020-10-05 23:25:26 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-10-05 23:25:26 +0800 |
| commit | 7cb4cd4a4d4f29b722d611bef4b0d9a2d9e12109 (patch) | |
| tree | a1c82c81330dce99a623b561840a4b998a19764e /xmake/core/project/project.lua | |
| parent | 5fb2bcc38583f830e064082024212c061f055b99 (diff) | |
add project.tmpdir
Diffstat (limited to 'xmake/core/project/project.lua')
| -rw-r--r-- | xmake/core/project/project.lua | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 8de824a32..3e11ece7f 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -1111,10 +1111,42 @@ function project.menu() end end end - - -- ok? return menu end +-- get the temporary directory of project +function project.tmpdir(opt) + + local tmpdir = project._TMPDIR + if not tmpdir then + if os.isdir(config.directory()) then + local tmpdir_root = path.join(config.directory(), "tmp") + tmpdir = path.join(tmpdir_root, os.date("%y%m%d")) + if not os.isdir(tmpdir) then + os.mkdir(tmpdir) + end + else + tmpdir = os.tmpdir() + end + end + return tmpdir +end + +-- generate the temporary file path of project +-- +-- e.g. +-- project.tmpfile("key") +-- project.tmpfile({key = "xxx"}) +-- +function project.tmpfile(opt_or_key) + local opt + local key = opt_or_key + if type(key) == "table" then + key = opt_or_key.key + opt = opt_or_key + end + return path.join(project.tmpdir(opt), "_" .. (hash.uuid4(key):gsub("-", ""))) +end + -- return module: project return project |
