cocoapods-podfile_patch 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db532f51a36d8ed122fe39dff75ad95af60c9ed4
4
- data.tar.gz: 8801633e0db80778e6c28348a0e235b96458dcbc
3
+ metadata.gz: c9bf1d36382cafc83dbcb729efa0d106ab8e8491
4
+ data.tar.gz: 74eb48c80a663f9e0cedc9f34a464d1843d62f0f
5
5
  SHA512:
6
- metadata.gz: 0d7bfa8726d98dfcb688ea598642082c60f85efc7e9e9f1c4cde0cc5aba2efe42283052f0965c868ff3dc85db8690f2d76d006ce9d3d6f0eb8a16de5562ef4c3
7
- data.tar.gz: 303764e98bf05c41a6aea36a4b92e920b1119ca987e7e21902c9e92f0de991f0d542cbba2742354e089dfacf27e1eb8f282a5dfc9ed6a2e6a78a724a20a3fe65
6
+ metadata.gz: 4d9297e7fb71edee6df68c3bbefb2a1f1aa241e01d8337e9fb133c5d5bb18a0e28f39c21646d17a81446f3b9f41c03e2b3b0bccdfec8bdc5b70b67e8821d0ab0
7
+ data.tar.gz: 02d02291d91aab7a7d1ff28e8f6491701728590e9a96d3f3da1a7656909a319e11dabcbbba47876d56a3177f502f7021d9a59b9d91d7579997ed527347971bb1
@@ -1,3 +1,3 @@
1
1
  module CocoapodsPodfile_patch
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -39,17 +39,17 @@ module Pod
39
39
  #
40
40
  def use_patch_file!(patchfile_path = 'Podfile.patch')
41
41
 
42
- @current_patch_files ||= []
43
- if @current_patch_files.include? patchfile_path
42
+ @CococapodsPodfilePatch_current_patch_files ||= []
43
+ if @CococapodsPodfilePatch_current_patch_files.include? patchfile_path
44
44
  # Yes, you could even use it recureively, but don't use the same patch file.
45
45
  raise "`use_patch_file!` called recursively. Most case is it's used in Patch file."
46
46
  return
47
47
  end
48
48
 
49
- @current_patch_files << patchfile_path
49
+ @CococapodsPodfilePatch_current_patch_files << patchfile_path
50
50
  require 'cocoapods-podfile_patch/podfile_patch'
51
- @patch_target = PodfilePatch.new.load_patch_target self, patchfile_path
52
- @current_patch_files.delete(patchfile_path)
51
+ @CococapodsPodfilePatch_patch_target = CococapodsPodfilePatch::PodfilePatch.new.load_patch_target self, patchfile_path
52
+ @CococapodsPodfilePatch_current_patch_files.delete(patchfile_path)
53
53
  end
54
54
 
55
55
  end
@@ -62,8 +62,8 @@ module Pod
62
62
  define_method(:initialize) do |defined_in_file = nil, internal_hash = {}, &block|
63
63
  old_initialize_function.bind(self).(defined_in_file, internal_hash, &block)
64
64
 
65
- if not @patch_target.nil?
66
- PodfilePatch.new.merge_patch_and_original_podfile(self, @patch_target)
65
+ if not @CococapodsPodfilePatch_patch_target.nil?
66
+ CococapodsPodfilePatch::PodfilePatch.new.merge_patch_and_original_podfile(self, @CococapodsPodfilePatch_patch_target)
67
67
  end
68
68
  end
69
69
  end
@@ -4,248 +4,246 @@ require 'cocoapods-core/podfile'
4
4
  require 'pathname'
5
5
  require 'set'
6
6
 
7
+ module CococapodsPodfilePatch
8
+ class PodfilePatch
7
9
 
8
- class PodfilePatch
10
+ ABSTRACT_PATCH_TARGET_NAME = "#{self}-fake-target"
9
11
 
10
- ABSTRACT_PATCH_TARGET_NAME = "cocoapods-podfile_patch-fake-target"
12
+ def load_patch_target(podfile, patchfile_path)
11
13
 
14
+ # find patch file
15
+ patch_file_path = Pathname.new(patchfile_path)
16
+ if not patch_file_path.expand_path.file?
17
+ podfile_root_path = Pathname.new(podfile.defined_in_file).dirname
18
+ patch_file_path = (podfile_root_path + patch_file_path).expand_path
19
+ end
20
+ if not patch_file_path.file?
21
+ Pod::UI.info "Podfile patch feature is enabled. (No patch file now.)"
22
+ return
23
+ end
24
+
25
+ # load patch file content. And add it to a abstract target
26
+ contents = File.read(patch_file_path)
27
+ podfile.target ABSTRACT_PATCH_TARGET_NAME do
28
+ podfile.instance_eval contents
29
+ end
12
30
 
13
- def load_patch_target(podfile, patchfile_path)
31
+ # find the patch target and delete it in original podfile
32
+ root_target = podfile.root_target_definitions[0]
33
+ patch_target = root_target.children.find {|t| t.name == ABSTRACT_PATCH_TARGET_NAME }
34
+ root_target.children.delete(patch_target)
14
35
 
15
- # find patch file
16
- patch_file_path = Pathname.new(patchfile_path)
17
- if not patch_file_path.expand_path.file?
18
- podfile_root_path = Pathname.new(podfile.defined_in_file).dirname
19
- patch_file_path = (podfile_root_path + patch_file_path).expand_path
20
- end
21
- if not patch_file_path.file?
22
- Pod::UI.info "Podfile patch feature is enabled. (No patch file now.)"
23
- return
36
+ return patch_target
24
37
  end
25
38
 
26
- # load patch file content. And add it to a abstract target
27
- contents = File.read(patch_file_path)
28
- podfile.target ABSTRACT_PATCH_TARGET_NAME do
29
- podfile.instance_eval contents
30
- end
31
-
32
- # find the patch target and delete it in original podfile
33
- root_target = podfile.root_target_definitions[0]
34
- patch_target = root_target.children.find {|t| t.name == ABSTRACT_PATCH_TARGET_NAME }
35
- root_target.children.delete(patch_target)
36
-
37
- return patch_target
38
- end
39
-
40
39
 
41
- def merge_patch_and_original_podfile(podfile, patch_target)
42
-
43
- root_target = podfile.root_target_definitions[0]
44
-
45
- # merge patch_target and original_target
46
- patch_target.name = root_target.name
47
- merge_target_definitions_dependency(root_target, patch_target)
48
-
49
- Pod::UI.titled_section "Podfile patch feature is enabled" do
50
- next unless Pod::UI.config.verbose?
51
- Pod::UI.section "Patchfile Info" do
52
- self.print_podfile_raw_dependencies patch_target
53
- end
54
- Pod::UI.section "Modified Podfile Info" do
55
- self.print_podfile_raw_dependencies root_target
40
+ def merge_patch_and_original_podfile(podfile, patch_target)
41
+
42
+ root_target = podfile.root_target_definitions[0]
43
+
44
+ # merge patch_target and original_target
45
+ patch_target.name = root_target.name
46
+ merge_target_definitions_dependency(root_target, patch_target)
47
+
48
+ Pod::UI.titled_section "Podfile patch feature is enabled" do
49
+ next unless Pod::UI.config.verbose?
50
+ Pod::UI.section "Patchfile Info" do
51
+ self.print_podfile_raw_dependencies patch_target
52
+ end
53
+ Pod::UI.section "Modified Podfile Info" do
54
+ self.print_podfile_raw_dependencies root_target
55
+ end
56
56
  end
57
57
  end
58
- end
59
58
 
60
59
 
61
- def merge_target_definitions_dependency(targetdef, patch_targetdef)
62
- # Demo Data
63
- # Original Target
64
- # ```
65
- # TargetDefination 'Pods':
66
- # [{"BDWebImage"=>["1.0.1.1-binary"]}]
67
- #
68
- # TargetDefination 'Pods-FrameworkDemos_Tests':
69
- # ["BDWebImage/SDAdapter", "BDWebImage/Download", {"TTNetworkManager"=>["2.2.8.46-rc.18"]}, {"AFNetworking"=>[{:path=>"/Users/lea/Downloads/AFNetworking"}]}]
70
- #
71
- # TargetDefination 'Pods-FrameworkDemos_Example':
72
- # ["BDWebImage", {"TTNetworkManager"=>["2.2.8.46-rc.18"]}]
73
- # ```
74
- #
75
- # Patch Target
76
- # ```
77
- # TargetDefination 'Pods':
78
- # [{"AFNetworking"=>["2.3"]}]
79
- # ```
80
-
81
- # 1. find all dependency patch_targetdef: patched_dependencies
82
- # 2. modify targetdef's depedencies recursively:
83
- # - replace the requirement to the one in patched_dependencies
84
- # - add to target if not contained
85
-
86
-
87
- def get_raw_dependencies(target_defination)
88
- (target_defination.send :get_hash_value, 'dependencies') || []
89
- end
60
+ def merge_target_definitions_dependency(targetdef, patch_targetdef)
61
+ # Demo Data
62
+ # Original Target
63
+ # ```
64
+ # TargetDefination 'Pods':
65
+ # [{"BDWebImage"=>["1.0.1.1-binary"]}]
66
+ #
67
+ # TargetDefination 'Pods-FrameworkDemos_Tests':
68
+ # ["BDWebImage/SDAdapter", "BDWebImage/Download", {"TTNetworkManager"=>["2.2.8.46-rc.18"]}, {"AFNetworking"=>[{:path=>"/Users/lea/Downloads/AFNetworking"}]}]
69
+ #
70
+ # TargetDefination 'Pods-FrameworkDemos_Example':
71
+ # ["BDWebImage", {"TTNetworkManager"=>["2.2.8.46-rc.18"]}]
72
+ # ```
73
+ #
74
+ # Patch Target
75
+ # ```
76
+ # TargetDefination 'Pods':
77
+ # [{"AFNetworking"=>["2.3"]}]
78
+ # ```
79
+
80
+ # 1. find all dependency patch_targetdef: patched_dependencies
81
+ # 2. modify targetdef's depedencies recursively:
82
+ # - replace the requirement to the one in patched_dependencies
83
+ # - add to target if not contained
84
+
85
+
86
+ def get_raw_dependencies(target_defination)
87
+ (target_defination.send :get_hash_value, 'dependencies') || []
88
+ end
90
89
 
91
- all_dependencies_in_patch = begin
92
- def all_dependencies(target_defination)
93
- d = get_raw_dependencies(target_defination)
94
- d += (target_defination.children.map do |subtarget|
95
- all_dependencies(subtarget)
96
- end.flatten || [])
97
- d
90
+ all_dependencies_in_patch = begin
91
+ def all_dependencies(target_defination)
92
+ d = get_raw_dependencies(target_defination)
93
+ d += (target_defination.children.map do |subtarget|
94
+ all_dependencies(subtarget)
95
+ end.flatten || [])
96
+ d
97
+ end
98
+ all_dependencies(patch_targetdef)
98
99
  end
99
- all_dependencies(patch_targetdef)
100
- end
101
-
102
- def transform_target_dependency_to_dict(dependencies)
103
- dict = {}
104
- dependencies.each do |name_or_hash|
105
- if name_or_hash.is_a?(Hash)
106
- name = name_or_hash.keys.first
107
- requirements = name_or_hash.values.first
108
- dict[name] = requirements
109
- else
110
- dict[name_or_hash] = {}
100
+
101
+ def transform_target_dependency_to_dict(dependencies)
102
+ dict = {}
103
+ dependencies.each do |name_or_hash|
104
+ if name_or_hash.is_a?(Hash)
105
+ name = name_or_hash.keys.first
106
+ requirements = name_or_hash.values.first
107
+ dict[name] = requirements
108
+ else
109
+ dict[name_or_hash] = {}
110
+ end
111
111
  end
112
+ dict
112
113
  end
113
- dict
114
- end
115
114
 
116
- dependencies_dict_in_patch = transform_target_dependency_to_dict(all_dependencies_in_patch)
115
+ dependencies_dict_in_patch = transform_target_dependency_to_dict(all_dependencies_in_patch)
117
116
 
118
- def modify_target_defination_recursively(target_defination, &block)
119
- block.call(target_defination)
120
- target_defination.children.each { |t| modify_target_defination_recursively(t, &block) }
121
- end
117
+ def modify_target_defination_recursively(target_defination, &block)
118
+ block.call(target_defination)
119
+ target_defination.children.each { |t| modify_target_defination_recursively(t, &block) }
120
+ end
122
121
 
123
- patch_file_all_targets_dict = begin
124
- targets = {}
125
- modify_target_defination_recursively(patch_targetdef) do |t|
126
- targets[t.name] = t
122
+ patch_file_all_targets_dict = begin
123
+ targets = {}
124
+ modify_target_defination_recursively(patch_targetdef) do |t|
125
+ targets[t.name] = t
126
+ end
127
+ targets
127
128
  end
128
- targets
129
- end
130
129
 
131
- patch_file_target_to_dependency_dict = begin
132
- dict = {}
133
- modify_target_defination_recursively(patch_targetdef) do |t|
134
- deps = get_raw_dependencies(t)
135
- dict[t.name] = transform_target_dependency_to_dict(deps)
130
+ patch_file_target_to_dependency_dict = begin
131
+ dict = {}
132
+ modify_target_defination_recursively(patch_targetdef) do |t|
133
+ deps = get_raw_dependencies(t)
134
+ dict[t.name] = transform_target_dependency_to_dict(deps)
135
+ end
136
+ dict
136
137
  end
137
- dict
138
- end
139
138
 
140
- modified_dependencies_names = {} # pod name => target name
139
+ modified_dependencies_names = {} # pod name => target name
141
140
 
142
- modify_target_defination_recursively(targetdef) do |t|
143
- deps = get_raw_dependencies(t)
144
- new_deps = []
145
- deps_set = Set.new
146
-
147
- # modify origianl dependency
148
- deps.each do |name_or_hash|
149
- name = nil
150
- if name_or_hash.is_a?(Hash)
151
- name = name_or_hash.keys.first
152
- else
153
- name = name_or_hash
141
+ modify_target_defination_recursively(targetdef) do |t|
142
+ deps = get_raw_dependencies(t)
143
+ new_deps = []
144
+ deps_set = Set.new
145
+
146
+ # modify origianl dependency
147
+ deps.each do |name_or_hash|
148
+ name = nil
149
+ if name_or_hash.is_a?(Hash)
150
+ name = name_or_hash.keys.first
151
+ else
152
+ name = name_or_hash
153
+ end
154
+ if dependencies_dict_in_patch.key? name
155
+ new_deps << {name => dependencies_dict_in_patch[name]}
156
+ modified_dependencies_names[name] = t
157
+ else
158
+ new_deps << name_or_hash
159
+ end
160
+ deps_set.add(name)
154
161
  end
155
- if dependencies_dict_in_patch.key? name
156
- new_deps << {name => dependencies_dict_in_patch[name]}
157
- modified_dependencies_names[name] = t
158
- else
159
- new_deps << name_or_hash
162
+ # add new dependency
163
+ patching_deps = patch_file_target_to_dependency_dict[t.name]
164
+ if not patching_deps.blank?
165
+ patching_deps.each do |name, requirements|
166
+ if not deps_set.include? name
167
+ new_deps << (requirements.empty? ? name : {name => requirements})
168
+ modified_dependencies_names[name] = t
169
+ end
170
+ end
160
171
  end
161
- deps_set.add(name)
172
+
173
+ t.send :set_hash_value, "dependencies", new_deps
162
174
  end
163
- # add new dependency
164
- patching_deps = patch_file_target_to_dependency_dict[t.name]
165
- if not patching_deps.blank?
166
- patching_deps.each do |name, requirements|
167
- if not deps_set.include? name
168
- new_deps << (requirements.empty? ? name : {name => requirements})
169
- modified_dependencies_names[name] = t
175
+
176
+ # handle MODULAR_HEADERS & INHIBIT_WARNING
177
+ [ 'inhibit_warnings',
178
+ 'use_modular_headers'].each do |method|
179
+ modify_target_defination_recursively(targetdef) do |t|
180
+ original_inhibit_warning_dict = t.send(:get_hash_value,method, {})
181
+ original_inhibit_warning_dict.each do |key, value|
182
+ # the key is "for_pods" or "not_for_pods" or "all"
183
+ # Clear if patchfile have modified the pod
184
+ next unless value.kind_of? Array
185
+ value.reject! { |name| modified_dependencies_names.include? name}
186
+ end
187
+
188
+ patch_target = patch_file_all_targets_dict[t.name]
189
+ if not patch_target.nil?
190
+ patch_inhibit_warning_dict = patch_target.send(:get_hash_value,method, {})
191
+ patch_inhibit_warning_dict.each do |key, value|
192
+ if value.kind_of? Array
193
+ original = original_inhibit_warning_dict[key] || []
194
+ original.concat(value).uniq!
195
+ original_inhibit_warning_dict[key] = original
196
+ elsif [true, false].include? value # "all"
197
+ original_inhibit_warning_dict[key] = value
198
+ end
199
+ end
200
+ end
201
+ # delete key if blank
202
+ if original_inhibit_warning_dict.empty?
203
+ t.send(:internal_hash).delete(method)
170
204
  end
171
205
  end
172
206
  end
173
207
 
174
- t.send :set_hash_value, "dependencies", new_deps
175
- end
176
-
177
- # handle MODULAR_HEADERS & INHIBIT_WARNING
178
- [ 'inhibit_warnings',
179
- 'use_modular_headers'].each do |method|
208
+ # handle CONFIGURATION_WHITELIST
180
209
  modify_target_defination_recursively(targetdef) do |t|
181
- original_inhibit_warning_dict = t.send(:get_hash_value,method, {})
182
- original_inhibit_warning_dict.each do |key, value|
183
- # the key is "for_pods" or "not_for_pods" or "all"
210
+ key = "configuration_pod_whitelist"
211
+ original = t.send :get_hash_value, key, {}
212
+ original.each do |config_name, pods|
184
213
  # Clear if patchfile have modified the pod
185
- next unless value.kind_of? Array
186
- value.reject! { |name| modified_dependencies_names.include? name}
214
+ next unless pods.kind_of? Array
215
+ pods.reject! { |name| modified_dependencies_names.include? name}
187
216
  end
188
-
217
+
189
218
  patch_target = patch_file_all_targets_dict[t.name]
190
219
  if not patch_target.nil?
191
- patch_inhibit_warning_dict = patch_target.send(:get_hash_value,method, {})
192
- patch_inhibit_warning_dict.each do |key, value|
193
- if value.kind_of? Array
194
- original = original_inhibit_warning_dict[key] || []
195
- original.concat(value).uniq!
196
- original_inhibit_warning_dict[key] = original
197
- elsif [true, false].include? value # "all"
198
- original_inhibit_warning_dict[key] = value
199
- end
220
+ patched = patch_target.send :raw_configuration_pod_whitelist
221
+ patched.each do |config_name, pods|
222
+ next unless pods.kind_of? Array
223
+ original_pods = original[config_name] || []
224
+ original_pods.concat(pods).uniq!
225
+ original[config_name] = original_pods
200
226
  end
201
227
  end
202
228
  # delete key if blank
203
- if original_inhibit_warning_dict.empty?
204
- t.send(:internal_hash).delete(method)
229
+ if original.empty?
230
+ t.send(:internal_hash).delete(key)
205
231
  end
206
232
  end
207
233
  end
208
234
 
209
- # handle CONFIGURATION_WHITELIST
210
- modify_target_defination_recursively(targetdef) do |t|
211
- key = "configuration_pod_whitelist"
212
- original = t.send :get_hash_value, key, {}
213
- original.each do |config_name, pods|
214
- # Clear if patchfile have modified the pod
215
- next unless pods.kind_of? Array
216
- pods.reject! { |name| modified_dependencies_names.include? name}
217
- end
218
-
219
- patch_target = patch_file_all_targets_dict[t.name]
220
- if not patch_target.nil?
221
- patched = patch_target.send :raw_configuration_pod_whitelist
222
- patched.each do |config_name, pods|
223
- next unless pods.kind_of? Array
224
- original_pods = original[config_name] || []
225
- original_pods.concat(pods).uniq!
226
- original[config_name] = original_pods
235
+ def print_podfile_raw_dependencies(target)
236
+
237
+ def print_target_def_and_its_dependencies(target_def, intend = "")
238
+ puts "|\n"
239
+ puts "| #{intend}TARGET_DEFINITION: #{target_def}"
240
+ puts "| #{intend}INHIBIT_WARNING: #{target_def.send :raw_inhibit_warnings_hash}"
241
+ puts "| #{intend}DEPS: #{target_def.send :get_hash_value, 'dependencies'}"
242
+ target_def.children.each do |target_def|
243
+ print_target_def_and_its_dependencies(target_def, intend + " ")
227
244
  end
228
245
  end
229
- # delete key if blank
230
- if original.empty?
231
- t.send(:internal_hash).delete(key)
232
- end
233
- end
246
+ print_target_def_and_its_dependencies(target)
247
+ end
234
248
  end
235
-
236
- def print_podfile_raw_dependencies(target)
237
-
238
- def print_target_def_and_its_dependencies(target_def, intend = "")
239
- puts "|\n"
240
- puts "| #{intend}TARGET_DEFINITION: #{target_def}"
241
- puts "| #{intend}INHIBIT_WARNING: #{target_def.send :raw_inhibit_warnings_hash}"
242
- puts "| #{intend}DEPS: #{target_def.send :get_hash_value, 'dependencies'}"
243
- target_def.children.each do |target_def|
244
- print_target_def_and_its_dependencies(target_def, intend + " ")
245
- end
246
- end
247
- print_target_def_and_its_dependencies(target)
248
- end
249
249
  end
250
-
251
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-podfile_patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-27 00:00:00.000000000 Z
11
+ date: 2019-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler