Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix depend.is_changed #6089 #6104

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading