Class: Pod::Installer
- Inherits:
-
Object
- Object
- Pod::Installer
- Includes:
- Config::Mixin, Shared
- Defined in:
- lib/cocoapods/installer.rb
Defined Under Namespace
Modules: Shared Classes: CopyResourcesScript, TargetInstaller
Instance Method Summary collapse
-
#configure_project(projpath) ⇒ Object
For now this assumes just one pods target, i.e.
- #generate_lock_file! ⇒ Object
-
#initialize(podfile) ⇒ Installer
constructor
A new instance of Installer.
- #install! ⇒ Object
- #lock_file ⇒ Object
- #project ⇒ Object
- #target_installers ⇒ Object
Methods included from Shared
#build_specifications, #dependent_specification_sets, #download_only_specifications
Methods included from Config::Mixin
Constructor Details
#initialize(podfile) ⇒ Installer
Returns a new instance of Installer.
164 165 166 |
# File 'lib/cocoapods/installer.rb', line 164 def initialize(podfile) @podfile = podfile end |
Instance Method Details
#configure_project(projpath) ⇒ Object
For now this assumes just one pods target, i.e. only libPods.a. Not sure yet if we should try to be smart with apps that have multiple targets and try to map pod targets to those app targets.
Possible options are:
-
Only cater to the most simple setup
-
Try to automagically figure it out by name. For example, a pod target called ‘:some_target’ could map to an app target called ‘SomeTarget’. (A variation would be to not even camelize the target name, but simply let the user specify it with the proper case.)
-
Let the user specify the app target name as an extra argument, but this seems to be a less good version of the variation on #2.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/cocoapods/installer.rb', line 263 def configure_project(projpath) root = File.dirname(projpath) xcworkspace = File.join(root, File.basename(projpath, '.xcodeproj') + '.xcworkspace') workspace = Xcodeproj::Workspace.new_from_xcworkspace(xcworkspace) pods_projpath = File.join(config.project_pods_root, 'Pods.xcodeproj') root = Pathname.new(root). [projpath, pods_projpath].each do |path| path = Pathname.new(path)..relative_path_from(root).to_s workspace << path unless workspace.include? path end workspace.save_as(xcworkspace) app_project = Xcodeproj::Project.new(projpath) return if app_project.files.find { |file| file.path =~ /libPods\.a$/ } configfile = app_project.files.new('path' => 'Pods/Pods.xcconfig') app_project.targets.each do |target| target.buildConfigurations.each do |config| config.baseConfiguration = configfile end end libfile = app_project.files.new_static_library('Pods') libfile.group = app_project.main_group.groups.find { |g| g.name == 'Frameworks' } app_project.objects.select_by_class(Xcodeproj::Project::PBXFrameworksBuildPhase).each do |build_phase| build_phase.files << libfile.buildFiles.new end copy_resources = app_project.add_shell_script_build_phase('Copy Pods Resources', %{"${SRCROOT}/Pods/Pods-resources.sh"\n}) app_project.targets.each { |target| target.buildPhases << copy_resources } app_project.save_as(projpath) end |
#generate_lock_file! ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/cocoapods/installer.rb', line 221 def generate_lock_file! lock_file.open('w') do |file| file.puts "PODS:" pods = build_specifications.map do |spec| [spec.to_s, spec.dependencies.map(&:to_s).sort] end.sort_by(&:first).each do |name, deps| if deps.empty? file.puts " - #{name}" else file.puts " - #{name}:" deps.each { |dep| file.puts " - #{dep}" } end end unless download_only_specifications.empty? file.puts file.puts "DOWNLOAD_ONLY:" download_only_specifications.map(&:to_s).sort.each do |name| file.puts " - #{name}" end end file.puts file.puts "DEPENDENCIES:" @podfile.dependencies.map(&:to_s).sort.each do |dep| file.puts " - #{dep}" end end end |
#install! ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/cocoapods/installer.rb', line 196 def install! puts "Installing dependencies of: #{@podfile.defined_in_file}" unless config.silent? build_specifications.each(&:install!) root = config.project_pods_root puts "==> Generating support files" unless config.silent? target_installers.each do |target_installer| target_installer.install! target_installer.create_files_in(root) end generate_lock_file! puts "==> Running post install hooks" unless config.silent? # Post install hooks run _before_ saving of project, so that they can alter it before saving. target_installers.each do |target_installer| target_installer.build_specifications.each { |spec| spec.post_install(target_installer) } end @podfile.post_install!(self) puts "==> Generating Xcode project" unless config.silent? projpath = File.join(root, 'Pods.xcodeproj') puts " * Writing Xcode project file to `#{projpath}'" if config.verbose? project.save_as(projpath) end |
#lock_file ⇒ Object
168 169 170 |
# File 'lib/cocoapods/installer.rb', line 168 def lock_file config.project_root + 'Podfile.lock' end |
#project ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/cocoapods/installer.rb', line 172 def project return @project if @project @project = Xcodeproj::Project.for_platform(@podfile.platform) # First we need to resolve dependencies across *all* targets, so that the # same correct versions of pods are being used for all targets. This # happens when we call `build_specifications'. build_specifications.each do |spec| # Add all source files to the project grouped by pod group = @project.add_pod_group(spec.name) spec..each do |path| group.children.new('path' => path.to_s) end end # Add a group to hold all the target support files @project.main_group.groups.new('name' => 'Targets Support Files') @project end |
#target_installers ⇒ Object
190 191 192 193 194 |
# File 'lib/cocoapods/installer.rb', line 190 def target_installers @target_installers ||= @podfile.target_definitions.values.map do |definition| TargetInstaller.new(@podfile, project, definition) end end |