From f42c68d86a82e4004748ce4fdbefab5d9f3c9736 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 22 Jan 2025 23:24:58 +0800 Subject: [PATCH] fix depend.is_changed #6089 --- xmake/modules/core/project/depend.lua | 20 ++++++++++++++----- xmake/modules/private/action/build/object.lua | 7 ++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua index 22840f09e6b..61d51c4a306 100644 --- a/xmake/modules/core/project/depend.lua +++ b/xmake/modules/core/project/depend.lua @@ -103,14 +103,23 @@ function is_changed(dependinfo, opt) end -- check whether the dependent files are changed + local timecache = opt.timecache local lastmtime = opt.lastmtime or 0 _g.files_mtime = _g.files_mtime or {} local files_mtime = _g.files_mtime for _, file in ipairs(files) do -- get and cache the file mtime - local mtime = files_mtime[file] or os.mtime(file) - files_mtime[file] = mtime + local mtime + if timecache then + mtime = files_mtime[file] + if mtime == nil then + mtime = os.mtime(file) + files_mtime[file] = mtime + end + else + mtime = os.mtime(file) + end -- source and header files have been changed or not exists? if mtime == 0 or mtime > lastmtime then @@ -186,8 +195,6 @@ end -- files = {sourcefile, ...}}) -- function on_changed(callback, opt) - - -- init option opt = opt or {} -- dry run? we only do callback directly and do not change any status @@ -209,7 +216,10 @@ function on_changed(callback, opt) -- @note we use mtime(dependfile) instead of mtime(objectfile) to ensure the object file is is fully compiled. -- @see https://github.com/xmake-io/xmake/issues/748 - if not is_changed(dependinfo, {lastmtime = opt.lastmtime or os.mtime(dependfile), values = opt.values, files = opt.files}) then + if not is_changed(dependinfo, { + timecache = opt.timecache, + lastmtime = opt.lastmtime or os.mtime(dependfile), + values = opt.values, files = opt.files}) then return end diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua index 25bf3385bfc..60137f3cbf0 100644 --- a/xmake/modules/private/action/build/object.lua +++ b/xmake/modules/private/action/build/object.lua @@ -55,9 +55,14 @@ function _do_build_file(target, sourcefile, opt) -- -- we also need avoid the problem of not being able to recompile after the objectfile has been deleted -- @see https://github.com/xmake-io/xmake/issues/2551#issuecomment-1183922208 + -- + -- optimization: + -- we enable time cache to speed up is_changed, because there are a lot of header files in depfiles. + -- but we need to cache it in link stage, maybe some objectfiles will be updated. + -- @see https://github.com/xmake-io/xmake/issues/6089 local depvalues = {compinst:program(), compflags} local lastmtime = os.isfile(objectfile) and os.mtime(dependfile) or 0 - if not dryrun and not depend.is_changed(dependinfo, {lastmtime = lastmtime, values = depvalues}) then + if not dryrun and not depend.is_changed(dependinfo, {lastmtime = lastmtime, values = depvalues, timecache = true}) then return end