cocoapods-core 0.27.1 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cocoapods-core.rb +0 -2
  3. data/lib/cocoapods-core/core_ui.rb +0 -1
  4. data/lib/cocoapods-core/dependency.rb +20 -15
  5. data/lib/cocoapods-core/gem_version.rb +1 -1
  6. data/lib/cocoapods-core/github.rb +1 -1
  7. data/lib/cocoapods-core/lockfile.rb +15 -11
  8. data/lib/cocoapods-core/platform.rb +10 -6
  9. data/lib/cocoapods-core/podfile.rb +18 -11
  10. data/lib/cocoapods-core/podfile/dsl.rb +25 -23
  11. data/lib/cocoapods-core/podfile/target_definition.rb +60 -36
  12. data/lib/cocoapods-core/requirement.rb +2 -2
  13. data/lib/cocoapods-core/source.rb +34 -10
  14. data/lib/cocoapods-core/source/acceptor.rb +12 -8
  15. data/lib/cocoapods-core/source/aggregate.rb +22 -9
  16. data/lib/cocoapods-core/source/health_reporter.rb +2 -2
  17. data/lib/cocoapods-core/specification.rb +14 -12
  18. data/lib/cocoapods-core/specification/consumer.rb +8 -6
  19. data/lib/cocoapods-core/specification/dsl.rb +66 -18
  20. data/lib/cocoapods-core/specification/dsl/attribute.rb +5 -4
  21. data/lib/cocoapods-core/specification/dsl/deprecations.rb +35 -23
  22. data/lib/cocoapods-core/specification/dsl/platform_proxy.rb +16 -11
  23. data/lib/cocoapods-core/specification/linter.rb +107 -36
  24. data/lib/cocoapods-core/specification/root_attribute_accessors.rb +16 -4
  25. data/lib/cocoapods-core/specification/set.rb +41 -24
  26. data/lib/cocoapods-core/specification/set/presenter.rb +7 -5
  27. data/lib/cocoapods-core/specification/yaml.rb +6 -2
  28. data/lib/cocoapods-core/standard_error.rb +3 -3
  29. data/lib/cocoapods-core/vendor.rb +0 -1
  30. data/lib/cocoapods-core/vendor/requirement.rb +9 -9
  31. data/lib/cocoapods-core/vendor/version.rb +143 -140
  32. data/lib/cocoapods-core/version.rb +5 -6
  33. data/lib/cocoapods-core/yaml_converter.rb +3 -2
  34. metadata +17 -3
@@ -30,7 +30,7 @@ module Pod
30
30
  @children = []
31
31
 
32
32
  unless internal_hash
33
- self.name = name
33
+ self.name = name
34
34
  end
35
35
  if parent.is_a?(TargetDefinition)
36
36
  parent.children << self
@@ -75,7 +75,11 @@ module Pod
75
75
  # definition including the inherited ones.
76
76
  #
77
77
  def dependencies
78
- non_inherited_dependencies + ((exclusive? || parent.nil?) ? [] : parent.dependencies)
78
+ if exclusive? || parent.nil?
79
+ non_inherited_dependencies
80
+ else
81
+ non_inherited_dependencies + parent.dependencies
82
+ end
79
83
  end
80
84
 
81
85
  # @return [Array] The list of the dependencies of the target definition,
@@ -105,7 +109,7 @@ module Pod
105
109
  end
106
110
  end
107
111
 
108
- alias :to_s :label
112
+ alias_method :to_s, :label
109
113
 
110
114
  # @return [String] A string representation suitable for debug.
111
115
  #
@@ -153,8 +157,10 @@ module Pod
153
157
  def exclusive?
154
158
  if root?
155
159
  true
160
+ elsif get_hash_value('exclusive')
161
+ true
156
162
  else
157
- get_hash_value('exclusive') || ( platform && parent && parent.platform != platform )
163
+ platform && parent && parent.platform != platform
158
164
  end
159
165
  end
160
166
 
@@ -250,7 +256,11 @@ module Pod
250
256
  # represents their type (`:debug` or `:release`).
251
257
  #
252
258
  def build_configurations
253
- get_hash_value('build_configurations') || (parent.build_configurations unless root?)
259
+ if root?
260
+ get_hash_value('build_configurations')
261
+ else
262
+ get_hash_value('build_configurations') || parent.build_configurations
263
+ end
254
264
  end
255
265
 
256
266
  # Sets the build configurations for this target.
@@ -272,10 +282,14 @@ module Pod
272
282
  # return true for any asked pod.
273
283
  #
274
284
  def inhibits_warnings_for_pod?(pod_name)
275
- return true if inhibit_warnings_hash['all'] || (parent.inhibits_warnings_for_pod?(pod_name) unless root?)
276
-
277
- inhibit_warnings_hash['for_pods'] ||= []
278
- inhibit_warnings_hash['for_pods'].include? pod_name
285
+ if inhibit_warnings_hash['all']
286
+ true
287
+ elsif !root? && parent.inhibits_warnings_for_pod?(pod_name)
288
+ true
289
+ else
290
+ inhibit_warnings_hash['for_pods'] ||= []
291
+ inhibit_warnings_hash['for_pods'].include? pod_name
292
+ end
279
293
  end
280
294
 
281
295
  # Sets whether the target definition should inhibit the warnings during
@@ -339,11 +353,12 @@ module Pod
339
353
  #
340
354
  def set_platform(name, target = nil)
341
355
  unless [:ios, :osx].include?(name)
342
- raise StandardError, "Unsupported platform `#{name}`. Platform must be `:ios` or `:osx`."
356
+ raise StandardError, "Unsupported platform `#{name}`. Platform " \
357
+ "must be `:ios` or `:osx`."
343
358
  end
344
359
 
345
360
  if target
346
- value = {name.to_s => target}
361
+ value = { name.to_s => target }
347
362
  else
348
363
  value = name.to_s
349
364
  end
@@ -401,7 +416,8 @@ module Pod
401
416
  def store_podspec(options = nil)
402
417
  if options
403
418
  unless options.keys.all? { |key| [:name, :path].include?(key) }
404
- raise StandardError, "Unrecognized options for the podspec method `#{options}`"
419
+ raise StandardError, "Unrecognized options for the podspec " \
420
+ "method `#{options}`"
405
421
  end
406
422
  get_hash_value('podspecs', []) << options
407
423
  else
@@ -418,18 +434,18 @@ module Pod
418
434
  # @return [Array] The keys used by the hash representation of the
419
435
  # target definition.
420
436
  #
421
- HASH_KEYS = [
422
- 'name',
423
- 'platform',
424
- 'podspecs',
425
- 'exclusive',
426
- 'link_with',
427
- 'link_with_first_target',
428
- 'inhibit_warnings',
429
- 'user_project_path',
430
- 'build_configurations',
431
- 'dependencies',
432
- 'children'
437
+ HASH_KEYS = %w[
438
+ name
439
+ platform
440
+ podspecs
441
+ exclusive
442
+ link_with
443
+ link_with_first_target
444
+ inhibit_warnings
445
+ user_project_path
446
+ build_configurations
447
+ dependencies
448
+ children
433
449
  ].freeze
434
450
 
435
451
  # @return [Hash] The hash representation of the target definition.
@@ -488,7 +504,9 @@ module Pod
488
504
  # @return [void]
489
505
  #
490
506
  def set_hash_value(key, value)
491
- raise StandardError, "Unsupported hash key `#{key}`" unless HASH_KEYS.include?(key)
507
+ unless HASH_KEYS.include?(key)
508
+ raise StandardError, "Unsupported hash key `#{key}`"
509
+ end
492
510
  internal_hash[key] = value
493
511
  end
494
512
 
@@ -506,20 +524,21 @@ module Pod
506
524
  # @return [Object] The value for the key.
507
525
  #
508
526
  def get_hash_value(key, base_value = nil)
509
- raise StandardError, "Unsupported hash key `#{key}`" unless HASH_KEYS.include?(key)
527
+ unless HASH_KEYS.include?(key)
528
+ raise StandardError, "Unsupported hash key `#{key}`"
529
+ end
510
530
  internal_hash[key] ||= base_value
511
531
  end
512
532
 
513
- # Returns the inhibit_warnings hash prepopulated with default values
533
+ # Returns the inhibit_warnings hash pre-populated with default values.
514
534
  #
515
- # @return [Hash<String, Array>] Hash with :all key for inhibiting all warnings,
516
- # and :for_pods key for inhibiting warnings per pod
535
+ # @return [Hash<String, Array>] Hash with :all key for inhibiting all
536
+ # warnings, and :for_pods key for inhibiting warnings per Pod.
517
537
  #
518
538
  def inhibit_warnings_hash
519
539
  get_hash_value('inhibit_warnings', {})
520
540
  end
521
541
 
522
-
523
542
  # @return [Array<Dependency>] The dependencies specified by the user for
524
543
  # this target definition.
525
544
  #
@@ -550,7 +569,7 @@ module Pod
550
569
  file = podspec_path_from_options(options)
551
570
  spec = Specification.from_file(file)
552
571
  all_specs = [spec, *spec.recursive_subspecs]
553
- all_deps = all_specs.map{ |s| s.dependencies(platform) }.flatten
572
+ all_deps = all_specs.map { |s| s.dependencies(platform) }.flatten
554
573
  all_deps.reject { |dep| dep.root_name == spec.root.name }
555
574
  end.flatten.uniq
556
575
  end
@@ -565,14 +584,19 @@ module Pod
565
584
  #
566
585
  def podspec_path_from_options(options)
567
586
  if path = options[:path]
568
- path_with_ext = File.extname(path) == '.podspec' ? path : "#{path}.podspec"
587
+ if File.extname(path) == '.podspec'
588
+ path_with_ext = path
589
+ else
590
+ path_with_ext = "#{path}.podspec"
591
+ end
569
592
  path_without_tilde = path_with_ext.gsub('~', ENV['HOME'])
570
- file = podfile.defined_in_file.dirname + path_without_tilde
593
+ podfile.defined_in_file.dirname + path_without_tilde
571
594
  elsif name = options[:name]
572
595
  name = File.extname(name) == '.podspec' ? name : "#{name}.podspec"
573
- file = podfile.defined_in_file.dirname + name
596
+ podfile.defined_in_file.dirname + name
574
597
  elsif options[:autodetect]
575
- file = Pathname.glob(podfile.defined_in_file.dirname + '*.podspec').first
598
+ glob_pattern = podfile.defined_in_file.dirname + '*.podspec'
599
+ Pathname.glob(glob_pattern).first
576
600
  end
577
601
  end
578
602
 
@@ -582,7 +606,7 @@ module Pod
582
606
  # @param [String] pod name
583
607
  #
584
608
  # @param [Array] requirements
585
- # If :inhibit_warnings is the only key in the hash, the hash
609
+ # If :inhibit_warnings is the only key in the hash, the hash
586
610
  # should be destroyed because it confuses Gem::Dependency.
587
611
  #
588
612
  # @return [void]
@@ -63,8 +63,8 @@ module Pod
63
63
  raise ArgumentError, "Illformed requirement `#{input.inspect}`"
64
64
  end
65
65
 
66
- operator = $1 || "="
67
- version = Version.new($2)
66
+ operator = Regexp.last_match[1] || "="
67
+ version = Version.new(Regexp.last_match[2])
68
68
  [operator, version]
69
69
  end
70
70
 
@@ -34,7 +34,6 @@ module Pod
34
34
 
35
35
  alias_method :to_s, :name
36
36
 
37
-
38
37
  # @return [Integer] compares a source with another one for sorting
39
38
  # purposes.
40
39
  #
@@ -42,7 +41,7 @@ module Pod
42
41
  # this convention should be used in any case where sources need to
43
42
  # be disambiguated.
44
43
  #
45
- def <=> (other)
44
+ def <=>(other)
46
45
  name <=> other.name
47
46
  end
48
47
 
@@ -57,7 +56,7 @@ module Pod
57
56
  def pods
58
57
  specs_dir_as_string = specs_dir.to_s
59
58
  Dir.entries(specs_dir).select do |entry|
60
- valid_name = !(entry =='.' || entry == '..' || entry == '.git')
59
+ valid_name = !(entry == '.' || entry == '..' || entry == '.git')
61
60
  valid_name && File.directory?(File.join(specs_dir_as_string, entry))
62
61
  end
63
62
  end
@@ -90,7 +89,7 @@ module Pod
90
89
  return unless pod_dir.exist?
91
90
  pod_dir.children.map do |v|
92
91
  basename = v.basename.to_s
93
- Version.new(basename) if v.directory? && basename[0,1] != '.'
92
+ Version.new(basename) if v.directory? && basename[0, 1] != '.'
94
93
  end.compact.sort.reverse
95
94
  end
96
95
 
@@ -147,10 +146,16 @@ module Pod
147
146
  # @return [Set] a set for a given dependency. The set is identified by the
148
147
  # name of the dependency and takes into account subspecs.
149
148
  #
150
- def search(dependency)
149
+ # @todo Rename to #load_set
150
+ #
151
+ def search(query)
152
+ if query.is_a?(Dependency)
153
+ name = query.root_name
154
+ else
155
+ name = query
156
+ end
151
157
  pod_sets.find do |set|
152
- # First match the (top level) name, which does not yet load the spec from disk
153
- set.name == dependency.root_name
158
+ set.name == name
154
159
  end
155
160
  end
156
161
 
@@ -173,16 +178,33 @@ module Pod
173
178
  s = set.specification
174
179
  text = "#{s.name} #{s.authors} #{s.summary} #{s.description}"
175
180
  rescue
176
- CoreUI.warn "Skipping `#{set.name}` because the podspec contains errors."
181
+ CoreUI.warn "Skipping `#{set.name}` because the podspec " \
182
+ "contains errors."
177
183
  end
178
184
  set if text && text.downcase.include?(query.downcase)
179
185
  end.compact
180
186
  else
181
- names = pods.select { |pod_name| pod_name.downcase.include?(query.downcase) }
187
+ names = pods.select { |name| name.downcase.include?(query.downcase) }
182
188
  names.map { |pod_name| set(pod_name) }
183
189
  end
184
190
  end
185
191
 
192
+ # Returns the set of the Pod whose name fuzzily matches the given query.
193
+ #
194
+ # @param [String] query
195
+ # The query to search for.
196
+ #
197
+ # @return [Set] The name of the Pod.
198
+ # @return [Nil] If no Pod with a suitable name was found.
199
+ #
200
+ def fuzzy_search(query)
201
+ require 'fuzzy_match'
202
+ pod_name = FuzzyMatch.new(pods).find(query)
203
+ if pod_name
204
+ search(pod_name)
205
+ end
206
+ end
207
+
186
208
  #-------------------------------------------------------------------------#
187
209
 
188
210
  # @!group Representations
@@ -225,8 +247,10 @@ module Pod
225
247
  specs_sub_dir = repo + 'Specs'
226
248
  if specs_sub_dir.exist?
227
249
  @specs_dir = specs_sub_dir
228
- else
250
+ elsif repo.exist?
229
251
  @specs_dir = repo
252
+ else
253
+ raise Informative, "Unable to find a source named: `#{name}`"
230
254
  end
231
255
  end
232
256
  @specs_dir
@@ -68,10 +68,11 @@ module Pod
68
68
  source = spec.source.values_at(*keys).compact.first
69
69
  old_source = reference_spec(spec).source.values_at(*keys).compact.first
70
70
  unless source == old_source
71
- errors << "The source of the spec doesn't match with the recorded ones." \
72
- "Source: `#{source}`. Previous: `#{old_source}`.\n " \
73
- "Please contact the specs repo maintainers if the library changed " \
74
- "location."
71
+ message = "The source of the spec doesn't match with the recorded "
72
+ message << "ones. Source: `#{source}`. Previous: `#{old_source}`.\n "
73
+ message << "Please contact the specs repo maintainers if the"
74
+ message << "library changed location."
75
+ errors << message
75
76
  end
76
77
  end
77
78
 
@@ -85,10 +86,12 @@ module Pod
85
86
  return if !spec.source[:git] || spec.source[:tag]
86
87
  return unless related_specifications(spec)
87
88
  return if previous_spec
88
- has_tagged_spec = related_specifications(spec).any? { |s| s.version != '0.0.1' }
89
+ has_tagged_spec = related_specifications(spec).any? do |s|
90
+ s.version != '0.0.1'
91
+ end
89
92
  if has_tagged_spec
90
- errors << "There is already at least one versioned specification so " \
91
- "untagged versions cannot be accepted."
93
+ errors << "There is already at least one versioned specification " \
94
+ "so untagged versions cannot be accepted."
92
95
  end
93
96
  end
94
97
 
@@ -114,7 +117,8 @@ module Pod
114
117
  spec.dependencies.each do |dep|
115
118
  set = source.search(dep)
116
119
  unless set && set.specification
117
- errors << "Unable to find a specification for the `#{dep}` dependency."
120
+ errors << "Unable to find a specification for the `#{dep}` " \
121
+ "dependency."
118
122
  end
119
123
  end
120
124
  end
@@ -43,7 +43,8 @@ module Pod
43
43
  pods = pods_by_source.values.flatten.uniq
44
44
 
45
45
  pods.map do |pod|
46
- pod_sources = sources.select{ |s| pods_by_source[s].include?(pod) }.compact
46
+ pod_sources = sources.select { |s| pods_by_source[s].include?(pod) }
47
+ pod_sources = pod_sources.compact
47
48
  Specification::Set.new(pod, pod_sources)
48
49
  end
49
50
  end
@@ -102,7 +103,9 @@ module Pod
102
103
  #
103
104
  def search(dependency)
104
105
  sources = all.select { |s| !s.search(dependency).nil? }
105
- Specification::Set.new(dependency.root_name, sources) unless sources.empty?
106
+ unless sources.empty?
107
+ Specification::Set.new(dependency.root_name, sources)
108
+ end
106
109
  end
107
110
 
108
111
  # @return [Array<Set>] the sets that contain the search term.
@@ -116,17 +119,22 @@ module Pod
116
119
  def search_by_name(query, full_text_search = false)
117
120
  pods_by_source = {}
118
121
  result = []
119
- all.each { |s| pods_by_source[s] = s.search_by_name(query, full_text_search).map(&:name) }
122
+ all.each do |s|
123
+ source_pods = s.search_by_name(query, full_text_search)
124
+ pods_by_source[s] = source_pods.map(&:name)
125
+ end
120
126
  root_spec_names = pods_by_source.values.flatten.uniq
121
127
  root_spec_names.each do |pod|
122
128
  sources = []
123
- pods_by_source.each{ |source, pods| sources << source if pods.include?(pod) }
129
+ pods_by_source.each do |source, pods|
130
+ sources << source if pods.include?(pod)
131
+ end
124
132
  result << Specification::Set.new(pod, sources)
125
133
  end
126
134
  if result.empty?
127
135
  extra = ", author, summary, or description" if full_text_search
128
- raise(Informative, "Unable to find a pod with name" \
129
- "#{extra} matching `#{query}'")
136
+ raise Informative, "Unable to find a pod with name" \
137
+ "#{extra} matching `#{query}'"
130
138
  end
131
139
  result
132
140
  end
@@ -170,8 +178,12 @@ module Pod
170
178
  enumerated_names << set.name
171
179
  set_data = search_data[set.name]
172
180
  has_data = set_data && set_data['version']
173
- needs_update = !has_data || Version.new(set_data['version']) < set.required_version
174
- if needs_update
181
+ if has_data
182
+ stored_version = Version.new(set_data['version'])
183
+ if stored_version < set.required_version
184
+ search_data[set.name] = search_data_from_set(set)
185
+ end
186
+ else
175
187
  search_data[set.name] = search_data_from_set(set)
176
188
  end
177
189
  end
@@ -218,7 +230,8 @@ module Pod
218
230
  result['authors'] = spec.authors.keys.sort * ', '
219
231
  result
220
232
  rescue
221
- CoreUI.warn "Skipping `#{set.name}` because the podspec contains errors."
233
+ CoreUI.warn "Skipping `#{set.name}` because the podspec contains " \
234
+ "errors."
222
235
  result
223
236
  end
224
237
 
@@ -111,7 +111,8 @@ module Pod
111
111
  #
112
112
  def check_spec_path(name, version, spec)
113
113
  unless spec.name == name && spec.version.to_s == version.to_s
114
- report.add_message(:error, "Incorrect path #{ spec.defined_in_file }", name, spec.version)
114
+ message = "Incorrect path #{ spec.defined_in_file }"
115
+ report.add_message(:error, message, name, spec.version)
115
116
  end
116
117
  end
117
118
 
@@ -198,4 +199,3 @@ module Pod
198
199
  end
199
200
  end
200
201
  end
201
-
@@ -68,7 +68,7 @@ module Pod
68
68
  # subspecs == other.subspecs &&
69
69
  # pre_install_callback == other.pre_install_callback &&
70
70
  # post_install_callback == other.post_install_callback
71
- self.to_s == other.to_s
71
+ to_s == other.to_s
72
72
  end
73
73
 
74
74
  # @see ==
@@ -126,7 +126,8 @@ module Pod
126
126
  def self.name_and_version_from_string(string_representation)
127
127
  match_data = string_representation.match(/(\S*) \((.*)\)/)
128
128
  unless match_data
129
- raise Informative, "Invalid string representation for a Specification: `#{string_representation}`."
129
+ raise Informative, "Invalid string representation for a " \
130
+ "Specification: `#{string_representation}`."
130
131
  end
131
132
  name = match_data[1]
132
133
  vers = Version.new(match_data[2])
@@ -202,12 +203,12 @@ module Pod
202
203
  if relative_name.nil? || relative_name == base_name
203
204
  self
204
205
  else
205
- remainder = relative_name[base_name.size+1..-1]
206
+ remainder = relative_name[base_name.size + 1..-1]
206
207
  subspec_name = remainder.split('/').shift
207
- subspec = subspecs.find { |s| s.name == "#{self.name}/#{subspec_name}" }
208
+ subspec = subspecs.find { |s| s.name == "#{name}/#{subspec_name}" }
208
209
  unless subspec
209
210
  raise Informative, "Unable to find a specification named " \
210
- "`#{relative_name}` in `#{self.name} (#{self.version})`."
211
+ "`#{relative_name}` in `#{name} (#{version})`."
211
212
  end
212
213
  subspec.subspec_by_name(remainder)
213
214
  end
@@ -368,7 +369,7 @@ module Pod
368
369
  when Hash
369
370
  value
370
371
  else
371
- Hash.new
372
+ {}
372
373
  end
373
374
  end
374
375
 
@@ -531,7 +532,7 @@ module Pod
531
532
  raise Informative, "No podspec exists at path `#{path}`."
532
533
  end
533
534
 
534
- string = File.open(path, 'r:utf-8') { |f| f.read }
535
+ string = File.open(path, 'r:utf-8') { |f| f.read }
535
536
  # Work around for Rubinius incomplete encoding in 1.9 mode
536
537
  if string.respond_to?(:encoding) && string.encoding.name != "UTF-8"
537
538
  string.encode!('UTF-8')
@@ -603,10 +604,11 @@ module Pod
603
604
  #
604
605
  #
605
606
  def self._eval_podspec(string, path)
606
- begin
607
- eval(string, nil, path.to_s)
608
- rescue Exception => e
609
- raise DSLError.new("Invalid `#{path.basename}` file: #{e.message}", path, e.backtrace)
610
- end
607
+ # rubocop:disable Eval
608
+ eval(string, nil, path.to_s)
609
+ # rubocop:enable Eval
610
+ rescue Exception => e
611
+ message = "Invalid `#{path.basename}` file: #{e.message}"
612
+ raise DSLError.new(message, path, e.backtrace)
611
613
  end
612
614
  end