Use absolute paths for Cache targets and dependencies

This commit is contained in:
Josh Holtrop 2026-01-28 10:58:01 -05:00
parent 13bd827d57
commit af7aad716d
2 changed files with 13 additions and 7 deletions

View File

@ -1758,7 +1758,7 @@ context "Cache management" do
end
result = run_rscons(args: %w[-f cache_debugging.rb])
expect_eq(result.stderr, "")
expect_match(result.stdout, /Target foo\.o needs rebuilding because dependency file simple\.c has changed/)
expect_match(result.stdout, /Target foo\.o needs rebuilding because dependency file \S*simple\.c has changed/)
end
end
end

View File

@ -142,12 +142,14 @@ module Rscons
# - each cached dependency file's current checksum matches the checksum
# stored in the cache file
def up_to_date?(targets, command, deps, env, options = {})
deps = deps.map {|dep| Util.absolute_path(dep)}
Array(targets).each do |target|
cache_key = get_cache_key(target)
abstarget = Util.absolute_path(target)
cache_key = get_cache_key(abstarget)
unless Rscons.phony_target?(target)
unless Rscons.phony_target?(abstarget)
# target file must exist on disk
unless File.exist?(target)
unless File.exist?(abstarget)
if options[:debug]
puts "Target #{target} needs rebuilding because it does not exist on disk"
end
@ -163,9 +165,9 @@ module Rscons
return false
end
unless Rscons.phony_target?(target)
unless Rscons.phony_target?(abstarget)
# target must have the same checksum as when it was built last
unless @cache["targets"][cache_key]["checksum"] == lookup_checksum(target)
unless @cache["targets"][cache_key]["checksum"] == lookup_checksum(abstarget)
if options[:debug]
puts "Target #{target} needs rebuilding because it has been changed on disk since being built last"
end
@ -202,7 +204,7 @@ module Rscons
end
# set of user dependencies must match
user_deps = env.get_user_deps(target) || []
user_deps = env.get_user_deps(abstarget) || []
cached_user_deps = @cache["targets"][cache_key]["user_deps"] || []
cached_user_deps_fnames = cached_user_deps.map { |dc| dc["fname"] }
unless user_deps == cached_user_deps_fnames
@ -247,12 +249,16 @@ module Rscons
# @return [void]
def register_build(targets, command, deps, env, options = {})
Array(targets).each do |target|
target = Util.absolute_path(target)
target_checksum =
if options[:side_effect] or Rscons.phony_target?(target)
""
else
calculate_checksum(target)
end
deps = deps.map do |dep|
Util.absolute_path(dep)
end.uniq
@cache["targets"][get_cache_key(target)] = {
"command" => Digest::MD5.hexdigest(command.inspect),
"checksum" => target_checksum,