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 | |
| parent | 5fb2bcc38583f830e064082024212c061f055b99 (diff) | |
add project.tmpdir
| -rw-r--r-- | xmake/actions/build/cleaner.lua | 13 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 36 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/core/project/depend.lua | 3 |
4 files changed, 51 insertions, 3 deletions
diff --git a/xmake/actions/build/cleaner.lua b/xmake/actions/build/cleaner.lua index 9f41be49f..f5be28225 100644 --- a/xmake/actions/build/cleaner.lua +++ b/xmake/actions/build/cleaner.lua @@ -23,6 +23,7 @@ import("core.base.option") import("core.base.global") import("core.base.process") import("core.project.config") +import("core.project.project") import("core.package.package") import("core.platform.platform") import("core.platform.environment") @@ -72,6 +73,18 @@ function main() end end + -- clean up the temporary files of project at last 30 days, @see project.tmpdir() + if os.isfile(os.projectfile()) then + local parentdir = path.directory(project.tmpdir()) + for day = 1, 30 do + local tmpdir = path.join(parentdir, os.date("%y%m%d", os.time() - day * 24 * 3600)) + if os.isdir(tmpdir) then + print("cleanup %s ..", tmpdir) + os.tryrm(tmpdir) + end + end + end + -- clean up the previous month package cache files, @see package.cachedir() local cachedir = path.join(global.directory(), "cache", "packages", os.date("%y%m", os.time() - 31 * 24 * 3600)) if os.isdir(cachedir) and cachedir ~= package.cachedir() then 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 diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 18d3de2b4..1a00d5935 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -58,6 +58,8 @@ sandbox_core_project.require = project.require sandbox_core_project.requires = project.requires sandbox_core_project.requires_str = project.requires_str sandbox_core_project.policy = project.policy +sandbox_core_project.tmpdir = project.tmpdir +sandbox_core_project.tmpfile = project.tmpfile -- load project function sandbox_core_project.load() diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua index cdc0a25f7..c10506c6f 100644 --- a/xmake/modules/core/project/depend.lua +++ b/xmake/modules/core/project/depend.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.project.project") import("private.tools.cl.parse_deps", {alias = "parse_deps_cl"}) import("private.tools.cl.parse_deps_json", {alias = "parse_deps_cl_json"}) import("private.tools.rc.parse_deps", {alias = "parse_deps_rc"}) @@ -160,7 +161,7 @@ function on_changed(callback, opt) -- get dependfile local dependfile = opt.dependfile if not dependfile then - dependfile = os.tmpfile(table.concat(table.wrap(opt.files), "")) + dependfile = project.tmpfile(table.concat(table.wrap(opt.files), "")) end -- load dependent info |
