Skip to content

Commit

Permalink
Merge pull request #11568 from jszumski/fix-incremental-installation-…
Browse files Browse the repository at this point in the history
…resources

Fix incremental installation when dependent pod resources change
  • Loading branch information
dnkoutso committed Sep 22, 2023
2 parents 0cf801d + 4d260ce commit 88a9db6
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ def create_cache_key_mappings(target_by_label)
when PodTarget
local = sandbox.local?(target.pod_name)
checkout_options = sandbox.checkout_sources[target.pod_name]
[label, TargetCacheKey.from_pod_target(sandbox, target, :is_local_pod => local,
:checkout_options => checkout_options)]
[label, TargetCacheKey.from_pod_target(sandbox, target_by_label, target,
:is_local_pod => local, :checkout_options => checkout_options)]
when AggregateTarget
[label, TargetCacheKey.from_aggregate_target(sandbox, target)]
[label, TargetCacheKey.from_aggregate_target(sandbox, target_by_label, target)]
else
raise "[BUG] Unknown target type #{target}"
end
Expand Down
42 changes: 40 additions & 2 deletions lib/cocoapods/installer/project_cache/target_cache_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def key_difference(other)
other_files = other.key_hash['FILES']
return :project if this_files != other_files

this_resources = key_hash['RESOURCES']
other_resources = other.key_hash['RESOURCES']
return :project if this_resources != other_resources

this_build_settings = key_hash['BUILD_SETTINGS_CHECKSUM']
other_build_settings = other.key_hash['BUILD_SETTINGS_CHECKSUM']
return :project if this_build_settings != other_build_settings
Expand Down Expand Up @@ -98,6 +102,9 @@ def self.from_cache_hash(sandbox, key_hash)
if specs = cache_hash['SPECS']
cache_hash['SPECS'] = specs.sort_by(&:downcase)
end
if resources = cache_hash['RESOURCES']
cache_hash['RESOURCES'] = resources.sort_by(&:downcase)
end
type = cache_hash['CHECKSUM'] ? :pod_target : :aggregate
TargetCacheKey.new(sandbox, type, cache_hash)
end
Expand All @@ -106,6 +113,9 @@ def self.from_cache_hash(sandbox, key_hash)
#
# @param [Sandbox] sandbox The sandbox to use to construct a TargetCacheKey object.
#
# @param [Hash] target_by_label
# Maps target names to PodTarget objects.
#
# @param [PodTarget] pod_target
# The pod target used to construct a TargetCacheKey object.
#
Expand All @@ -117,7 +127,7 @@ def self.from_cache_hash(sandbox, key_hash)
#
# @return [TargetCacheKey]
#
def self.from_pod_target(sandbox, pod_target, is_local_pod: false, checkout_options: nil)
def self.from_pod_target(sandbox, target_by_label, pod_target, is_local_pod: false, checkout_options: nil)
build_settings = {}
build_settings[pod_target.label.to_s] = Hash[pod_target.build_settings.map do |k, v|
[k, Digest::MD5.hexdigest(v.xcconfig.to_s)]
Expand All @@ -129,6 +139,20 @@ def self.from_pod_target(sandbox, pod_target, is_local_pod: false, checkout_opti
build_settings[name] = Hash[settings_by_config.map { |k, v| [k, Digest::MD5.hexdigest(v.xcconfig.to_s)] }]
end

# find resources from upstream dependencies that will be named in the `{name}-resources.sh` script
resource_dependencies = []
pod_target.dependencies.each do |name|
next unless target_by_label[name]

upstream = target_by_label[name]

# pod target
resource_dependencies.append(upstream.resource_paths.values.flatten) if upstream.respond_to?(:resource_paths)

# aggregate target
resource_dependencies.append(upstream.resource_paths_by_config.values.flatten) if upstream.respond_to?(:resource_paths_by_config)
end

contents = {
'CHECKSUM' => pod_target.root_spec.checksum,
'SPECS' => pod_target.specs.map(&:to_s).sort_by(&:downcase),
Expand All @@ -140,6 +164,7 @@ def self.from_pod_target(sandbox, pod_target, is_local_pod: false, checkout_opti
contents['FILES'] = relative_file_paths.sort_by(&:downcase)
end
contents['CHECKOUT_OPTIONS'] = checkout_options if checkout_options
contents['RESOURCES'] = resource_dependencies.flatten.uniq.sort_by(&:downcase) if resource_dependencies.any?
TargetCacheKey.new(sandbox, :pod_target, contents)
end

Expand All @@ -152,12 +177,24 @@ def self.from_pod_target(sandbox, pod_target, is_local_pod: false, checkout_opti
#
# @return [TargetCacheKey]
#
def self.from_aggregate_target(sandbox, aggregate_target)
def self.from_aggregate_target(sandbox, target_by_label, aggregate_target)
build_settings = {}
aggregate_target.user_build_configurations.keys.each do |configuration|
build_settings[configuration] = Digest::MD5.hexdigest(aggregate_target.build_settings(configuration).xcconfig.to_s)
end

# find resources from upstream dependencies that will be named in the `{name}-resources.sh` script
resource_dependencies = []
aggregate_target.pod_targets.each do |name|
upstream = target_by_label[name]

# pod target
resource_dependencies.append(upstream.resource_paths.values.flatten) if upstream.respond_to?(:resource_paths)

# aggregate target
resource_dependencies.append(upstream.resource_paths_by_config.values.flatten) if upstream.respond_to?(:resource_paths_by_config)
end

contents = {
'BUILD_SETTINGS_CHECKSUM' => build_settings,
}
Expand All @@ -167,6 +204,7 @@ def self.from_aggregate_target(sandbox, aggregate_target)
res.relative_path_from(sandbox.project_path.dirname).to_s
end
contents['FILES'] = (relative_resource_file_paths + relative_on_demand_resource_file_paths).sort_by(&:downcase)
contents['RESOURCES'] = resource_dependencies.flatten.uniq.sort_by(&:downcase) if resource_dependencies.any?
end
TargetCacheKey.new(sandbox, :aggregate, contents)
end
Expand Down

0 comments on commit 88a9db6

Please sign in to comment.