summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-12-19 00:33:58 +0800
committerruki <[email protected]>2020-12-19 00:33:58 +0800
commitbbf9e7988955d4385639ee30f5df309ff6891736 (patch)
treecdd10d7f651bc6834c36b9874c7ce8c04b851c62
parent37d4120c6cfd0454b45d606d2969e41631cc1f42 (diff)
add global cache directory
-rw-r--r--xmake/actions/build/cleaner.lua2
-rw-r--r--xmake/actions/global/xmake.lua4
-rw-r--r--xmake/core/base/global.lua5
-rw-r--r--xmake/core/package/package.lua2
-rw-r--r--xmake/core/sandbox/modules/import/core/base/global.lua60
5 files changed, 19 insertions, 54 deletions
diff --git a/xmake/actions/build/cleaner.lua b/xmake/actions/build/cleaner.lua
index f5be28225..54108fbce 100644
--- a/xmake/actions/build/cleaner.lua
+++ b/xmake/actions/build/cleaner.lua
@@ -86,7 +86,7 @@ function main()
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))
+ local cachedir = path.join(global.cachedir(), "packages", 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/actions/global/xmake.lua b/xmake/actions/global/xmake.lua
index 97a3da630..cbb32d998 100644
--- a/xmake/actions/global/xmake.lua
+++ b/xmake/actions/global/xmake.lua
@@ -50,7 +50,8 @@ task("global")
end}
, {nil, "debugger", "kv", "auto" , "The debugger program path." }
, {category = "Build Configuration"}
- , {nil, "build_warning", "kv", nil , "Enable the warnings output by default when building." }
+ , {nil, "build_warning", "kv", nil , "Enable the warnings output by default when building." }
+ , {nil, "cachedir", "kv", nil , "The global cache directory." }
-- network configuration
, {category = "Network Configuration"}
@@ -91,7 +92,6 @@ task("global")
-- get global menu options
return menu.options("global")
end
-
}
}
diff --git a/xmake/core/base/global.lua b/xmake/core/base/global.lua
index d493235d1..61d9d9e3b 100644
--- a/xmake/core/base/global.lua
+++ b/xmake/core/base/global.lua
@@ -110,6 +110,11 @@ function global.directory()
return global._DIRECTORY
end
+-- get the global cache directory
+function global.cachedir()
+ return global.get("cachedir") or path.join(global.directory(), "cache")
+end
+
-- load the global configuration
function global.load()
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index cdc0dfcef..135329d10 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1344,7 +1344,7 @@ end
-- the cache directory
function package.cachedir()
- return path.join(global.directory(), "cache", "packages", os.date("%y%m"))
+ return path.join(global.cachedir(), "packages", os.date("%y%m"))
end
-- the install directory
diff --git a/xmake/core/sandbox/modules/import/core/base/global.lua b/xmake/core/sandbox/modules/import/core/base/global.lua
index 24cc441df..5b66142fc 100644
--- a/xmake/core/sandbox/modules/import/core/base/global.lua
+++ b/xmake/core/sandbox/modules/import/core/base/global.lua
@@ -28,64 +28,24 @@ local global = require("base/global")
local platform = require("platform/platform")
local raise = require("sandbox/modules/raise")
--- get the configure
-function sandbox_core_base_global.get(name)
- return global.get(name)
-end
-
--- set the configure
---
--- @param name the name
--- @param value the value
--- @param opt the argument options, e.g. {readonly = false, force = false}
---
-function sandbox_core_base_global.set(name, value, opt)
- global.set(name, value, opt)
-end
-
--- this config name is readonly?
-function sandbox_core_base_global.readonly(name)
- return config.readonly(name)
-end
-
--- dump the configure
-function sandbox_core_base_global.dump()
- global.dump()
-end
+-- export some readonly interfaces
+sandbox_core_base_global.get = global.get
+sandbox_core_base_global.set = global.set
+sandbox_core_base_global.readonly = global.readonly
+sandbox_core_base_global.dump = global.dump
+sandbox_core_base_global.clear = global.clear
+sandbox_core_base_global.options = global.options
+sandbox_core_base_global.filepath = global.filepath
+sandbox_core_base_global.directory = global.directory
+sandbox_core_base_global.cachedir = global.cachedir
-- save the configure
function sandbox_core_base_global.save()
-
- -- save it
local ok, errors = global.save()
if not ok then
raise(errors)
end
end
--- clear the configure
-function sandbox_core_base_global.clear()
- return global.clear()
-end
-
--- get all options
-function sandbox_core_base_global.options()
- return global.options()
-end
-
--- get the configure file path
-function sandbox_core_base_global.filepath()
- local filepath = global.filepath()
- assert(filepath)
- return filepath
-end
-
--- get the configure directory
-function sandbox_core_base_global.directory()
- local dir = global.directory()
- assert(dir)
- return dir
-end
-
-- return module
return sandbox_core_base_global