diff options
| author | ruki <[email protected]> | 2022-06-18 17:30:51 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-06-18 17:30:51 +0800 |
| commit | e3b3ffbc6230e9dee45a38356095705f9705966f (patch) | |
| tree | 812c99d8a200fc25f66fac32af8e26670e6bc179 | |
| parent | 91395ec93c42631a613a64fd1b11ab6610bf3ea4 (diff) | |
improve cachekey
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/private/cache/build_cache.lua | 14 | ||||
| -rw-r--r-- | xmake/modules/private/service/distcc_build/client.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/qt/xmake.lua | 2 |
4 files changed, 16 insertions, 6 deletions
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index a495f2696..cf8fad4db 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -511,7 +511,9 @@ function _preprocess(program, argv, opt) -- do preprocess local cppinfo = try {function () local outdata, errdata = os.iorunv(program, cppflags, opt) - return {outdata = outdata, errdata = errdata, sourcefile = sourcefile, objectfile = objectfile, cppfile = cppfile, cppflags = flags} + return {outdata = outdata, errdata = errdata, + sourcefile = sourcefile, objectfile = objectfile, cppfile = cppfile, cppflags = flags, + directives_only = directives_only} end} if not cppinfo then if is_gcc then diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua index fc69b9b84..a06aabe50 100644 --- a/xmake/modules/private/cache/build_cache.lua +++ b/xmake/modules/private/cache/build_cache.lua @@ -65,10 +65,18 @@ function is_supported(sourcekind) end -- get cache key -function cachekey(program, cppfile, cppflags, envs) +function cachekey(program, cppinfo, envs) + local cppfile = cppinfo.cppfile + local cppflags = cppinfo.cppflags + local directives_only = cppinfo.directives_only local items = {program} for _, cppflag in ipairs(cppflags) do - table.insert(items, cppflag) + if not directives_only and (cppflag:startswith("-D") or cppflag:startswith("/D")) then + -- ignore `-Dxx` to improve the cache hit rate, as some source files may not use the defined macros. + -- @see https://github.com/xmake-io/xmake/issues/2425 + else + table.insert(items, cppflag) + end end table.sort(items) table.insert(items, hash.xxhash128(cppfile)) @@ -181,7 +189,7 @@ function build(program, argv, opt) 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 cachekey = cachekey(program, cppinfo, opt.envs) local objectfile_cached = get(cachekey) if objectfile_cached then os.cp(objectfile_cached, cppinfo.objectfile) diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua index 946ce32b8..37033abd7 100644 --- a/xmake/modules/private/service/distcc_build/client.lua +++ b/xmake/modules/private/service/distcc_build/client.lua @@ -239,7 +239,7 @@ function distcc_build_client:compile(program, argv, opt) local cached = false local cachekey if build_cache.is_enabled() then - cachekey = build_cache.cachekey(program, cppinfo.cppfile, cppinfo.cppflags, opt.envs) + cachekey = build_cache.cachekey(program, cppinfo, opt.envs) local objectfile_cached = build_cache.get(cachekey) if objectfile_cached then os.cp(objectfile_cached, cppinfo.objectfile) diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua index b8cc59cfd..16c54db33 100644 --- a/xmake/rules/qt/xmake.lua +++ b/xmake/rules/qt/xmake.lua @@ -87,7 +87,7 @@ rule("qt.widgetapp") end) on_config(function (target) - + -- get qt sdk version local qt = target:data("qt") local qt_sdkver = nil |
