Skip to content

Commit ad9afd8

Browse files
feat(Devpod): Support devpod cache flow and refactoring
1 parent c4ba4b3 commit ad9afd8

File tree

17 files changed

+96
-111
lines changed

17 files changed

+96
-111
lines changed

docs/configure_cocoapods_binary_cache.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ Following are the options available in `config_cocoapods_binary_cache`:
1313

1414
- `prebuild_config` (default: `Debug`): The configuration to use (such as `Debug`) when prebuilding pods
1515

16-
- `prebuild_job` (default: `false`): Whether or not this is a prebuild job
17-
1816
- `prebuild_all_vendor_pods` (default: `false`): Whether to build all vendor pods in the prebuild job
1917

2018
- `excluded_pods` (default: `[]`): A list of pods to exclude (ie. treat them as non-prebuilt pods)

lib/cocoapods-binary-cache/cache/validator.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module PodPrebuild
2-
class CacheValidator < BaseCacheValidator
2+
class CacheValidator
33
def initialize(options)
4-
super(options)
54
@validators = [
65
PodPrebuild::PodfileChangesCacheValidator.new(options),
76
PodPrebuild::NonDevPodsCacheValidator.new(options)

lib/cocoapods-binary-cache/cache/validator_base.rb

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ def validate_pods(options)
7070
PodPrebuild::CacheValidationResult.new(missed, hit)
7171
end
7272

73-
def read_prebuilt_build_settings(name)
74-
return {} if generated_framework_path.nil?
75-
76-
metadata = PodPrebuild::Metadata.in_dir(generated_framework_path + name)
77-
metadata.build_settings
78-
end
79-
8073
def incompatible_build_settings(name)
8174
settings_diff = {}
8275
prebuilt_build_settings = read_prebuilt_build_settings(name)
@@ -88,5 +81,37 @@ def incompatible_build_settings(name)
8881
end
8982
settings_diff
9083
end
84+
85+
def incompatible_source(name)
86+
diff = {}
87+
prebuilt_hash = source_hash_info(name)
88+
expected_hash = pod_lockfile.dev_pod_hash(name)
89+
unless prebuilt_hash == expected_hash
90+
diff[name] = { :prebuilt_hash => prebuilt_hash, :expected_hash => expected_hash}
91+
end
92+
diff
93+
end
94+
95+
private
96+
97+
def load_metadata(name)
98+
return nil if generated_framework_path.nil?
99+
100+
PodPrebuild::Metadata.in_dir(generated_framework_path + name)
101+
end
102+
103+
def read_prebuilt_build_settings(name)
104+
metadata = load_metadata(name)
105+
return {} if metadata.nil?
106+
107+
metadata.build_settings
108+
end
109+
110+
def source_hash_info(name)
111+
metadata = load_metadata(name)
112+
return {} if metadata.nil?
113+
114+
metadata.source_hash || {}
115+
end
91116
end
92117
end

lib/cocoapods-binary-cache/cache/validator_dev_pods.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ def initialize(options)
88
def validate(*)
99
return PodPrebuild::CacheValidationResult.new if @pod_lockfile.nil?
1010

11-
# TODO (thuyen): Logic needs to be revised
12-
# TODO (thuyen): Migrate the code PodCacheValidator.verify_devpod_checksum to this place
13-
missed_with_checksum, hit_with_checksum = PodCacheValidator.verify_devpod_checksum(
14-
@sandbox_root,
15-
@generated_framework_path,
16-
@pod_lockfile.lockfile
17-
)
18-
missed = missed_with_checksum.transform_values { |checksum| "Checksum changed: #{checksum}" }
19-
PodPrebuild::CacheValidationResult.new(missed, hit_with_checksum.keys.to_set)
11+
hits = Set.new
12+
misses = {}
13+
@pod_lockfile.dev_pod_names.each do |name|
14+
diff = incompatible_source(name)
15+
if diff.empty?
16+
hits.add(name)
17+
else
18+
misses[name] = "Incompatible source: #{diff}"
19+
end
20+
end
21+
PodPrebuild::CacheValidationResult.new(misses, hits)
2022
end
2123
end
2224
end

lib/cocoapods-binary-cache/helper/lockfile.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require_relative "checksum"
2+
13
module PodPrebuild
24
class Lockfile
35
attr_reader :lockfile, :data
@@ -15,6 +17,10 @@ def external_sources
1517
@data["EXTERNAL SOURCES"] || {}
1618
end
1719

20+
def dev_pod_sources
21+
@dev_pod_sources ||= external_sources.select { |_, attributes| attributes.key?(:path) } || {}
22+
end
23+
1824
def dev_pod_names
1925
# There are 2 types of external sources:
2026
# - Development pods: declared with `:path` option in Podfile, corresponding to `:path` in the Lockfile
@@ -27,7 +33,7 @@ def dev_pod_names
2733
# :git: git@remote_url
2834
# :commit: abc1234
2935
# --------------------
30-
@dev_pod_names ||= external_sources.select { |_, attributes| attributes.key?(:path) }.keys.to_set
36+
@dev_pod_names ||= dev_pod_sources.keys.to_set
3137
end
3238

3339
def dev_pods
@@ -46,8 +52,20 @@ def subspec_pods
4652
.group_by { |k| k.split("/")[0] }
4753
end
4854

55+
# Return content hash (Hash the directory at source path) of a dev_pod
56+
# Return nil if it's not a dev_pod
57+
def dev_pod_hash(pod_name)
58+
dev_pod_hashes_map[pod_name]
59+
end
60+
4961
private
5062

63+
# Generate a map between a dev_pod and it source hash
64+
def dev_pod_hashes_map
65+
@dev_pod_hashes_map ||=
66+
dev_pod_sources.map { |name, attribs| [name, FolderChecksum.checksum(attribs[:path])] }.to_h
67+
end
68+
5169
# Parse an item under `PODS` section of a Lockfile
5270
# @param hash_or_string: an item under `PODS` section, could be a Hash (if having dependencies) or a String
5371
# Examples:

lib/cocoapods-binary-cache/helper/podspec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Pod
22
class Specification
3+
# TODO: this detect objc lib as empty source, eg. Realm
34
def empty_source_files?
45
return subspecs.all?(&:empty_source_files?) unless subspecs.empty?
56

lib/cocoapods-binary-cache/main.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
require_relative "pod-binary/prebuild_dsl"
1616
require_relative "pod-binary/prebuild_hook"
1717
require_relative "pod-binary/prebuild"
18-
require_relative "prebuild_cache"
1918
require_relative "prebuild_output/metadata"
2019
require_relative "prebuild_output/output"
2120
require_relative "scheme_editor"

lib/cocoapods-binary-cache/pod-binary/helper/names.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,10 @@
1818
module Pod
1919
def self.fast_get_targets_for_pod_name(pod_name, targets, cache)
2020
pod_name = pod_name.split("/")[0] # Look for parent spec instead of subspecs
21-
pod_name_to_targets_hash = nil
2221
if cache.empty?
23-
pod_name_to_targets_hash = targets.reduce({}) do |sum, target|
24-
array = sum[target.pod_name] || []
25-
array << target
26-
sum[target.pod_name] = array
27-
sum
28-
end
29-
cache << pod_name_to_targets_hash
22+
targets.select { |target| target.name == pod_name }
3023
else
31-
pod_name_to_targets_hash = cache.first
24+
cache.first[pod_name] || []
3225
end
33-
34-
pod_name_to_targets_hash[pod_name] || []
3526
end
3627
end

lib/cocoapods-binary-cache/pod-binary/integration.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
require_relative "helper/target_checker"
66
require_relative "integration/alter_specs"
77
require_relative "integration/remove_target_files"
8-
require_relative "integration/source_installer"
98
require_relative "integration/validation"
109
require_relative "integration/patch/embed_framework_script"
1110
require_relative "integration/patch/resolve_dependencies"

lib/cocoapods-binary-cache/pod-binary/integration/patch/source_installation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require_relative "../source_installer"
2+
13
module Pod
24
class Installer
35
# Override the download step to skip download and prepare file in target folder

0 commit comments

Comments
 (0)