Class: Pod::Installer::TargetInstaller

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Config::Mixin

#config

Constructor Details

- (TargetInstaller) initialize(podfile, project, target_definition)

A new instance of TargetInstaller



9
10
11
# File 'lib/cocoapods/installer/target_installer.rb', line 9

def initialize(podfile, project, target_definition)
  @podfile, @project, @target_definition = podfile, project, target_definition
end

Instance Attribute Details

- (Object) podfile (readonly)

Returns the value of attribute podfile



6
7
8
# File 'lib/cocoapods/installer/target_installer.rb', line 6

def podfile
  @podfile
end

- (Object) project (readonly)

Returns the value of attribute project



6
7
8
# File 'lib/cocoapods/installer/target_installer.rb', line 6

def project
  @project
end

- (Object) requires_arc

Returns the value of attribute requires_arc



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

def requires_arc
  @requires_arc
end

- (Object) target (readonly)

Returns the value of attribute target



6
7
8
# File 'lib/cocoapods/installer/target_installer.rb', line 6

def target
  @target
end

- (Object) target_definition (readonly)

Returns the value of attribute target_definition



6
7
8
# File 'lib/cocoapods/installer/target_installer.rb', line 6

def target_definition
  @target_definition
end

Instance Method Details

- (Object) bridge_support_generator_for(pods, sandbox)



26
27
28
29
30
# File 'lib/cocoapods/installer/target_installer.rb', line 26

def bridge_support_generator_for(pods, sandbox)
  Generator::BridgeSupport.new(pods.map do |pod|
    pod.relative_header_files.map { |header| sandbox.root + header }
  end.flatten)
end

- (Object) configure_build_configurations(xcconfig_file)



85
86
87
88
89
90
91
92
# File 'lib/cocoapods/installer/target_installer.rb', line 85

def configure_build_configurations(xcconfig_file)
  @target.build_configurations.each do |config|
    config.base_configuration = xcconfig_file
    config.build_settings['OTHER_LDFLAGS'] = ''
    config.build_settings['GCC_PREFIX_HEADER'] = @target_definition.prefix_header_name
    config.build_settings['PODS_ROOT'] = '${SRCROOT}'
  end
end

- (Object) copy_resources_script_for(pods)



22
23
24
# File 'lib/cocoapods/installer/target_installer.rb', line 22

def copy_resources_script_for(pods)
  @copy_resources_script ||= Generator::CopyResourcesScript.new(pods.map { |p| p.relative_resource_files }.flatten)
end

- (Object) create_files(pods, sandbox)



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/cocoapods/installer/target_installer.rb', line 94

def create_files(pods, sandbox)
  if @podfile.generate_bridge_support?
     = sandbox.root + @target_definition.bridge_support_name
    puts "- Generating BridgeSupport metadata file at `#{}'" if config.verbose?
    bridge_support_generator_for(pods, sandbox).save_as()
    copy_resources_script_for(pods).resources << @target_definition.bridge_support_name
  end
  puts "- Generating xcconfig file at `#{sandbox.root + @target_definition.xcconfig_name}'" if config.verbose?
  xcconfig.save_as(sandbox.root + @target_definition.xcconfig_name)
  puts "- Generating prefix header at `#{sandbox.root + @target_definition.prefix_header_name}'" if config.verbose?
  save_prefix_header_as(sandbox.root + @target_definition.prefix_header_name, pods)
  puts "- Generating copy resources script at `#{sandbox.root + @target_definition.copy_resources_script_name}'" if config.verbose?
  copy_resources_script_for(pods).save_as(sandbox.root + @target_definition.copy_resources_script_name)
end

- (Object) default_ld_flags (private)



115
116
117
118
119
# File 'lib/cocoapods/installer/target_installer.rb', line 115

def default_ld_flags
  flags = %w{-ObjC}
  flags << '-fobjc-arc' if @podfile.set_arc_compatibility_flag? && self.requires_arc
  flags.join(" ")
end

- (Object) install!(pods, sandbox)

TODO move xcconfig related code into the xcconfig method, like copy_resources_script and generate_bridge_support.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cocoapods/installer/target_installer.rb', line 60

def install!(pods, sandbox)
  self.requires_arc = pods.any? { |pod| pod.requires_arc? }

  @target = @project.add_pod_target(@target_definition.label, @target_definition.platform)

  source_file_descriptions = []
  pods.each do |pod|
    xcconfig.merge!(pod.xcconfig)
    source_file_descriptions += pod.source_file_descriptions

    # TODO: this doesn't need to be done here, it has nothing to do with the target
    pod.link_headers
  end
  @target.add_source_files(source_file_descriptions)

  xcconfig.merge!('HEADER_SEARCH_PATHS' => quoted(sandbox.header_search_paths).join(" "))

  support_files_group = @project.group("Targets Support Files").create_group(@target_definition.label)
  support_files_group.create_files(target_support_files)

  xcconfig_file = support_files_group.files.where(:path => @target_definition.xcconfig_name)
  configure_build_configurations(xcconfig_file)
  create_files(pods, sandbox)
end

- (Object) prefix_header_filename

TODO This has to be removed, but this means the specs have to be updated if they need a reference to the prefix header.



33
34
35
# File 'lib/cocoapods/installer/target_installer.rb', line 33

def prefix_header_filename
  @target_definition.prefix_header_name
end

- (Object) quoted(strings) (private)



111
112
113
# File 'lib/cocoapods/installer/target_installer.rb', line 111

def quoted(strings)
  strings.map { |s| "\"#{s}\"" }
end

- (Object) save_prefix_header_as(pathname, pods)

TODO move out to Generator::PrefixHeader



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cocoapods/installer/target_installer.rb', line 38

def save_prefix_header_as(pathname, pods)
  pathname.open('w') do |header|
    header.puts "#ifdef __OBJC__"
    header.puts "#import #{@target_definition.platform == :ios ? '<UIKit/UIKit.h>' : '<Cocoa/Cocoa.h>'}"
    header.puts "#endif"
    pods.each do |pod|
      if prefix_header_contents = pod.top_specification.prefix_header_contents
        header.puts
        header.puts prefix_header_contents
      elsif prefix_header = pod.prefix_header_file
        header.puts
        header.puts prefix_header.read
      end
    end
  end
end

- (Object) target_support_files



55
56
57
# File 'lib/cocoapods/installer/target_installer.rb', line 55

def target_support_files
  [:copy_resources_script_name, :prefix_header_name, :xcconfig_name].map { |file| @target_definition.send(file) }
end

- (Object) xcconfig



13
14
15
16
17
18
19
20
# File 'lib/cocoapods/installer/target_installer.rb', line 13

def xcconfig
  @xcconfig ||= Xcodeproj::Config.new({
    # In a workspace this is where the static library headers should be found.
    'PODS_ROOT'                => @target_definition.relative_pods_root,
    'ALWAYS_SEARCH_USER_PATHS' => 'YES', # needed to make EmbedReader build
    'OTHER_LDFLAGS'            => default_ld_flags,
  })
end