Skip to content

Commit d366f10

Browse files
fix(*): duplicate resources for dynamic frameworks grab#74
1 parent f73781c commit d366f10

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
NA
66

77
### Bug fixes
8-
NA
8+
- Fix duplicate resources for dynamic frameworks https://github.com/grab/cocoapods-binary-cache/issues/74.
99

1010
## 0.1.14
1111
### Enhancements

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
module Pod
44
class PrebuildSandbox < Sandbox
55
# [String] standard_sandbox_path
6-
def self.from_standard_sanbox_path(path)
6+
def self.from_standard_sandbox_path(path)
77
prebuild_sandbox_path = Pathname.new(path).realpath + ".." + PodPrebuild.config.prebuild_sandbox_path
88
new(prebuild_sandbox_path)
99
end
1010

1111
def self.from_standard_sandbox(sandbox)
12-
from_standard_sanbox_path(sandbox.root)
12+
from_standard_sandbox_path(sandbox.root)
1313
end
1414

1515
def standard_sanbox_path
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require_relative "prebuild_sandbox"
2+
3+
module Pod
4+
class Sandbox
5+
def prebuild_sandbox
6+
@prebuild_sandbox ||= Pod::PrebuildSandbox.from_standard_sandbox(self)
7+
end
8+
end
9+
end

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

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require_relative "helper/podfile_options"
22
require_relative "helper/prebuild_sandbox"
3+
require_relative "helper/sandbox"
34
require_relative "helper/names"
45
require_relative "helper/target_checker"
56
require_relative "integration/alter_specs"

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

+34-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,19 @@ def alter_specs_for_prebuilt_pods
2626

2727
private
2828

29+
def metadata_of_target(name)
30+
@metadata_by_target ||= {}
31+
metadata = @metadata_by_target[name]
32+
return metadata unless metadata.nil?
33+
34+
framework_path = sandbox.prebuild_sandbox.framework_folder_path_for_target_name(name)
35+
metadata = PodPrebuild::Metadata.in_dir(framework_path)
36+
@metadata_by_target[name] = metadata
37+
metadata
38+
end
39+
2940
def alter_spec(spec, alterations, cache)
41+
metadata = metadata_of_target(spec.root.name)
3042
targets = Pod.fast_get_targets_for_pod_name(spec.root.name, pod_targets, cache)
3143
platforms = targets.map { |target| target.platform.name.to_s }.uniq
3244

@@ -43,11 +55,31 @@ def alter_spec(spec, alterations, cache)
4355
end
4456

4557
empty_source_files(spec, platforms) if alterations[:source_files]
46-
tweak_resources_for_xib(spec, platforms) if alterations[:resources]
47-
tweak_resources_for_resource_bundles(spec, platforms) if alterations[:resources]
58+
if alterations[:resources]
59+
if metadata.static_framework?
60+
tweak_resources_for_xib(spec, platforms)
61+
tweak_resources_for_resource_bundles(spec, platforms)
62+
else
63+
# For dynamic frameworks, resources & resource bundles are already bundled inside the framework.
64+
# We need to empty resources & resource bundles. Otherwise, there will be duplications
65+
# (resources locating in both app bundle and framework bundle)
66+
empty_resources(spec, platforms)
67+
end
68+
end
4869
empty_liscence(spec) if alterations[:license]
4970
end
5071

72+
def empty_resources(spec, platforms)
73+
spec.attributes_hash["resources"] = nil
74+
spec.attributes_hash["resource_bundles"] = nil
75+
platforms.each do |platform|
76+
next if spec.attributes_hash[platform].nil?
77+
78+
spec.attributes_hash[platform]["resources"] = nil
79+
spec.attributes_hash[platform]["resource_bundles"] = nil
80+
end
81+
end
82+
5183
def tweak_resources_for_xib(spec, platforms)
5284
# This is a workaround for prebuilt static framework that has `*.xib` files in the resources
5385
# (declared by `spec.resources = ...`)

0 commit comments

Comments
 (0)