Skip to content

Commit f42c68d

Browse files
committed
fix depend.is_changed #6089
1 parent e7e3316 commit f42c68d

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

xmake/modules/core/project/depend.lua

+15-5
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,23 @@ function is_changed(dependinfo, opt)
103103
end
104104

105105
-- check whether the dependent files are changed
106+
local timecache = opt.timecache
106107
local lastmtime = opt.lastmtime or 0
107108
_g.files_mtime = _g.files_mtime or {}
108109
local files_mtime = _g.files_mtime
109110
for _, file in ipairs(files) do
110111

111112
-- get and cache the file mtime
112-
local mtime = files_mtime[file] or os.mtime(file)
113-
files_mtime[file] = mtime
113+
local mtime
114+
if timecache then
115+
mtime = files_mtime[file]
116+
if mtime == nil then
117+
mtime = os.mtime(file)
118+
files_mtime[file] = mtime
119+
end
120+
else
121+
mtime = os.mtime(file)
122+
end
114123

115124
-- source and header files have been changed or not exists?
116125
if mtime == 0 or mtime > lastmtime then
@@ -186,8 +195,6 @@ end
186195
-- files = {sourcefile, ...}})
187196
--
188197
function on_changed(callback, opt)
189-
190-
-- init option
191198
opt = opt or {}
192199

193200
-- dry run? we only do callback directly and do not change any status
@@ -209,7 +216,10 @@ function on_changed(callback, opt)
209216

210217
-- @note we use mtime(dependfile) instead of mtime(objectfile) to ensure the object file is is fully compiled.
211218
-- @see https://github.com/xmake-io/xmake/issues/748
212-
if not is_changed(dependinfo, {lastmtime = opt.lastmtime or os.mtime(dependfile), values = opt.values, files = opt.files}) then
219+
if not is_changed(dependinfo, {
220+
timecache = opt.timecache,
221+
lastmtime = opt.lastmtime or os.mtime(dependfile),
222+
values = opt.values, files = opt.files}) then
213223
return
214224
end
215225

xmake/modules/private/action/build/object.lua

+6-1
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,14 @@ function _do_build_file(target, sourcefile, opt)
5555
--
5656
-- we also need avoid the problem of not being able to recompile after the objectfile has been deleted
5757
-- @see https://github.com/xmake-io/xmake/issues/2551#issuecomment-1183922208
58+
--
59+
-- optimization:
60+
-- we enable time cache to speed up is_changed, because there are a lot of header files in depfiles.
61+
-- but we need to cache it in link stage, maybe some objectfiles will be updated.
62+
-- @see https://github.com/xmake-io/xmake/issues/6089
5863
local depvalues = {compinst:program(), compflags}
5964
local lastmtime = os.isfile(objectfile) and os.mtime(dependfile) or 0
60-
if not dryrun and not depend.is_changed(dependinfo, {lastmtime = lastmtime, values = depvalues}) then
65+
if not dryrun and not depend.is_changed(dependinfo, {lastmtime = lastmtime, values = depvalues, timecache = true}) then
6166
return
6267
end
6368

0 commit comments

Comments
 (0)