Class: Pod::Installer::TargetInstaller

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Shared

#build_specifications, #dependent_specification_sets, #download_only_specifications

Methods included from Config::Mixin

#config

Constructor Details

#initialize(podfile, project, definition) ⇒ TargetInstaller

Returns a new instance of TargetInstaller.



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

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

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



53
54
55
# File 'lib/cocoapods/installer.rb', line 53

def target
  @target
end

Instance Method Details

#bridge_support_filenameObject



92
93
94
# File 'lib/cocoapods/installer.rb', line 92

def bridge_support_filename
  "#{@definition.lib_name}.bridgesupport"
end

#bridge_support_generatorObject



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

def bridge_support_generator
  BridgeSupportGenerator.new(build_specifications.map do |spec|
    spec.header_files.map do |header|
      config.project_pods_root + header
    end
  end.flatten)
end

#copy_resources_filenameObject



80
81
82
# File 'lib/cocoapods/installer.rb', line 80

def copy_resources_filename
  "#{@definition.lib_name}-resources.sh"
end

#copy_resources_scriptObject



74
75
76
77
78
# File 'lib/cocoapods/installer.rb', line 74

def copy_resources_script
  @copy_resources_script ||= CopyResourcesScript.new(build_specifications.map do |spec|
    spec.expanded_resources
  end.flatten)
end

#create_files_in(root) ⇒ Object



150
151
152
153
154
155
156
157
158
# File 'lib/cocoapods/installer.rb', line 150

def create_files_in(root)
  xcconfig.save_as(root + xcconfig_filename)
  if @podfile.generate_bridge_support?
    bridge_support_generator.save_as(root + bridge_support_filename)
    copy_resources_script.resources << bridge_support_filename
  end
  save_prefix_header_as(root + prefix_header_filename)
  copy_resources_script.save_as(root + copy_resources_filename)
end

#install!Object

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



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/cocoapods/installer.rb', line 110

def install!
  # First add the target to the project
  @target = @project.targets.new_static_library(@definition.lib_name)

  user_header_search_paths = []
  build_specifications.each do |spec|
    xcconfig.merge!(spec.xcconfig)
    # Only add implementation files to the compile phase
    spec.implementation_files.each do |file|
      @target.add_source_file(file, nil, spec.compiler_flags)
    end
    # Add header files to a `copy header build phase` for each destination
    # directory in the pod's header directory.
    spec.copy_header_mappings.each do |header_dir, files|
      copy_phase = @target.copy_files_build_phases.new_pod_dir(spec.name, header_dir)
      files.each do |file|
        @target.add_source_file(file, copy_phase)
      end
    end
    # Collect all header search paths
    user_header_search_paths.concat(spec.user_header_search_paths)
  end
  xcconfig.merge!('USER_HEADER_SEARCH_PATHS' => user_header_search_paths.sort.uniq.join(" "))

  # Add all the target related support files to the group, even the copy
  # resources script although the project doesn't actually use them.
  support_files_group = @project.groups.find do |group|
    group.name == "Targets Support Files"
  end.groups.new("name" => @definition.lib_name)
  support_files_group.files.new('path' => copy_resources_filename)
  prefix_file = support_files_group.files.new('path' => prefix_header_filename)
  xcconfig_file = support_files_group.files.new("path" => xcconfig_filename)
  # Assign the xcconfig as the base config of each config.
  @target.buildConfigurations.each do |config|
    config.baseConfiguration = xcconfig_file
    config.buildSettings['OTHER_LDFLAGS'] = ''
    config.buildSettings['GCC_PREFIX_HEADER'] = prefix_header_filename
  end
end

#prefix_header_filenameObject



105
106
107
# File 'lib/cocoapods/installer.rb', line 105

def prefix_header_filename
  "#{@definition.lib_name}-prefix.pch"
end

#save_prefix_header_as(pathname) ⇒ Object

TODO move out



97
98
99
100
101
102
103
# File 'lib/cocoapods/installer.rb', line 97

def save_prefix_header_as(pathname)
  pathname.open('w') do |header|
    header.puts "#ifdef __OBJC__"
    header.puts "#import #{@podfile.platform == :ios ? '<UIKit/UIKit.h>' : '<Cocoa/Cocoa.h>'}"
    header.puts "#endif"
  end
end

#xcconfigObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/cocoapods/installer.rb', line 59

def xcconfig
  @xcconfig ||= Xcodeproj::Config.new({
    # In a workspace this is where the static library headers should be found.
    'USER_HEADER_SEARCH_PATHS' => '"$(BUILT_PRODUCTS_DIR)/Pods"',
    'ALWAYS_SEARCH_USER_PATHS' => 'YES',
    # This makes categories from static libraries work, which many libraries
    # require, so we add these by default.
    'OTHER_LDFLAGS'            => '-ObjC -all_load',
  })
end

#xcconfig_filenameObject



70
71
72
# File 'lib/cocoapods/installer.rb', line 70

def xcconfig_filename
  "#{@definition.lib_name}.xcconfig"
end