Commit 6985dec3 authored by Fabio Pelosin's avatar Fabio Pelosin

[PodsProjectGenerator] Group support files generation logic in SupportFilesGenerator

parent b8160f92
......@@ -9,6 +9,7 @@ module Pod
autoload :AggregateTargetInstaller, 'cocoapods/installer/pods_project_generator/target_installer/aggregate_target_installer'
autoload :FileReferencesInstaller, 'cocoapods/installer/pods_project_generator/file_references_installer'
autoload :PodTargetInstaller, 'cocoapods/installer/pods_project_generator/target_installer/pod_target_installer'
autoload :SupportFilesGenerator, 'cocoapods/installer/pods_project_generator/support_files_generator'
autoload :TargetInstaller, 'cocoapods/installer/pods_project_generator/target_installer'
# @return [Sandbox] The sandbox of the installation.
......@@ -138,12 +139,25 @@ module Pod
remove_aggregate_target(target)
end
aggregate_targets.each do |target|
# TODO: increment support files generation
# support_group = project.support_files_group[target.name]
# support_group.remove_from_project if support_group
unless target.target_definition.empty?
gen = SupportFilesGenerator.new(target, sandbox.project)
gen.generate!
end
end
# TODO: clean up dependencies and linking
# TODO: clean removed targets and their support files
# TODO: Fix sorting of targets
# TODO: clean stray and unrecognized targets
# TODO: skip empty aggregate targets
# TODO: Install aggregate targets first
# TODO: sort targets by name before serialization in the project
# TODO: Add integration checks (adding an aggregate target, removing
# one, performing an installation without a project)
end
......@@ -183,6 +197,8 @@ module Pod
pod_targets.each do |pod_target|
UI.message"- Installing targets" do
PodTargetInstaller.new(sandbox, pod_target).install!
gen = SupportFilesGenerator.new(pod_target, sandbox.project)
gen.generate!
end
end
end
......@@ -288,14 +304,10 @@ module Pod
#
def pods_to_install
if new_project
puts "$$$ Installing all Pods"
all_pod_targets.map(&:pod_name).uniq.sort
else
# TODO: Add missing groups
missing_target = all_pod_targets.select { |pod_target| pod_target.target.nil? }.map(&:pod_name).uniq
puts "$$$ missing target: #{missing_target}"
puts "$$$ sandbox.state.added: #{sandbox.state.added}"
puts "$$$ sandbox.state.changed: #{sandbox.state.changed}"
@pods_to_install ||= (sandbox.state.added | sandbox.state.changed | missing_target).uniq.sort
end
end
......@@ -309,13 +321,13 @@ module Pod
end
def targets_to_install
aggregate_targets.select do |aggregate_target|
aggregate_targets.sort_by(&:name).select do |target|
empty = target.target_definition.empty?
if new_project
true
!empty
else
missing = aggregate_target.target.nil?
empty = aggregate_target.target_definition.empty?
missing || empty
missing = target.target.nil?
missing && !empty
end
end
end
......
module Pod
class Installer
class PodsProjectGenerator
# Generates the support files for the given target
#
class SupportFilesGenerator
# TODO: move generators in name-space
# TODO: remove unused file references to the support group
# @return [Target] The target whose support files need to be generated.
#
attr_reader :target
attr_reader :project
def initialize(target, project)
@target = target
@project = project
end
def generate!
validate
# TODO clean up
if target.is_a?(AggregateTarget)
create_xcconfig_file_aggregate
create_target_environment_header
create_bridge_support_file
create_copy_resources_script
create_acknowledgements
else
create_xcconfig_file_pods
create_prefix_header
end
create_dummy_source
end
private
# @!group Generation Steps
#---------------------------------------------------------------------#
def validate
unless target.target
raise "[SupportFilesGenerator] Missing native target for `#{target}`"
end
end
# Generates the contents of the xcconfig file and saves it to disk.
#
# @return [void]
#
def create_xcconfig_file_aggregate
UI.message "- Generating xcconfig file" do
path = target.xcconfig_path
gen = Generator::XCConfig::AggregateXCConfig.new(target)
gen.save_as(path)
target.xcconfig = gen.xcconfig
xcconfig_file_ref = add_file_to_support_group(path)
target.target.build_configurations.each do |c|
c.base_configuration_reference = xcconfig_file_ref
end
end
end
# Generates the contents of the xcconfig file and saves it to disk.
#
# @return [void]
#
def create_xcconfig_file_pods
public_gen = Generator::XCConfig::PublicPodXCConfig.new(target)
UI.message "- Generating public xcconfig file" do
path = target.xcconfig_path
public_gen.save_as(path)
add_file_to_support_group(path)
end
UI.message "- Generating private xcconfig file" do
path = target.xcconfig_private_path
private_gen = Generator::XCConfig::PrivatePodXCConfig.new(target, public_gen.xcconfig)
private_gen.save_as(path)
xcconfig_file_ref = add_file_to_support_group(path)
target.target.build_configurations.each do |c|
c.base_configuration_reference = xcconfig_file_ref
end
end
end
# Generates a header which allows to inspect at compile time the installed
# pods and the installed specifications of a pod.
#
def create_target_environment_header
UI.message "- Generating target environment header" do
path = target.target_environment_header_path
generator = Generator::TargetEnvironmentHeader.new(target.pod_targets.map { |l| l.specs }.flatten)
generator.save_as(path)
add_file_to_support_group(path)
end
end
# Generates the bridge support metadata if requested by the {Podfile}.
#
# @note The bridge support metadata is added to the resources of the
# target because it is needed for environments interpreted at
# runtime.
#
# @return [void]
#
def create_bridge_support_file
if target.target_definition.podfile.generate_bridge_support?
UI.message "- Generating BridgeSupport metadata" do
path = target.bridge_support_path
headers = target.target.headers_build_phase.files.map { |bf| bf.file_ref.real_path }
generator = Generator::BridgeSupport.new(headers)
generator.save_as(path)
add_file_to_support_group(path)
@bridge_support_file = path
end
end
end
# Generates the acknowledgement files (markdown and plist) for the target.
#
# @return [void]
#
def create_acknowledgements
Generator::Acknowledgements.generators.each do |generator_class|
UI.message "- Generating acknowledgements" do
basepath = target.acknowledgements_basepath
path = generator_class.path_from_basepath(basepath)
file_accessors = target.pod_targets.map(&:file_accessors).flatten
generator = generator_class.new(file_accessors)
generator.save_as(path)
add_file_to_support_group(path)
end
end
end
# Creates a script that copies the resources to the bundle of the client
# target.
#
# @note The bridge support file needs to be created before the prefix
# header, otherwise it will not be added to the resources script.
#
# @return [void]
#
def create_copy_resources_script
UI.message "- Generating copy resources script" do
path = target.copy_resources_script_path
file_accessors = target.pod_targets.map(&:file_accessors).flatten
resource_paths = file_accessors.map { |accessor| accessor.resources.flatten.map { |res| res.relative_path_from(path.dirname) }}.flatten
resource_bundles = file_accessors.map { |accessor| accessor.resource_bundles.keys.map {|name| "${BUILT_PRODUCTS_DIR}/#{name}.bundle" } }.flatten
resources = []
resources.concat(resource_paths)
resources.concat(resource_bundles)
resources << bridge_support_file.relative_path_from(project.path.dirname) if bridge_support_file
generator = Generator::CopyResourcesScript.new(resources, target.platform)
generator.save_as(path)
add_file_to_support_group(path)
end
end
# Creates a prefix header file which imports `UIKit` or `Cocoa` according
# to the platform of the target. This file also include any prefix header
# content reported by the specification of the pods.
#
# @return [void]
#
def create_prefix_header
UI.message "- Generating prefix header" do
path = target.prefix_header_path
generator = Generator::PrefixHeader.new(target.file_accessors, target.platform)
generator.imports << target.target_environment_header_path.basename
generator.save_as(path)
add_file_to_support_group(path)
target.target.build_configurations.each do |c|
relative_path = path.relative_path_from(project.path.dirname)
c.build_settings['GCC_PREFIX_HEADER'] = relative_path.to_s
end
end
end
# Generates a dummy source file for each target so libraries that contain
# only categories build.
#
# @return [void]
#
def create_dummy_source
UI.message "- Generating dummy source file" do
path = target.dummy_source_path
generator = Generator::DummySource.new(target.label)
generator.save_as(path)
file_reference = add_file_to_support_group(path)
existing = target.target.source_build_phase.files_references.include?(file_reference)
unless existing
target.target.source_build_phase.add_file_reference(file_reference)
end
end
end
private
# @!group Private helpers.
#---------------------------------------------------------------------#
# @return [PBXGroup] the group where the file references to the support
# files should be stored.
#
def support_files_group
# TODO
unless @support_files_group
if target.is_a?(AggregateTarget)
#TODO move to Pods
@support_files_group = project.support_files_group[target.name] || project.support_files_group.new_group(target.name)
else
pod_name = target.pod_name
@support_files_group = project.group_for_spec(pod_name, :support_files)
end
end
@support_files_group
end
# Adds a reference to the given file in the support group of this
# target unless it already exists.
#
# @param [Pathname] path
# The path of the file to which the reference should be added.
#
# @return [PBXFileReference] the file reference of the added file.
#
def add_file_to_support_group(path)
existing = support_files_group.children.find { |reference| reference.real_path == path }
if existing
existing
else
support_files_group.new_file(path)
end
end
# @return [Pathname] the path of the bridge support file relative to the
# project.
#
# @return [Nil] if no bridge support file was generated.
#
attr_reader :bridge_support_file
#---------------------------------------------------------------------#
end
end
end
end
......@@ -59,35 +59,15 @@ module Pod
target.target = @native_target
end
# Creates the group that holds the references to the support files
# generated by this installer.
#
# @return [void]
#
def create_suport_files_group
@support_files_group = project.support_files_group.new_group(target.name)
end
# Generates a dummy source file for each target so libraries that contain
# only categories build.
#
# @return [void]
#
def create_dummy_source
UI.message "- Generating dummy source file" do
path = target.dummy_source_path
generator = Generator::DummySource.new(target.label)
generator.save_as(path)
file_reference = add_file_to_support_group(path)
target.target.source_build_phase.add_file_reference(file_reference)
end
end
# @return [PBXNativeTarget] the target generated by the installation
# process.
#
# @note Generated by the {#add_target} step.
#
# TODO Remove
#
attr_reader :native_target
......@@ -102,28 +82,6 @@ module Pod
sandbox.project
end
# @return [TargetDefinition] the target definition of the target.
#
def target_definition
target.target_definition
end
# @return [PBXGroup] the group where the file references to the support
# files should be stored.
#
attr_reader :support_files_group
# Adds a reference to the given file in the support group of this target.
#
# @param [Pathname] path
# The path of the file to which the reference should be added.
#
# @return [PBXFileReference] the file reference of the added file.
#
def add_file_to_support_group(path)
support_files_group.new_file(path)
end
#-----------------------------------------------------------------------#
end
......
......@@ -14,121 +14,8 @@ module Pod
def install!
UI.message "- Installing target `#{target.name}` #{target.platform}" do
add_target
create_suport_files_group
create_xcconfig_file
create_target_environment_header
create_bridge_support_file
create_copy_resources_script
create_acknowledgements
create_dummy_source
end
end
#-----------------------------------------------------------------------#
private
# Generates the contents of the xcconfig file and saves it to disk.
#
# @return [void]
#
def create_xcconfig_file
UI.message "- Generating xcconfig file" do
path = target.xcconfig_path
gen = Generator::XCConfig::AggregateXCConfig.new(target)
gen.save_as(path)
target.xcconfig = gen.xcconfig
xcconfig_file_ref = add_file_to_support_group(path)
target.target.build_configurations.each do |c|
c.base_configuration_reference = xcconfig_file_ref
end
end
end
# Generates a header which allows to inspect at compile time the installed
# pods and the installed specifications of a pod.
#
def create_target_environment_header
UI.message "- Generating target environment header" do
path = target.target_environment_header_path
generator = Generator::TargetEnvironmentHeader.new(target.pod_targets.map { |l| l.specs }.flatten)
generator.save_as(path)
add_file_to_support_group(path)
end
end
# Generates the bridge support metadata if requested by the {Podfile}.
#
# @note The bridge support metadata is added to the resources of the
# target because it is needed for environments interpreted at
# runtime.
#
# @return [void]
#
def create_bridge_support_file
if target_definition.podfile.generate_bridge_support?
UI.message "- Generating BridgeSupport metadata" do
path = target.bridge_support_path
headers = target.target.headers_build_phase.files.map { |bf| sandbox.root + bf.file_ref.path }
generator = Generator::BridgeSupport.new(headers)
generator.save_as(path)
add_file_to_support_group(path)
@bridge_support_file = path.relative_path_from(sandbox.root)
end
end
end
# Creates a script that copies the resources to the bundle of the client
# target.
#
# @note The bridge support file needs to be created before the prefix
# header, otherwise it will not be added to the resources script.
#
# @return [void]
#
def create_copy_resources_script
UI.message "- Generating copy resources script" do
path = target.copy_resources_script_path
file_accessors = target.pod_targets.map(&:file_accessors).flatten
resource_paths = file_accessors.map { |accessor| accessor.resources.flatten.map { |res| res.relative_path_from(project.path.dirname) }}.flatten
resource_bundles = file_accessors.map { |accessor| accessor.resource_bundles.keys.map {|name| "${BUILT_PRODUCTS_DIR}/#{name}.bundle" } }.flatten
resources = []
resources.concat(resource_paths)
resources.concat(resource_bundles)
resources << bridge_support_file if bridge_support_file
generator = Generator::CopyResourcesScript.new(resources, target.platform)
generator.save_as(path)
add_file_to_support_group(path)
end
end
# Generates the acknowledgement files (markdown and plist) for the target.
#
# @return [void]
#
def create_acknowledgements
Generator::Acknowledgements.generators.each do |generator_class|
UI.message "- Generating acknowledgements" do
basepath = target.acknowledgements_basepath
path = generator_class.path_from_basepath(basepath)
file_accessors = target.pod_targets.map(&:file_accessors).flatten
generator = generator_class.new(file_accessors)
generator.save_as(path)
add_file_to_support_group(path)
end
end
end
# @return [Pathname] the path of the bridge support file relative to the
# sandbox.
#
# @return [Nil] if no bridge support file was generated.
#
attr_reader :bridge_support_file
#-----------------------------------------------------------------------#
end
end
end
......
......@@ -17,10 +17,6 @@ module Pod
move_target_product_file_reference
add_files_to_build_phases
add_resources_bundle_targets
# create_suport_files_group
create_xcconfig_file
create_prefix_header
create_dummy_source
link_to_system_frameworks
end
end
......@@ -49,7 +45,10 @@ module Pod
end
end
# TODO
#
def move_target_product_file_reference
# TODO: add the target to the appropriate group from the start
pod_name = target.pod_name
group = project.group_for_spec(pod_name, :products)
target.target.product_reference.move(group)
......@@ -82,55 +81,6 @@ module Pod
end
end
# Generates the contents of the xcconfig file and saves it to disk.
#
# @return [void]
#
def create_xcconfig_file
public_gen = Generator::XCConfig::PublicPodXCConfig.new(target)
UI.message "- Generating public xcconfig file" do
path = target.xcconfig_path
public_gen.save_as(path)
#
# TODO
add_file_to_support_group(path)
# relative_path = path.relative_path_from(sandbox.root)
# group = project.group_for_spec(target.root_spec.name, :support_files)
# group.new_file(relative_path)
end
UI.message "- Generating private xcconfig file" do
path = target.xcconfig_private_path
private_gen = Generator::XCConfig::PrivatePodXCConfig.new(target, public_gen.xcconfig)
private_gen.save_as(path)
xcconfig_file_ref = add_file_to_support_group(path)
target.target.build_configurations.each do |c|
c.base_configuration_reference = xcconfig_file_ref
end
end
end
# Creates a prefix header file which imports `UIKit` or `Cocoa` according
# to the platform of the target. This file also include any prefix header
# content reported by the specification of the pods.
#
# @return [void]
#
def create_prefix_header
UI.message "- Generating prefix header" do
path = target.prefix_header_path
generator = Generator::PrefixHeader.new(target.file_accessors, target.platform)
generator.imports << target.target_environment_header_path.basename
generator.save_as(path)
add_file_to_support_group(path)
target.target.build_configurations.each do |c|
relative_path = path.relative_path_from(sandbox.root)
c.build_settings['GCC_PREFIX_HEADER'] = relative_path.to_s
end
end
end
# Add a file reference to the system frameworks if needed and links the
# target to them.
......@@ -150,6 +100,11 @@ module Pod
end
end
# TODO
#
ENABLE_OBJECT_USE_OBJC_FROM = {
:ios => Version.new('6'),
:osx => Version.new('10.8')
......@@ -200,25 +155,12 @@ module Pod
flags << '-DOS_OBJECT_USE_OBJC=0'
end
end
if target_definition.inhibits_warnings_for_pod?(consumer.spec.root.name)
if target.target_definition.inhibits_warnings_for_pod?(consumer.spec.root.name)
flags << '-w -Xanalyzer -analyzer-disable-checker'
end
flags * " "
end
# Adds a reference to the given file in the support group of this target.
#
# @param [Pathname] path
# The path of the file to which the reference should be added.
#
# @return [PBXFileReference] the file reference of the added file.
#
def add_file_to_support_group(path)
pod_name = target.pod_name
group = project.group_for_spec(pod_name, :support_files)
group.new_file(path)
end
#-----------------------------------------------------------------------#
end
......
require File.expand_path('../../../../spec_helper', __FILE__)
module Pod
describe Installer::PodsProjectGenerator::SupportFilesGenerator do
describe "AggregateTarget" do
before do
@project = Project.new(config.sandbox.project_path)
native_target = @project.new_target(:static_target, 'Pods', :ios, '6.0')
@podfile = Podfile.new do
platform :ios
xcodeproj 'dummy'
end
@target_definition = @podfile.target_definitions['Pods']
@target = AggregateTarget.new(@target_definition, config.sandbox)
@target.stubs(:label).returns('Pods')
@target.stubs(:platform).returns(Platform.new(:ios, '6.0'))
@target.user_project_path = config.sandbox.root + '../user_project.xcodeproj'
@target.client_root = config.sandbox.root.dirname
@target.user_build_configurations = { 'Debug' => :debug, 'Release' => :release, 'AppStore' => :release, 'Test' => :debug }
@target.target = native_target
file_accessor = fixture_file_accessor('banana-lib/BananaLib.podspec')
@spec = fixture_spec('banana-lib/BananaLib.podspec')
@pod_target = PodTarget.new([@spec], @target_definition, config.sandbox)
@pod_target.stubs(:platform).returns(Platform.new(:ios, '6.0'))
@pod_target.user_build_configurations = @target.user_build_configurations
@pod_target.file_accessors = [file_accessor]
@target.pod_targets = [@pod_target]
@sut = Installer::PodsProjectGenerator::SupportFilesGenerator.new(@target, @project)
end
it "adds file references for the support files of the target" do
@sut.generate!
group = @project.support_files_group['Pods']
group.children.map(&:display_name).sort.should == [
"Pods-acknowledgements.markdown",
"Pods-acknowledgements.plist",
"Pods-dummy.m",
"Pods-environment.h",
"Pods-resources.sh",
"Pods.xcconfig"
]
end
it "creates the xcconfig file" do
@sut.generate!
file = config.sandbox.root + @target.xcconfig_path
xcconfig = Xcodeproj::Config.new(file)
xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}/Pods'
end
it "creates a header for the target which contains the information about the installed Pods" do
@sut.generate!
file = config.sandbox.root + 'Pods-environment.h'
contents = file.read
contents.should.include?('#define COCOAPODS_POD_AVAILABLE_BananaLib')
contents.should.include?('#define COCOAPODS_VERSION_MAJOR_BananaLib 1')
contents.should.include?('#define COCOAPODS_VERSION_MINOR_BananaLib 0')
contents.should.include?('#define COCOAPODS_VERSION_PATCH_BananaLib 0')
end
it "creates a bridge support file" do
Podfile.any_instance.stubs(:generate_bridge_support? => true)
Generator::BridgeSupport.any_instance.expects(:save_as).once
@sut.generate!
end
it "creates a create copy resources script" do
@sut.generate!
script = config.sandbox.root + 'Pods-resources.sh'
script.read.should.include?('logo-sidebar.png')
end
xit "adds the resources bundles to the copy resources script" do
end
xit "adds the bridge support file to the copy resources script, if one was created" do
end
it "creates the acknowledgements files " do
@sut.generate!
markdown = config.sandbox.root + 'Pods-acknowledgements.markdown'
markdown.read.should.include?('Permission is hereby granted')
plist = config.sandbox.root + 'Pods-acknowledgements.plist'
plist.read.should.include?('Permission is hereby granted')
end
it "creates a dummy source to ensure the creation of a single base target" do
@sut.generate!
build_files = @sut.target.target.source_build_phase.files
build_file = build_files.find { |bf| bf.file_ref.path.include?('Pods-dummy.m') }
build_file.should.be.not.nil
build_file.file_ref.path.should == 'Pods-dummy.m'
dummy = config.sandbox.root + 'Pods-dummy.m'
dummy.read.should.include?('@interface PodsDummy_Pods')
end
end
#-------------------------------------------------------------------------#
describe "PodTarget" do
before do
@project = Project.new(config.sandbox.project_path)
@project.add_pod_group('BananaLib', fixture('banana-lib'))
native_target = @project.new_target(:static_target, 'Pods-BananaLib', :ios, '6.0')
@podfile = Podfile.new do
platform :ios
xcodeproj 'dummy'
end
@target_definition = @podfile.target_definitions['Pods']
file_accessor = fixture_file_accessor('banana-lib/BananaLib.podspec')
@spec = fixture_spec('banana-lib/BananaLib.podspec')
@target = PodTarget.new([@spec], @target_definition, config.sandbox)
@target.stubs(:platform).returns(Platform.new(:ios, '6.0'))
@target.user_build_configurations = @target.user_build_configurations
@target.file_accessors = [file_accessor]
@target.target = native_target
@sut = Installer::PodsProjectGenerator::SupportFilesGenerator.new(@target, @project)
end
it "creates the xcconfig file" do
@sut.generate!
file = config.sandbox.root + @target.xcconfig_private_path
xcconfig = Xcodeproj::Config.new(file)
xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}'
end
it "creates a prefix header, including the contents of the specification's prefix header" do
@sut.generate!
prefix_header = config.sandbox.root + 'Pods-BananaLib-prefix.pch'
generated = prefix_header.read
expected = <<-EOS.strip_heredoc
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import "Pods-environment.h"
#import <BananaTree/BananaTree.h>
EOS
generated.should == expected
end
it "creates a dummy source to ensure the compilation of libraries with only categories" do
@sut.generate!
build_files = @sut.target.target.source_build_phase.files
build_file = build_files.find { |bf| bf.file_ref.display_name == 'Pods-BananaLib-dummy.m' }
build_file.should.be.not.nil
build_file.file_ref.path.should == 'Pods-BananaLib-dummy.m'
dummy = config.sandbox.root + 'Pods-BananaLib-dummy.m'
dummy.read.should.include?('@interface PodsDummy_Pods')
end
end
#-------------------------------------------------------------------------#
end
end
......@@ -4,78 +4,40 @@ module Pod
describe Installer::PodsProjectGenerator::AggregateTargetInstaller do
describe "In General" do
before do
@podfile = Podfile.new do
platform :ios
xcodeproj 'dummy'
end
@target_definition = @podfile.target_definitions['Pods']
@project = Project.new(config.sandbox.project_path)
config.sandbox.project = @project
path_list = Sandbox::PathList.new(fixture('banana-lib'))
@spec = fixture_spec('banana-lib/BananaLib.podspec')
file_accessor = Sandbox::FileAccessor.new(path_list, @spec.consumer(:ios))
@project.add_pod_group('BananaLib', fixture('banana-lib'))
group = @project.group_for_spec('BananaLib', :source_files)
file_accessor.source_files.each do |file|
@project.add_file_reference(file, group)
end
config.sandbox.project = Project.new(config.sandbox.project_path)
@target = AggregateTarget.new(@target_definition, config.sandbox)
@target.stubs(:label).returns('Pods')
@target.stubs(:platform).returns(Platform.new(:ios, '6.0'))
@target.user_project_path = config.sandbox.root + '../user_project.xcodeproj'
@target.client_root = config.sandbox.root.dirname
@target.user_build_configurations = { 'Debug' => :debug, 'Release' => :release, 'AppStore' => :release, 'Test' => :debug }
@pod_target = PodTarget.new([@spec], @target_definition, config.sandbox)
@pod_target.stubs(:platform).returns(Platform.new(:ios, '6.0'))
@pod_target.user_build_configurations = @target.user_build_configurations
@pod_target.file_accessors = [file_accessor]
@target.pod_targets = [@pod_target]
@target.user_build_configurations = { 'AppStore' => :release, 'Test' => :debug }
@installer = Installer::PodsProjectGenerator::AggregateTargetInstaller.new(config.sandbox, @target)
@spec.prefix_header_contents = '#import "BlocksKit.h"'
@sut = Installer::PodsProjectGenerator::AggregateTargetInstaller.new(config.sandbox, @target)
end
it "adds file references for the support files of the target" do
@installer.install!
group = @project.support_files_group['Pods']
group.children.map(&:display_name).sort.should == [
"Pods-acknowledgements.markdown",
"Pods-acknowledgements.plist",
"Pods-dummy.m",
"Pods-environment.h",
"Pods-resources.sh",
"Pods.xcconfig"
]
end
#--------------------------------------#
#-----------------------------------------------------------------------#
it 'adds the target for the static target to the project' do
@installer.install!
@project.targets.count.should == 1
@project.targets.first.name.should == @target_definition.label
@sut.generate!
config.sandbox.project.targets.count.should == 1
config.sandbox.project.targets.first.name.should == 'Pods'
end
it "adds the user build configurations to the target" do
@installer.install!
target = @project.targets.first
@sut.generate!
target = config.sandbox.project.targets.first
target.build_settings('Test')["VALIDATE_PRODUCT"].should == nil
target.build_settings('AppStore')["VALIDATE_PRODUCT"].should == "YES"
end
it "sets VALIDATE_PRODUCT to YES for the Release configuration for iOS targets" do
@installer.install!
target = @project.targets.first
@sut.generate!
target = config.sandbox.project.targets.first
target.build_settings('Release')["VALIDATE_PRODUCT"].should == "YES"
end
it "sets the platform and the deployment target for iOS targets" do
@installer.install!
target = @project.targets.first
@sut.generate!
target = config.sandbox.project.targets.first
target.platform_name.should == :ios
target.deployment_target.should == "6.0"
target.build_settings('Debug')["IPHONEOS_DEPLOYMENT_TARGET"].should == "6.0"
......@@ -84,8 +46,8 @@ module Pod
it "sets the platform and the deployment target for OS X targets" do
@target.stubs(:platform).returns(Platform.new(:osx, '10.8'))
@installer.install!
target = @project.targets.first
@sut.generate!
target = config.sandbox.project.targets.first
target.platform_name.should == :osx
target.deployment_target.should == "10.8"
target.build_settings('Debug')["MACOSX_DEPLOYMENT_TARGET"].should == "10.8"
......@@ -93,79 +55,71 @@ module Pod
end
it "adds the user's build configurations to the target" do
@installer.install!
@project.targets.first.build_configurations.map(&:name).sort.should == %w{ AppStore Debug Release Test }
@sut.generate!
config.sandbox.project.targets.first.build_configurations.map(&:name).sort.should == %w{ AppStore Debug Release Test }
end
it "it creates different hash instances for the build settings of various build configurations" do
@installer.install!
build_settings = @project.targets.first.build_configurations.map(&:build_settings)
@sut.generate!
build_settings = config.sandbox.project.targets.first.build_configurations.map(&:build_settings)
build_settings.map(&:object_id).uniq.count.should == 4
end
it "does not enable the GCC_WARN_INHIBIT_ALL_WARNINGS flag by default" do
@installer.install!
@installer.target.target.build_configurations.each do |config|
@sut.generate!
@sut.target.target.build_configurations.each do |config|
config.build_settings['GCC_WARN_INHIBIT_ALL_WARNINGS'].should.be.nil
end
end
#--------------------------------------#
it "creates the xcconfig file" do
@installer.install!
file = config.sandbox.root + @target.xcconfig_path
xcconfig = Xcodeproj::Config.new(file)
xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}/Pods'
end
it "creates a header for the target which contains the information about the installed Pods" do
@installer.install!
file = config.sandbox.root + 'Pods-environment.h'
contents = file.read
contents.should.include?('#define COCOAPODS_POD_AVAILABLE_BananaLib')
contents.should.include?('#define COCOAPODS_VERSION_MAJOR_BananaLib 1')
contents.should.include?('#define COCOAPODS_VERSION_MINOR_BananaLib 0')
contents.should.include?('#define COCOAPODS_VERSION_PATCH_BananaLib 0')
end
it "creates a bridge support file" do
Podfile.any_instance.stubs(:generate_bridge_support? => true)
Generator::BridgeSupport.any_instance.expects(:save_as).once
@installer.install!
end
it "creates a create copy resources script" do
@installer.install!
script = config.sandbox.root + 'Pods-resources.sh'
script.read.should.include?('logo-sidebar.png')
end
xit "adds the resources bundles to the copy resources script" do
end
xit "adds the bridge support file to the copy resources script, if one was created" do
#-----------------------------------------------------------------------#
it "adds file references for the support files of the target" do
@sut.generate!
@project.support_files_group
group = @project['Pods/BananaLib/Support Files']
group.children.map(&:display_name).sort.should == [
"Pods-BananaLib-Private.xcconfig",
"Pods-BananaLib-dummy.m",
"Pods-BananaLib-prefix.pch",
"Pods-BananaLib.xcconfig",
]
end
it "creates the acknowledgements files " do
@installer.install!
markdown = config.sandbox.root + 'Pods-acknowledgements.markdown'
markdown.read.should.include?('Permission is hereby granted')
plist = config.sandbox.root + 'Pods-acknowledgements.plist'
plist.read.should.include?('Permission is hereby granted')
it "creates the xcconfig file" do
@sut.generate!
file = config.sandbox.root + @pod_target.xcconfig_private_path
xcconfig = Xcodeproj::Config.new(file)
xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}'
end
it "creates a dummy source to ensure the creation of a single base target" do
@installer.install!
build_files = @installer.target.target.source_build_phase.files
build_file = build_files.find { |bf| bf.file_ref.path.include?('Pods-dummy.m') }
it "creates a prefix header, including the contents of the specification's prefix header" do
@spec.prefix_header_contents = '#import "BlocksKit.h"'
@sut.generate!
prefix_header = config.sandbox.root + 'Pods-BananaLib-prefix.pch'
generated = prefix_header.read
expected = <<-EOS.strip_heredoc
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import "Pods-environment.h"
#import "BlocksKit.h"
#import <BananaTree/BananaTree.h>
EOS
generated.should == expected
end
it "creates a dummy source to ensure the compilation of libraries with only categories" do
@sut.generate!
build_files = @sut.target.target.source_build_phase.files
build_file = build_files.find { |bf| bf.file_ref.display_name == 'Pods-BananaLib-dummy.m' }
build_file.should.be.not.nil
build_file.file_ref.path.should == 'Pods-dummy.m'
dummy = config.sandbox.root + 'Pods-dummy.m'
build_file.file_ref.path.should == 'Pods-BananaLib-dummy.m'
dummy = config.sandbox.root + 'Pods-BananaLib-dummy.m'
dummy.read.should.include?('@interface PodsDummy_Pods')
end
end
end
end
......@@ -30,18 +30,6 @@ module Pod
@spec.prefix_header_contents = '#import "BlocksKit.h"'
end
it "adds file references for the support files of the target" do
@installer.install!
@project.support_files_group
group = @project['Pods/BananaLib/Support Files']
group.children.map(&:display_name).sort.should == [
"Pods-BananaLib-Private.xcconfig",
"Pods-BananaLib-dummy.m",
"Pods-BananaLib-prefix.pch",
"Pods-BananaLib.xcconfig",
]
end
#--------------------------------------#
it 'adds the target for the static target to the project' do
......@@ -112,40 +100,6 @@ module Pod
#--------------------------------------#
it "creates the xcconfig file" do
@installer.install!
file = config.sandbox.root + @pod_target.xcconfig_private_path
xcconfig = Xcodeproj::Config.new(file)
xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}'
end
it "creates a prefix header, including the contents of the specification's prefix header" do
@spec.prefix_header_contents = '#import "BlocksKit.h"'
@installer.install!
prefix_header = config.sandbox.root + 'Pods-BananaLib-prefix.pch'
generated = prefix_header.read
expected = <<-EOS.strip_heredoc
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import "Pods-environment.h"
#import "BlocksKit.h"
#import <BananaTree/BananaTree.h>
EOS
generated.should == expected
end
it "creates a dummy source to ensure the compilation of libraries with only categories" do
@installer.install!
build_files = @installer.target.target.source_build_phase.files
build_file = build_files.find { |bf| bf.file_ref.display_name == 'Pods-BananaLib-dummy.m' }
build_file.should.be.not.nil
build_file.file_ref.path.should == 'Pods-BananaLib-dummy.m'
dummy = config.sandbox.root + 'Pods-BananaLib-dummy.m'
dummy.read.should.include?('@interface PodsDummy_Pods')
end
xit 'links to system frameworks' do
end
......@@ -153,6 +107,7 @@ module Pod
#--------------------------------------------------------------------------------#
describe "concerning ARC before and after iOS 6.0 and OS X 10.8" do
before do
@spec = Pod::Spec.new
end
......
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