summaryrefslogtreecommitdiff
path: root/xmake/modules/private/cache/build_cache.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-18 00:59:06 +0800
committerruki <[email protected]>2022-05-18 00:59:06 +0800
commite73caa9e24f4c6ca5fa6d60e9c1623cf496bf1e8 (patch)
tree6b058abb0bf5552e38d1cc54cc1056df25dca0cf /xmake/modules/private/cache/build_cache.lua
parent11ba8e1356abcdd6efa9716c5e9dfd337764aeae (diff)
add build cache to distcc
Diffstat (limited to 'xmake/modules/private/cache/build_cache.lua')
-rw-r--r--xmake/modules/private/cache/build_cache.lua42
1 files changed, 40 insertions, 2 deletions
diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua
index 6537f691b..8f3c98bd3 100644
--- a/xmake/modules/private/cache/build_cache.lua
+++ b/xmake/modules/private/cache/build_cache.lua
@@ -24,9 +24,47 @@ import("core.project.config")
-- is enabled?
function enabled()
local build_cache = _g.build_cache
- if build_cache == nil and config.get("ccache") then
- _g.build_cache = build_cache or false
+ if build_cache == nil then
+ build_cache = config.get("ccache") or false
+ _g.build_cache = build_cache
end
return build_cache or false
end
+-- get cache key
+function cachekey(program, cppfile, cppflags, envs)
+ local items = {program}
+ table.insert(items, hash.sha256(cppfile))
+ table.join2(items, cppflags)
+ if envs then
+ for k, v in pairs(table.orderpairs(envs)) do
+ table.insert(items, k)
+ table.insert(items, v)
+ end
+ end
+ return (hash.uuid(table.concat(items, "")):gsub("-", "")):lower()
+end
+
+-- get cache root directory
+function rootdir()
+ return path.join(config.buildir(), ".cache")
+end
+
+-- clean cached files
+function clean()
+ os.rm(rootdir())
+end
+
+-- get object file
+function get(cachekey)
+ local objectfile_cached = path.join(rootdir(), cachekey:sub(1, 2):lower(), cachekey)
+ if os.isfile(objectfile_cached) then
+ return objectfile_cached
+ end
+end
+
+-- put object file
+function put(cachekey, objectfile)
+ local objectfile_cached = path.join(rootdir(), cachekey:sub(1, 2):lower(), cachekey)
+ os.cp(objectfile, objectfile_cached)
+end