diff options
| author | ruki <[email protected]> | 2021-04-13 23:12:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-04-13 23:12:08 +0800 |
| commit | b00f05dd421c8fd8aab0cc6716ecedf185fe32e4 (patch) | |
| tree | 06a8262ee98c34f9c56e9e46c17c8970809947fa | |
| parent | 05f8db002c1fc6078c561e1d3b3329b7fc2aff5e (diff) | |
add package directory envs
| -rw-r--r-- | xmake/actions/build/cleaner.lua | 2 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 20 | ||||
| -rw-r--r-- | xmake/plugins/show/lists/envs.lua | 20 |
3 files changed, 29 insertions, 13 deletions
diff --git a/xmake/actions/build/cleaner.lua b/xmake/actions/build/cleaner.lua index 62bbcf8d4..6916d961d 100644 --- a/xmake/actions/build/cleaner.lua +++ b/xmake/actions/build/cleaner.lua @@ -85,7 +85,7 @@ function main() end -- clean up the previous month package cache files, @see package.cachedir() - local cachedir = path.join(global.cachedir(), "packages", os.date("%y%m", os.time() - 31 * 24 * 3600)) + local cachedir = path.join(package.cachedir({rootonly = true}), os.date("%y%m", os.time() - 31 * 24 * 3600)) if os.isdir(cachedir) and cachedir ~= package.cachedir() then print("cleanup %s ..", cachedir) os.tryrm(cachedir) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index c4db97454..8370961eb 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1641,13 +1641,27 @@ function package.apis() end -- the cache directory -function package.cachedir() - return path.join(global.cachedir(), "packages", os.date("%y%m")) +function package.cachedir(opt) + opt = opt or {} + local cachedir = package._CACHEDIR + if not cachedir then + cachedir = os.getenv("XMAKE_PKG_CACHEDIR") or path.join(global.cachedir(), "packages") + package._CACHEDIR = cachedir + end + if opt.rootonly then + return cachedir + end + return path.join(cachedir, os.date("%y%m")) end -- the install directory function package.installdir() - return global.get("pkg_installdir") or path.join(global.directory(), "packages") + local installdir = package._INSTALLDIR + if not installdir then + installdir = os.getenv("XMAKE_PKG_INSTALLDIR") or global.get("pkg_installdir") or path.join(global.directory(), "packages") + package._INSTALLDIR = installdir + end + return installdir end -- the search directories diff --git a/xmake/plugins/show/lists/envs.lua b/xmake/plugins/show/lists/envs.lua index 1f13b4cb1..f0ce9030a 100644 --- a/xmake/plugins/show/lists/envs.lua +++ b/xmake/plugins/show/lists/envs.lua @@ -27,15 +27,17 @@ import("core.project.project") -- show all toolchains function main() - local envs = { XMAKE_PROGRAM_DIR = {"Set the program scripts directory of xmake.", os.programdir()}, - XMAKE_CONFIGDIR = {"Set the local config directory of project.", config.directory()}, - XMAKE_GLOBALDIR = {"Set the global config directory of xmake.", global.directory()}, - XMAKE_COLORTERM = {"Set the color terminal environment.", os.getenv("XMAKE_COLORTERM") or os.getenv("COLORTERM")}, - XMAKE_LOGFILE = {"Set the log output file path.", os.getenv("XMAKE_LOGFILE")}, - XMAKE_ROOT = {"Allow xmake to run under root.", os.getenv("XMAKE_ROOT")}, - XMAKE_RAMDIR = {"Set the ramdisk directory.", os.getenv("XMAKE_RAMDIR")}, - XMAKE_RCFILES = {"Set the runtime configuration files.", path.joinenv(project.rcfiles())}, - XMAKE_TMPDIR = {"Set the temporary directory.", os.tmpdir()}} + local envs = { XMAKE_PROGRAM_DIR = {"Set the program scripts directory of xmake.", os.programdir()}, + XMAKE_CONFIGDIR = {"Set the local config directory of project.", config.directory()}, + XMAKE_GLOBALDIR = {"Set the global config directory of xmake.", global.directory()}, + XMAKE_COLORTERM = {"Set the color terminal environment.", os.getenv("XMAKE_COLORTERM") or os.getenv("COLORTERM")}, + XMAKE_LOGFILE = {"Set the log output file path.", os.getenv("XMAKE_LOGFILE")}, + XMAKE_ROOT = {"Allow xmake to run under root.", os.getenv("XMAKE_ROOT")}, + XMAKE_RAMDIR = {"Set the ramdisk directory.", os.getenv("XMAKE_RAMDIR")}, + XMAKE_RCFILES = {"Set the runtime configuration files.", path.joinenv(project.rcfiles())}, + XMAKE_TMPDIR = {"Set the temporary directory.", os.tmpdir()}, + XMAKE_PKG_CACHEDIR = {"Set the cache directory of packages.", os.getenv("XMAKE_PKG_CACHEDIR")}, + XMAKE_PKG_INSTALLDIR = {"Set the install directory of packages.", os.getenv("XMAKE_PACKAGEDIR")}} local width = 24 for name, env in pairs(envs) do cprint("${color.dump.string}%s${clear}%s%s", name, (" "):rep(width - #name), env[1]) |
