Skip to content

Commit

Permalink
Merge pull request #6104 from xmake-io/depend
Browse files Browse the repository at this point in the history
fix depend.is_changed #6089
  • Loading branch information
waruqi authored Jan 22, 2025
2 parents e7e3316 + f42c68d commit 5ceda71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
20 changes: 15 additions & 5 deletions xmake/modules/core/project/depend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
7 changes: 6 additions & 1 deletion xmake/modules/private/action/build/object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5ceda71

Please sign in to comment.