summaryrefslogtreecommitdiff
path: root/xmake/modules/private/cache/build_cache.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-20 22:24:41 +0800
committerruki <[email protected]>2022-05-20 22:24:41 +0800
commitc710b189a6501578c29f1c882cdf711663950f62 (patch)
treec5c7b10deb260fd31c8615bd4ec2891dfff068e5 /xmake/modules/private/cache/build_cache.lua
parent6fad9d40962d1c137d65394e99ea84acba5fe5cc (diff)
improve compile and build cache
Diffstat (limited to 'xmake/modules/private/cache/build_cache.lua')
-rw-r--r--xmake/modules/private/cache/build_cache.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua
index 8ab9cb03a..16655a632 100644
--- a/xmake/modules/private/cache/build_cache.lua
+++ b/xmake/modules/private/cache/build_cache.lua
@@ -100,3 +100,28 @@ function put(cachekey, objectfile)
local objectfile_cached = path.join(rootdir(), cachekey:sub(1, 2):lower(), cachekey)
os.cp(objectfile, objectfile_cached)
end
+
+-- build with cache
+function build(program, argv, opt)
+
+ -- do preprocess
+ opt = opt or {}
+ local preprocess = assert(opt.preprocess, "preprocessor not found!")
+ local compile = assert(opt.compile, "compiler not found!")
+ local cppinfo = preprocess(program, argv, opt)
+ if cppinfo then
+ local cachekey = cachekey(program, cppinfo.cppfile, cppinfo.cppflags, opt.envs)
+ local objectfile_cached = get(cachekey)
+ if objectfile_cached then
+ os.cp(objectfile_cached, cppinfo.objectfile)
+ else
+ -- do compile
+ compile(program, cppinfo, opt)
+ if cachekey then
+ put(cachekey, cppinfo.objectfile)
+ end
+ end
+ os.rm(cppinfo.cppfile)
+ end
+ return cppinfo
+end