Commit b14f3708 authored by Fabio Pelosin's avatar Fabio Pelosin

[Installer][Refactor] Add PodsProjectGenerator

parent 28b23c82
...@@ -29,11 +29,8 @@ module Pod ...@@ -29,11 +29,8 @@ module Pod
class Installer class Installer
autoload :Analyzer, 'cocoapods/installer/analyzer' autoload :Analyzer, 'cocoapods/installer/analyzer'
autoload :FileReferencesInstaller, 'cocoapods/installer/file_references_installer'
autoload :PodSourceInstaller, 'cocoapods/installer/pod_source_installer' autoload :PodSourceInstaller, 'cocoapods/installer/pod_source_installer'
autoload :TargetInstaller, 'cocoapods/installer/target_installer' autoload :PodsProjectGenerator, 'cocoapods/installer/pods_project_generator'
autoload :AggregateTargetInstaller, 'cocoapods/installer/target_installer/aggregate_target_installer'
autoload :PodTargetInstaller, 'cocoapods/installer/target_installer/pod_target_installer'
autoload :UserProjectIntegrator, 'cocoapods/installer/user_project_integrator' autoload :UserProjectIntegrator, 'cocoapods/installer/user_project_integrator'
include Config::Mixin include Config::Mixin
...@@ -86,6 +83,7 @@ module Pod ...@@ -86,6 +83,7 @@ module Pod
resolve_dependencies resolve_dependencies
download_dependencies download_dependencies
generate_pods_project generate_pods_project
write_lockfiles
integrate_user_project if config.integrate_targets? integrate_user_project if config.integrate_targets?
end end
...@@ -108,14 +106,12 @@ module Pod ...@@ -108,14 +106,12 @@ module Pod
def generate_pods_project def generate_pods_project
UI.section "Generating Pods project" do UI.section "Generating Pods project" do
prepare_pods_project installer = PodsProjectGenerator.new(sandbox, aggregate_targets)
install_file_references installer.user_build_configurations = analysis_result.all_user_build_configurations
install_libraries installer.podfile_path = config.podfile_path
set_target_dependencies installer.install
link_aggregate_target
run_post_install_hooks run_post_install_hooks
write_pod_project installer.write_pod_project
write_lockfiles
end end
end end
...@@ -130,11 +126,8 @@ module Pod ...@@ -130,11 +126,8 @@ module Pod
# #
attr_reader :analysis_result attr_reader :analysis_result
# @return [Pod::Project] the `Pods/Pods.xcodeproj` project.
#
attr_reader :pods_project
# @return [Array<String>] The Pods that should be installed. # @return [Array<String>] The Pods that should be installed.
# TODO
# #
attr_reader :names_of_pods_to_install attr_reader :names_of_pods_to_install
...@@ -147,6 +140,10 @@ module Pod ...@@ -147,6 +140,10 @@ module Pod
# #
attr_accessor :installed_specs attr_accessor :installed_specs
def pods_project
sandbox.project
end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
private private
...@@ -277,132 +274,7 @@ module Pod ...@@ -277,132 +274,7 @@ module Pod
end end
end end
# Creates the Pods project from scratch if it doesn't exists.
#
# @return [void]
#
# @todo Clean and modify the project if it exists.
#
def prepare_pods_project
UI.message "- Creating Pods project" do
@pods_project = Pod::Project.new(sandbox.project_path)
analysis_result.all_user_build_configurations.each do |name, type|
@pods_project.add_build_configuration(name, type)
end
pod_names = pod_targets.map(&:pod_name).uniq
pod_names.each do |pod_name|
path = sandbox.pod_dir(pod_name)
local = sandbox.local?(pod_name)
@pods_project.add_pod_group(pod_name, path, local)
end
if config.podfile_path
@pods_project.add_podfile(config.podfile_path)
end
sandbox.project = @pods_project
platforms = aggregate_targets.map(&:platform)
osx_deployment_target = platforms.select { |p| p.name == :osx }.map(&:deployment_target).min
ios_deployment_target = platforms.select { |p| p.name == :ios }.map(&:deployment_target).min
@pods_project.build_configurations.each do |build_configuration|
build_configuration.build_settings['MACOSX_DEPLOYMENT_TARGET'] = osx_deployment_target.to_s if osx_deployment_target
build_configuration.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ios_deployment_target.to_s if ios_deployment_target
build_configuration.build_settings['STRIP_INSTALLED_PRODUCT'] = 'NO'
end
end
end
# Installs the file references in the Pods project. This is done once per
# Pod as the same file reference might be shared by multiple aggregate
# targets.
#
# @return [void]
#
def install_file_references
installer = FileReferencesInstaller.new(sandbox, pod_targets, pods_project)
installer.install!
end
# Installs the aggregate targets of the Pods projects and generates their
# support files.
#
# @return [void]
#
def install_libraries
UI.message"- Installing libraries" do
pod_targets.sort_by(&:name).each do |pod_target|
next if pod_target.target_definition.empty?
target_installer = PodTargetInstaller.new(sandbox, pod_target)
target_installer.install!
end
aggregate_targets.sort_by(&:name).each do |target|
next if target.target_definition.empty?
target_installer = AggregateTargetInstaller.new(sandbox, target)
target_installer.install!
end
# TODO
# Move and add specs
pod_targets.sort_by(&:name).each do |pod_target|
pod_target.file_accessors.each do |file_accessor|
file_accessor.spec_consumer.frameworks.each do |framework|
ref = pods_project.add_system_framework(framework, pod_target.target)
end
end
end
end
end
def set_target_dependencies
aggregate_targets.each do |aggregate_target|
aggregate_target.pod_targets.each do |pod_target|
aggregate_target.target.add_dependency(pod_target.target)
pod_target.dependencies.each do |dep|
unless dep == pod_target.pod_name
pod_dependency_target = aggregate_target.pod_targets.find { |target| target.pod_name == dep }
# TODO remove me
unless pod_dependency_target
puts "[BUG] DEP: #{dep}"
end
pod_target.target.add_dependency(pod_dependency_target.target)
end
end
end
end
end
# Links the aggregate targets with all the dependent libraries.
#
# @note This is run in the integration step to ensure that targets
# have been created for all per spec libraries.
#
def link_aggregate_target
aggregate_targets.each do |aggregate_target|
native_target = aggregate_target.target
aggregate_target.pod_targets.each do |pod_target|
product = pod_target.target.product_reference
native_target.frameworks_build_phase.add_file_reference(product)
end
end
end
# Writes the Pods project to the disk.
#
# @return [void]
#
def write_pod_project
UI.message "- Writing Xcode project file to #{UI.path sandbox.project_path}" do
pods_project.pods.remove_from_project if pods_project.pods.empty?
pods_project.development_pods.remove_from_project if pods_project.development_pods.empty?
pods_project.main_group.recursively_sort_by_type
pods_project.save
end
end
# Writes the Podfile and the lock files. # Writes the Podfile and the lock files.
# #
......
module Pod
class Installer
# Generates the Pods project according to the targets identified by the
# analyzer.
#
class PodsProjectGenerator
autoload :FileReferencesInstaller, 'cocoapods/installer/pods_project_generator/file_references_installer'
autoload :TargetInstaller, 'cocoapods/installer/pods_project_generator/target_installer'
autoload :AggregateTargetInstaller, 'cocoapods/installer/pods_project_generator/target_installer/aggregate_target_installer'
autoload :PodTargetInstaller, 'cocoapods/installer/pods_project_generator/target_installer/pod_target_installer'
# @return [Sandbox] The sandbox of the installation.
#
attr_reader :sandbox
# @return [Array<AggregateTarget>] The aggregate targets of the
# installation.
#
attr_reader :aggregate_targets
# @param [Sandbox] sandbox @see sandbox
# @param [Array<AggregateTarget>] aggregate_targets @see aggregate_targets
#
def initialize(sandbox, aggregate_targets)
@sandbox = sandbox
@aggregate_targets = aggregate_targets
@user_build_configurations = []
end
# @return [Pathname] The path of the Podfile.
#
attr_accessor :podfile_path
# @return [Hash] The name and the type of the build configurations of the
# user.
#
attr_accessor :user_build_configurations
# Generates the Pods project.
#
# @return [void]
#
def install
prepare_project
install_file_references
install_targets
install_system_frameworks
set_target_dependencies
link_aggregate_target
end
# @return [Project] the generated Pods project.
#
attr_reader :project
# Writes the Pods project to the disk.
#
# @return [void]
#
def write_pod_project
UI.message "- Writing Xcode project file to #{UI.path sandbox.project_path}" do
clean_up_project
project.save
end
end
private
# @!group Installation steps
#-----------------------------------------------------------------------#
# Creates the Pods project from scratch.
#
# @return [void]
#
def prepare_project
UI.message "- Creating Pods project" do
@project = Pod::Project.new(sandbox.project_path)
user_build_configurations.each do |name, type|
project.add_build_configuration(name, type)
end
pod_names = pod_targets.map(&:pod_name).uniq
pod_names.each do |pod_name|
path = sandbox.pod_dir(pod_name)
local = sandbox.local?(pod_name)
project.add_pod_group(pod_name, path, local)
end
if podfile_path
project.add_podfile(podfile_path)
end
sandbox.project = @project
platforms = aggregate_targets.map(&:platform)
osx_deployment_target = platforms.select { |p| p.name == :osx }.map(&:deployment_target).min
ios_deployment_target = platforms.select { |p| p.name == :ios }.map(&:deployment_target).min
project.build_configurations.each do |build_configuration|
build_configuration.build_settings['MACOSX_DEPLOYMENT_TARGET'] = osx_deployment_target.to_s if osx_deployment_target
build_configuration.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ios_deployment_target.to_s if ios_deployment_target
build_configuration.build_settings['STRIP_INSTALLED_PRODUCT'] = 'NO'
end
end
end
# Installs the file references in the Pods project. This is done once per
# Pod as the same file reference might be shared by multiple aggregate
# targets.
#
# @return [void]
#
def install_file_references
installer = FileReferencesInstaller.new(sandbox, pod_targets, project)
installer.install!
end
# Installs the pods and the aggregate targets generating their support
# files.
#
# @return [void]
#
def install_targets
UI.message"- Installing Targets" do
pod_targets.sort_by(&:name).each do |pod_target|
next if pod_target.target_definition.empty?
target_installer = PodTargetInstaller.new(sandbox, pod_target)
target_installer.install!
end
aggregate_targets.sort_by(&:name).each do |target|
next if target.target_definition.empty?
target_installer = AggregateTargetInstaller.new(sandbox, target)
target_installer.install!
end
end
end
# Generates file references to the system frameworks used by the targets.
# This is done for informative purposes and is not needed as the
# canonical source for the build settings are the xcconfig files.
#
# @return [void]
#
def install_system_frameworks
pod_targets.each do |pod_target|
pod_target.specs.each do |spec|
spec.consumer(pod_target.platform).frameworks.each do |framework|
project.add_system_framework(framework, pod_target.target)
end
end
end
end
# Sets the dependencies of the targets.
#
# @return [void]
#
def set_target_dependencies
aggregate_targets.each do |aggregate_target|
aggregate_target.pod_targets.each do |pod_target|
aggregate_target.target.add_dependency(pod_target.target)
pod_target.dependencies.each do |dep|
pod_dependency_target = aggregate_target.pod_targets.find { |target| target.pod_name == dep }
pod_target.target.add_dependency(pod_dependency_target.target)
end
end
end
end
# Links the aggregate targets with all the dependent pod targets.
#
# @return [void]
#
def link_aggregate_target
aggregate_targets.each do |aggregate_target|
native_target = aggregate_target.target
aggregate_target.pod_targets.each do |pod_target|
product = pod_target.target.product_reference
native_target.frameworks_build_phase.add_file_reference(product)
end
end
end
private
# @!group Write steps
#-----------------------------------------------------------------------#
# Cleans up the project to prepare it for serialization.
#
# @return [void]
#
def clean_up_project
project.pods.remove_from_project if project.pods.empty?
project.development_pods.remove_from_project if project.development_pods.empty?
project.main_group.recursively_sort_by_type
end
private
# @!group Private Helpers
#-----------------------------------------------------------------------#
# @return [Array<PodTarget>] The pod targets generated by the installation
# process.
#
def pod_targets
aggregate_targets.map(&:pod_targets).flatten
end
#-----------------------------------------------------------------------#
end
end
end
module Pod module Pod
class Installer class Installer
class PodsProjectGenerator
# Controller class responsible of installing the file references of the # Controller class responsible of installing the file references of the
# specifications in the Pods project. # specifications in the Pods project.
...@@ -206,3 +207,4 @@ module Pod ...@@ -206,3 +207,4 @@ module Pod
end end
end end
end end
end
module Pod module Pod
class Installer class Installer
class PodsProjectGenerator
# Controller class responsible of creating and configuring the static # Controller class responsible of creating and configuring the static
# library target in Pods project. It also creates the support file needed # library target in Pods project. It also creates the support file needed
...@@ -128,4 +129,5 @@ module Pod ...@@ -128,4 +129,5 @@ module Pod
end end
end end
end end
end
module Pod module Pod
class Installer class Installer
class PodsProjectGenerator
# Creates the targets which aggregate the Pods libraries in the Pods # Creates the targets which aggregate the Pods libraries in the Pods
# project and the relative support files. # project and the relative support files.
...@@ -131,3 +132,4 @@ module Pod ...@@ -131,3 +132,4 @@ module Pod
end end
end end
end end
end
module Pod module Pod
class Installer class Installer
class PodsProjectGenerator
# Creates the target for the Pods libraries in the Pods project and the # Creates the target for the Pods libraries in the Pods project and the
# relative support files. # relative support files.
...@@ -205,3 +206,4 @@ module Pod ...@@ -205,3 +206,4 @@ module Pod
end end
end end
end end
end
...@@ -61,7 +61,7 @@ module Pod ...@@ -61,7 +61,7 @@ module Pod
def dependencies def dependencies
specs.map do |spec| specs.map do |spec|
spec.consumer(platform).dependencies.map { |dep| Specification.root_name(dep.name) } spec.consumer(platform).dependencies.map { |dep| Specification.root_name(dep.name) }
end.flatten end.flatten.reject { |dep| dep == pod_name }
end end
end end
......
require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../../spec_helper', __FILE__)
module Pod module Pod
describe Installer::FileReferencesInstaller do describe Installer::PodsProjectGenerator::FileReferencesInstaller do
before do before do
@file_accessor = fixture_file_accessor('banana-lib/BananaLib.podspec') @file_accessor = fixture_file_accessor('banana-lib/BananaLib.podspec')
...@@ -9,7 +9,7 @@ module Pod ...@@ -9,7 +9,7 @@ module Pod
@pod_target.file_accessors = [@file_accessor] @pod_target.file_accessors = [@file_accessor]
@project = Project.new(config.sandbox.project_path) @project = Project.new(config.sandbox.project_path)
@project.add_pod_group('BananaLib', fixture('banana-lib')) @project.add_pod_group('BananaLib', fixture('banana-lib'))
@installer = Installer::FileReferencesInstaller.new(config.sandbox, [@pod_target], @project) @installer = Installer::PodsProjectGenerator::FileReferencesInstaller.new(config.sandbox, [@pod_target], @project)
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -74,7 +74,7 @@ module Pod ...@@ -74,7 +74,7 @@ module Pod
pod_target_1.file_accessors = [fixture_file_accessor('banana-lib/BananaLib.podspec')] pod_target_1.file_accessors = [fixture_file_accessor('banana-lib/BananaLib.podspec')]
pod_target_2 = PodTarget.new([], nil, config.sandbox) pod_target_2 = PodTarget.new([], nil, config.sandbox)
pod_target_2.file_accessors = [fixture_file_accessor('banana-lib/BananaLib.podspec')] pod_target_2.file_accessors = [fixture_file_accessor('banana-lib/BananaLib.podspec')]
installer = Installer::FileReferencesInstaller.new(config.sandbox, [pod_target_1, pod_target_2], @project) installer = Installer::PodsProjectGenerator::FileReferencesInstaller.new(config.sandbox, [pod_target_1, pod_target_2], @project)
roots = installer.send(:file_accessors).map { |fa| fa.path_list.root } roots = installer.send(:file_accessors).map { |fa| fa.path_list.root }
roots.should == [fixture('banana-lib'), fixture('banana-lib')] roots.should == [fixture('banana-lib'), fixture('banana-lib')]
end end
...@@ -82,7 +82,7 @@ module Pod ...@@ -82,7 +82,7 @@ module Pod
it "handles libraries empty libraries without file accessors" do it "handles libraries empty libraries without file accessors" do
pod_target_1 = PodTarget.new([], nil, config.sandbox) pod_target_1 = PodTarget.new([], nil, config.sandbox)
pod_target_1.file_accessors = [] pod_target_1.file_accessors = []
installer = Installer::FileReferencesInstaller.new(config.sandbox, [pod_target_1], @project) installer = Installer::PodsProjectGenerator::FileReferencesInstaller.new(config.sandbox, [pod_target_1], @project)
roots = installer.send(:file_accessors).should == [] roots = installer.send(:file_accessors).should == []
end end
end end
......
require File.expand_path('../../../../spec_helper', __FILE__) require File.expand_path('../../../../../spec_helper', __FILE__)
module Pod module Pod
describe Installer::AggregateTargetInstaller do describe Installer::PodsProjectGenerator::AggregateTargetInstaller do
describe "In General" do describe "In General" do
before do before do
@podfile = Podfile.new do @podfile = Podfile.new do
...@@ -34,7 +34,7 @@ module Pod ...@@ -34,7 +34,7 @@ module Pod
@target.pod_targets = [@pod_target] @target.pod_targets = [@pod_target]
@installer = Installer::AggregateTargetInstaller.new(config.sandbox, @target) @installer = Installer::PodsProjectGenerator::AggregateTargetInstaller.new(config.sandbox, @target)
@spec.prefix_header_contents = '#import "BlocksKit.h"' @spec.prefix_header_contents = '#import "BlocksKit.h"'
end end
......
require File.expand_path('../../../../spec_helper', __FILE__) require File.expand_path('../../../../../spec_helper', __FILE__)
module Pod module Pod
describe Installer::PodTargetInstaller do describe Installer::PodsProjectGenerator::PodTargetInstaller do
describe "In General" do describe "In General" do
before do before do
@podfile = Podfile.new do @podfile = Podfile.new do
...@@ -25,7 +25,7 @@ module Pod ...@@ -25,7 +25,7 @@ module Pod
@pod_target.stubs(:platform).returns(Platform.new(:ios, '6.0')) @pod_target.stubs(:platform).returns(Platform.new(:ios, '6.0'))
@pod_target.file_accessors = [file_accessor] @pod_target.file_accessors = [file_accessor]
@pod_target.user_build_configurations = { 'Debug' => :debug, 'Release' => :release } @pod_target.user_build_configurations = { 'Debug' => :debug, 'Release' => :release }
@installer = Installer::PodTargetInstaller.new(config.sandbox, @pod_target) @installer = Installer::PodsProjectGenerator::PodTargetInstaller.new(config.sandbox, @pod_target)
@spec.prefix_header_contents = '#import "BlocksKit.h"' @spec.prefix_header_contents = '#import "BlocksKit.h"'
end end
......
require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../../spec_helper', __FILE__)
module Pod module Pod
describe Installer::TargetInstaller do describe Installer::PodsProjectGenerator::TargetInstaller do
before do before do
@podfile = Podfile.new do @podfile = Podfile.new do
...@@ -26,7 +26,7 @@ module Pod ...@@ -26,7 +26,7 @@ module Pod
@pod_target.user_build_configurations = { 'Debug' => :debug, 'Release' => :release, 'AppStore' => :release, 'Test' => :debug } @pod_target.user_build_configurations = { 'Debug' => :debug, 'Release' => :release, 'AppStore' => :release, 'Test' => :debug }
@pod_target.file_accessors = [file_accessor] @pod_target.file_accessors = [file_accessor]
@installer = Installer::TargetInstaller.new(config.sandbox, @pod_target) @installer = Installer::PodsProjectGenerator::TargetInstaller.new(config.sandbox, @pod_target)
end end
it "sets the ARCHS" do it "sets the ARCHS" do
......
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
class Installer
describe PodsProjectGenerator do
#-----------------------------------------------------------------------#
describe "In general" do
before do
@sut = PodsProjectGenerator.new(config.sandbox, [])
end
it "performs an installation" do
@sut.send(:install)
@sut.project.should.not.be.nil
end
it "can write the pods project" do
@sut.send(:install)
@sut.project.expects(:save)
@sut.send(:write_pod_project)
end
end
#-----------------------------------------------------------------------#
describe "#prepare_project" do
before do
@sut = PodsProjectGenerator.new(config.sandbox, [])
@sut.user_build_configurations = { 'App Store' => :release, 'Test' => :debug }
end
it "creates the Pods project" do
@sut.send(:prepare_project)
@sut.project.class.should == Pod::Project
end
it "creates a group for each Pod" do
pod_target = PodTarget.new([], nil, config.sandbox)
pod_target.stubs(:pod_name).returns('BananaLib')
@sut.stubs(:pod_targets).returns([pod_target])
@sut.send(:prepare_project)
@sut.project['Pods/BananaLib'].should.not.be.nil
end
it "creates a group for each development Pod" do
pod_target = PodTarget.new([], nil, config.sandbox)
pod_target.stubs(:pod_name).returns('BananaLib')
@sut.stubs(:pod_targets).returns([pod_target])
config.sandbox.expects(:pod_dir).with('BananaLib').returns('/BananaLib')
config.sandbox.expects(:local?).with('BananaLib').returns(true)
@sut.send(:prepare_project)
@sut.project['Development Pods/BananaLib'].should.not.be.nil
end
it "adds the Podfile to the project" do
@sut.podfile_path = Pathname.new('/Podfile')
@sut.send(:prepare_project)
@sut.project['Podfile'].should.be.not.nil
end
it "adds the user build configurations to the project" do
@sut.send(:prepare_project)
@sut.project.build_configurations.map(&:name).sort.should == ['App Store', 'Debug', 'Release', 'Test']
end
it "sets STRIP_INSTALLED_PRODUCT to NO for all configurations of the project" do
@sut.send(:prepare_project)
@sut.project.build_configurations.each do |build_configuration|
build_configuration.build_settings["STRIP_INSTALLED_PRODUCT"].should == "NO"
end
end
it "sets the deployment target for the project" do
target_ios = AggregateTarget.new(nil, config.sandbox)
target_osx = AggregateTarget.new(nil, config.sandbox)
target_ios.stubs(:platform).returns(Platform.new(:ios, '6.0'))
target_osx.stubs(:platform).returns(Platform.new(:osx, '10.8'))
@sut.stubs(:aggregate_targets).returns([target_ios, target_osx])
@sut.send(:prepare_project)
build_settings = @sut.project.build_configurations.map(&:build_settings)
build_settings.each do |build_setting|
build_setting["MACOSX_DEPLOYMENT_TARGET"].should == '10.8'
build_setting["IPHONEOS_DEPLOYMENT_TARGET"].should == '6.0'
end
end
end
#-----------------------------------------------------------------------#
describe "#install_file_references" do
before do
@sut = PodsProjectGenerator.new(config.sandbox, [])
end
it "installs the file references" do
Installer::PodsProjectGenerator::FileReferencesInstaller.any_instance.expects(:install!)
@sut.send(:install_file_references)
end
end
#-----------------------------------------------------------------------#
describe "#install_targets" do
before do
@target_definition = Podfile::TargetDefinition.new(:default, nil)
pod_target = PodTarget.new([], @target_definition, config.sandbox)
pod_target.stubs(:name).returns('BananaLib')
aggregate_target = AggregateTarget.new(@target_definition, config.sandbox)
aggregate_target.pod_targets = [pod_target]
@sut = PodsProjectGenerator.new(config.sandbox, [aggregate_target])
end
it "install the aggregate targets" do
@target_definition.store_pod('BananaLib')
Installer::PodsProjectGenerator::PodTargetInstaller.any_instance.stubs(:install!)
Installer::PodsProjectGenerator::AggregateTargetInstaller.any_instance.expects(:install!)
@sut.send(:install_targets)
end
it "install the Pod targets" do
@target_definition.store_pod('BananaLib')
Installer::PodsProjectGenerator::AggregateTargetInstaller.any_instance.stubs(:install!)
Installer::PodsProjectGenerator::PodTargetInstaller.any_instance.expects(:install!)
@sut.send(:install_targets)
end
it "skips empty targets" do
Installer::PodsProjectGenerator::PodTargetInstaller.any_instance.expects(:install!).never
Installer::PodsProjectGenerator::PodTargetInstaller.any_instance.expects(:install!).never
@sut.send(:install_targets)
end
end
#-----------------------------------------------------------------------#
describe "#install_system_frameworks" do
before do
spec = Spec.new
spec.frameworks = ['QuartzCore']
pod_target = PodTarget.new([spec], nil, config.sandbox)
pod_target.stubs(:pod_name).returns('BananaLib')
pod_target.stubs(:platform).returns(:ios)
@pod_native_target = stub()
pod_target.target = @pod_native_target
@sut = PodsProjectGenerator.new(config.sandbox, [])
@sut.stubs(:pod_targets).returns([pod_target])
@sut.send(:prepare_project)
end
it 'adds the frameworks required by to the pod to the project for informative purposes' do
Project.any_instance.expects(:add_system_framework).with('QuartzCore', @pod_native_target)
@sut.send(:install_system_frameworks)
end
end
#-----------------------------------------------------------------------#
describe "#set_target_dependencies" do
before do
project = Pod::Project.new(config.sandbox.project_path)
aggregate_native_target = project.new_target(:static_library, 'Pods', :ios)
pod_native_target_1 = project.new_target(:static_library, 'Pods-BananaLib', :ios)
@pod_target_1 = PodTarget.new([], nil, config.sandbox)
@pod_target_1.stubs(:pod_name).returns('BananaLib')
@pod_target_1.target = pod_native_target_1
pod_native_target_2 = project.new_target(:static_library, 'Pods-monkey', :ios)
pod_target_2 = PodTarget.new([], nil, config.sandbox)
pod_target_2.stubs(:pod_name).returns('monkey')
pod_target_2.target = pod_native_target_2
@aggregate_target = AggregateTarget.new(nil, config.sandbox)
@aggregate_target.pod_targets = [@pod_target_1, pod_target_2]
@aggregate_target.target = aggregate_native_target
@sut = PodsProjectGenerator.new(config.sandbox, [@aggregate_target])
end
it "sets the pod targets as dependencies of the aggregate target" do
@sut.send(:set_target_dependencies)
dependencies = @aggregate_target.target.dependencies
dependencies.map { |d| d.target.name}.should == ["Pods-BananaLib", "Pods-monkey"]
end
it "sets the dependencies of the pod targets" do
@pod_target_1.stubs(:dependencies).returns(['monkey'])
@sut.send(:set_target_dependencies)
dependencies = @pod_target_1.target.dependencies
dependencies.map { |d| d.target.name}.should == ["Pods-monkey"]
end
end
#-----------------------------------------------------------------------#
describe "#link_aggregate_target" do
before do
project = Pod::Project.new(config.sandbox.project_path)
@aggregate_native_target = project.new_target(:static_library, 'Pods', :ios)
@pod_native_target = project.new_target(:static_library, 'Pods-BananaLib', :ios)
pod_target = PodTarget.new([], nil, config.sandbox)
pod_target.target = @pod_native_target
aggregate_target = AggregateTarget.new(nil, config.sandbox)
aggregate_target.pod_targets = [pod_target]
aggregate_target.target = @aggregate_native_target
@sut = PodsProjectGenerator.new(config.sandbox, [aggregate_target])
end
it "links the aggregate targets to the pod targets" do
@sut.send(:link_aggregate_target)
@aggregate_native_target.frameworks_build_phase.files.map(&:file_ref).should.include?(@pod_native_target.product_reference)
end
end
#-----------------------------------------------------------------------#
describe "#clean_up_project" do
before do
@sut = PodsProjectGenerator.new(config.sandbox, [])
@sut.install
end
it "removes the Pods group if empty" do
@sut.send(:write_pod_project)
@sut.project['Pods'].should.be.nil
end
it "removes the Development Pods group if empty" do
@sut.send(:write_pod_project)
@sut.project['Development Pods'].should.be.nil
end
it "recursively sorts the project by type" do
@sut.project.main_group.expects(:recursively_sort_by_type)
@sut.send(:write_pod_project)
end
end
#-----------------------------------------------------------------------#
end
end
end
...@@ -41,6 +41,7 @@ module Pod ...@@ -41,6 +41,7 @@ module Pod
@installer.stubs(:resolve_dependencies) @installer.stubs(:resolve_dependencies)
@installer.stubs(:download_dependencies) @installer.stubs(:download_dependencies)
@installer.stubs(:generate_pods_project) @installer.stubs(:generate_pods_project)
@installer.stubs(:write_lockfiles)
@installer.stubs(:integrate_user_project) @installer.stubs(:integrate_user_project)
end end
...@@ -57,24 +58,6 @@ module Pod ...@@ -57,24 +58,6 @@ module Pod
@installer.install! @installer.install!
end end
it "in runs the post-install hooks before serializing the Pods project" do
@installer.stubs(:prepare_pods_project)
@installer.stubs(:run_pre_install_hooks)
@installer.stubs(:install_file_references)
@installer.stubs(:install_libraries)
@installer.stubs(:link_aggregate_target)
@installer.stubs(:write_lockfiles)
@installer.stubs(:aggregate_targets).returns([])
@installer.unstub(:generate_pods_project)
def @installer.run_post_install_hooks
@hook_called = true
end
def @installer.write_pod_project
@hook_called.should.be.true
end
@installer.install!
end
it "integrates the user targets if the corresponding config is set" do it "integrates the user targets if the corresponding config is set" do
config.integrate_targets = true config.integrate_targets = true
@installer.expects(:integrate_user_project) @installer.expects(:integrate_user_project)
...@@ -91,7 +74,7 @@ module Pod ...@@ -91,7 +74,7 @@ module Pod
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
describe "Dependencies Resolution" do describe "#resolve_dependencies" do
describe "#analyze" do describe "#analyze" do
...@@ -155,7 +138,7 @@ module Pod ...@@ -155,7 +138,7 @@ module Pod
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
describe "Downloading dependencies" do describe "#download_dependencies" do
describe "#install_pod_sources" do describe "#install_pod_sources" do
...@@ -205,159 +188,37 @@ module Pod ...@@ -205,159 +188,37 @@ module Pod
end end
end end
#--------------------------------------#
end end
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
describe "Generating pods project" do describe "#generate_pods_project" do
describe "#prepare_pods_project" do
before do
@installer.stubs(:aggregate_targets).returns([])
end
it "creates build configurations for all of the user's targets" do
config.integrate_targets = true
@installer.send(:analyze)
@installer.send(:prepare_pods_project)
@installer.pods_project.build_configurations.map(&:name).sort.should == ['App Store', 'Debug', 'Release', 'Test']
end
it "sets STRIP_INSTALLED_PRODUCT to NO for all configurations for the whole project" do
config.integrate_targets = true
@installer.send(:analyze)
@installer.send(:prepare_pods_project)
@installer.pods_project.build_settings('Debug')["STRIP_INSTALLED_PRODUCT"].should == "NO"
@installer.pods_project.build_settings('Test')["STRIP_INSTALLED_PRODUCT"].should == "NO"
@installer.pods_project.build_settings('Release')["STRIP_INSTALLED_PRODUCT"].should == "NO"
@installer.pods_project.build_settings('App Store')["STRIP_INSTALLED_PRODUCT"].should == "NO"
end
before do before do
@installer.stubs(:analysis_result).returns(stub(:all_user_build_configurations => {})) analysis_result = Installer::Analyzer::AnalysisResult.new
end analysis_result.specifications = []
analysis_result.stubs(:all_user_build_configurations).returns({})
it "creates the Pods project" do @installer.stubs(:analysis_result).returns(analysis_result)
@installer.send(:prepare_pods_project)
@installer.pods_project.class.should == Pod::Project
end
it "adds the Podfile to the Pods project" do
config.stubs(:podfile_path).returns(Pathname.new('/Podfile'))
@installer.send(:prepare_pods_project)
@installer.pods_project['Podfile'].should.be.not.nil
end
it "sets the deployment target for the whole project" do
pod_target_ios = PodTarget.new([], nil, config.sandbox)
pod_target_osx = PodTarget.new([], nil, config.sandbox)
pod_target_ios.stubs(:platform).returns(Platform.new(:ios, '6.0'))
pod_target_osx.stubs(:platform).returns(Platform.new(:osx, '10.8'))
@installer.stubs(:aggregate_targets).returns([pod_target_ios, pod_target_osx])
@installer.stubs(:pod_targets).returns([])
@installer.send(:prepare_pods_project)
build_settings = @installer.pods_project.build_configurations.map(&:build_settings)
build_settings.each do |build_setting|
build_setting["MACOSX_DEPLOYMENT_TARGET"].should == '10.8'
build_setting["IPHONEOS_DEPLOYMENT_TARGET"].should == '6.0'
end
end
end
#--------------------------------------#
describe "#install_file_references" do
it "installs the file references" do
@installer.stubs(:pod_targets).returns([])
Installer::FileReferencesInstaller.any_instance.expects(:install!)
@installer.send(:install_file_references)
end
end
#--------------------------------------#
describe "#install_libraries" do
it "install the targets of the Pod project" do
spec = fixture_spec('banana-lib/BananaLib.podspec')
target_definition = Podfile::TargetDefinition.new(:default, nil)
target_definition.store_pod('BananaLib')
pod_target = PodTarget.new([spec], target_definition, config.sandbox)
@installer.stubs(:aggregate_targets).returns([])
@installer.stubs(:pod_targets).returns([pod_target])
Installer::PodTargetInstaller.any_instance.expects(:install!)
@installer.send(:install_libraries)
end
it "skips empty pod targets" do
spec = fixture_spec('banana-lib/BananaLib.podspec')
target_definition = Podfile::TargetDefinition.new(:default, nil)
pod_target = PodTarget.new([spec], target_definition, config.sandbox)
@installer.stubs(:aggregate_targets).returns([]) @installer.stubs(:aggregate_targets).returns([])
@installer.stubs(:pod_targets).returns([pod_target])
Installer::PodTargetInstaller.any_instance.expects(:install!).never
@installer.send(:install_libraries)
end
xit 'adds the frameworks required by to the pod to the project for informative purposes' do
Specification::Consumer.any_instance.stubs(:frameworks).returns(['QuartzCore'])
@installer.install!
names = @installer.sandbox.project['Frameworks'].children.map(&:name)
names.sort.should == ["Foundation.framework", "QuartzCore.framework"]
end
end
#--------------------------------------#
describe "#set_target_dependencies" do
xit "sets the pod targets as dependencies of the aggregate target" do
end
xit "sets the dependecies of the pod targets" do
end
xit "is robusts against subspecs" do
end
end end
#--------------------------------------# it "generates the Pods project" do
Installer::PodsProjectGenerator.any_instance.expects(:install)
describe "#write_pod_project" do Installer::PodsProjectGenerator.any_instance.expects(:write_pod_project)
@installer.send(:generate_pods_project)
before do
@installer.stubs(:aggregate_targets).returns([])
@installer.stubs(:analysis_result).returns(stub(:all_user_build_configurations => {}))
@installer.send(:prepare_pods_project)
end end
it "recursively sorts the project by type" do it "in runs the post-install hooks before serializing the Pods project" do
@installer.pods_project.main_group.expects(:recursively_sort_by_type) def @installer.run_post_install_hooks
@installer.send(:write_pod_project) Installer::PodsProjectGenerator.any_instance.expects(:write_pod_project)
end end
@installer.send(:generate_pods_project)
it "saves the project to the given path" do
path = temporary_directory + 'Pods/Pods.xcodeproj'
@installer.pods_project.expects(:save)
@installer.send(:write_pod_project)
end end
end end
#--------------------------------------# #-------------------------------------------------------------------------#
describe "#write_lockfiles" do describe "#write_lockfiles" do
...@@ -386,35 +247,9 @@ module Pod ...@@ -386,35 +247,9 @@ module Pod
end end
end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
describe "Integrating client projects" do describe "#integrate_user_project" do
it "links the pod targets with the aggregate integration library target" do
spec = fixture_spec('banana-lib/BananaLib.podspec')
target_definition = Podfile::TargetDefinition.new('Pods', nil)
target = AggregateTarget.new(target_definition, config.sandbox)
lib_definition = Podfile::TargetDefinition.new('BananaLib', nil)
lib_definition.store_pod('BananaLib')
pod_target = PodTarget.new([spec], lib_definition, config.sandbox)
target.pod_targets = [pod_target]
project = Xcodeproj::Project.new('path')
pods_target = project.new_target(:static_library, target.name, :ios)
target.target = pods_target
native_target = project.new_target(:static_library, pod_target.name, :ios)
pod_target.target = pods_target
@installer.stubs(:pods_project).returns(project)
@installer.stubs(:aggregate_targets).returns([target])
@installer.stubs(:pod_targets).returns([pod_target])
@installer.send(:link_aggregate_target)
pods_target.frameworks_build_phase.files.map(&:file_ref).should.include?(pod_target.target.product_reference)
end
it "integrates the client projects" do it "integrates the client projects" do
@installer.stubs(:aggregate_targets).returns([AggregateTarget.new(nil, config.sandbox)]) @installer.stubs(:aggregate_targets).returns([AggregateTarget.new(nil, config.sandbox)])
...@@ -449,7 +284,7 @@ module Pod ...@@ -449,7 +284,7 @@ module Pod
@installer.send(:run_pre_install_hooks) @installer.send(:run_pre_install_hooks)
end end
it "run_post_install_hooks" do it "runs the post install hooks" do
installer_rep = stub() installer_rep = stub()
target_installer_data = stub() target_installer_data = stub()
......
...@@ -37,6 +37,18 @@ module Pod ...@@ -37,6 +37,18 @@ module Pod
it "returns the name of the Pods on which this target depends" do it "returns the name of the Pods on which this target depends" do
@pod_target.dependencies.should == ["monkey"] @pod_target.dependencies.should == ["monkey"]
end end
it "returns the dependencies as root names" do
dependencies = [stub(:name => 'monkey/subspec')]
Specification::Consumer.any_instance.stubs(:dependencies).returns(dependencies)
@pod_target.dependencies.should == ["monkey"]
end
it "never includes itself in the dependencies" do
dependencies = [stub(:name => 'BananaLib/subspec')]
Specification::Consumer.any_instance.stubs(:dependencies).returns(dependencies)
@pod_target.dependencies.should == []
end
end end
describe "Support files" do describe "Support files" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment