Class: Pod::Resolver

Inherits:
Object
  • Object
show all
Includes:
Config::Mixin
Defined in:
lib/cocoapods/resolver.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Config::Mixin

#config

Constructor Details

- (Resolver) initialize(podfile, sandbox)

A new instance of Resolver



10
11
12
13
14
15
16
# File 'lib/cocoapods/resolver.rb', line 10

def initialize(podfile, sandbox)
  @podfile = podfile
  @sandbox = sandbox
  @cached_sets = {}
  @cached_sources = Source::Aggregate.new
  @log_indent = 0;
end

Instance Attribute Details

- (Object) cached_sets

Returns the value of attribute cached_sets



8
9
10
# File 'lib/cocoapods/resolver.rb', line 8

def cached_sets
  @cached_sets
end

- (Object) cached_sources

Returns the value of attribute cached_sources



8
9
10
# File 'lib/cocoapods/resolver.rb', line 8

def cached_sources
  @cached_sources
end

- (Object) podfile (readonly)

Returns the value of attribute podfile



7
8
9
# File 'lib/cocoapods/resolver.rb', line 7

def podfile
  @podfile
end

- (Object) sandbox (readonly)

Returns the value of attribute sandbox



7
8
9
# File 'lib/cocoapods/resolver.rb', line 7

def sandbox
  @sandbox
end

Instance Method Details

- (Object) find_cached_set(dependency, platform) (private)



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cocoapods/resolver.rb', line 35

def find_cached_set(dependency, platform)
  set_name = dependency.name.split('/').first
  @cached_sets[set_name] ||= begin
    if dependency.specification
      Specification::Set::External.new(dependency.specification)
    elsif external_source = dependency.external_source
      # The platform isn't actually being used by the LocalPod instance
      # that's being used behind the scenes, but passing it anyways for
      # completeness sake.
      specification = external_source.specification_from_sandbox(@sandbox, platform)
      set = Specification::Set::External.new(specification)
      if dependency.subspec_dependency?
        @cached_sets[dependency.top_level_spec_name] ||= set
      end
      set
    else
      @cached_sources.search(dependency)
    end
  end
end

- (Object) find_dependency_specs(dependent_specification, dependencies, target_definition) (private)



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cocoapods/resolver.rb', line 56

def find_dependency_specs(dependent_specification, dependencies, target_definition)
  @log_indent += 1
  dependencies.each do |dependency|
    puts '  ' * @log_indent + "- #{dependency}" if config.verbose?
    set = find_cached_set(dependency, target_definition.platform)
    set.required_by(dependent_specification)
    # Ensure we don't resolve the same spec twice for one target
    unless @loaded_specs.include?(dependency.name)
    spec = set.specification_by_name(dependency.name)
      @loaded_specs << spec.name
      @specs[spec.name] = spec
      spec.activate_platform(target_definition.platform)
      # And recursively load the dependencies of the spec.
      find_dependency_specs(spec, spec.dependencies, target_definition) if spec.dependencies
    end
    validate_platform!(spec || @specs[dependency.name], target_definition)
  end
  @log_indent -= 1
end

- (Object) resolve



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cocoapods/resolver.rb', line 18

def resolve
  @specs = {}
  targets_and_specs = {}

  @podfile.target_definitions.values.each do |target_definition|
    puts "\nResolving dependencies for target `#{target_definition.name}' (#{target_definition.platform})".green if config.verbose?
    @loaded_specs = []
    find_dependency_specs(@podfile, target_definition.dependencies, target_definition)
    targets_and_specs[target_definition] = @specs.values_at(*@loaded_specs).sort_by(&:name)
  end

  @specs.values.sort_by(&:name)
  targets_and_specs
end

- (Object) validate_platform!(spec, target) (private)



76
77
78
79
80
# File 'lib/cocoapods/resolver.rb', line 76

def validate_platform!(spec, target)
  unless spec.available_platforms.any? { |platform| target.platform.supports?(platform) }
    raise Informative, "[!] The platform of the target `#{target.name}' (#{target.platform}) is not compatible with `#{spec}' which has a minimun requirement of #{spec.available_platforms.join(' - ')}.".red
  end
end