Commit 5a647fde authored by Fabio Pelosin's avatar Fabio Pelosin

[TargetInstaller] Adapt for architectural changes

parent 65dcd5e2
......@@ -7,40 +7,6 @@ module Pod
#
class TargetInstaller
# @param [Project] project @see project
# @param [Library] library @see library
#
def initialize(sandbox, library)
@sandbox = sandbox
@library = library
end
# Creates the target in the Pods project and the relative support files.
#
# @return [void]
#
def install!
add_target
add_pod_references
create_suport_files_group
create_xcconfig_file
create_target_header
create_prefix_header
create_bridge_support_file
create_copy_resources_script
create_acknowledgements
create_dummy_source
end
#-----------------------------------------------------------------------#
public
# @!group API
#
# This is the tentative API for the podfile and the specification hooks.
# @return [Sandbox] sandbox the sandbox where the support files should
# be generated.
#
......@@ -50,41 +16,32 @@ module Pod
#
attr_reader :library
# @return [PBXNativeTarget] the target generated by the installation
# process.
#
# @note Generated by the {#add_target} step.
#
attr_reader :target
# @return [Project] the Pods project of the sandbox.
#
def project
sandbox.project
end
# @return [Array<LocalPod>] the local pods of this target.
# @param [Project] project @see project
# @param [Library] library @see library
#
def pods
library.local_pods
def initialize(sandbox, library)
@sandbox = sandbox
@library = library
end
# @return [TargetDefinition] the target definition of the library.
# Creates the target in the Pods project and the relative support files.
#
def target_definition
library.target_definition
end
#--------------------------------------#
# @!group Hooks compatiblity
# @todo This has to be removed, but this means the specs have to be
# updated if they need a reference to the prefix header.
# @return [void]
#
def prefix_header_filename
UI.warn "The usage of the TargetInstaller#prefix_header_filename is deprecated."
library.prefix_header_path.relative_path_from(sandbox.root)
def install!
UI.message "- Installing target `#{library.name}` #{library.platform}" do
add_target
add_files_to_build_phases
create_suport_files_group
create_xcconfig_file
create_target_header
create_prefix_header
create_bridge_support_file
create_copy_resources_script
create_acknowledgements
create_dummy_source
end
end
#-----------------------------------------------------------------------#
......@@ -131,7 +88,7 @@ module Pod
end
end
library.target = @target
library.target = @target
end
# Adds the build files of the pods to the target and adds a refence to
......@@ -142,12 +99,21 @@ module Pod
#
# @return [void]
#
def add_pod_references
pods.each do |pod|
pod.add_build_files_to_target(target)
pod.frameworks.each do |framework|
framework_ref = project.add_system_framework(framework, target)
def add_files_to_build_phases
UI.message "- Adding Build files" do
library.file_accessors.each do |file_accessor|
UI.message "- #{file_accessor.spec}"
file_accessor.source_files.each do |source_file|
file_reference = project.file_reference(source_file, file_accessor.spec_consumer.spec.name)
consumer = file_accessor.spec_consumer
flags = consumer.compiler_flags.dup
flags << '-fobjc-arc' if consumer.requires_arc
flags = flags * " "
target.add_file_references([file_reference], flags)
end
file_accessor.spec_consumer.frameworks.each do |framework|
framework_ref = project.add_system_framework(framework, target)
end
end
end
end
......@@ -174,7 +140,7 @@ module Pod
def create_xcconfig_file
path = library.xcconfig_path
UI.message "- Generating xcconfig file at #{UI.path(path)}" do
gen = Generator::XCConfig.new(sandbox, pods, library.relative_pods_root)
gen = Generator::XCConfig.new(sandbox, spec_consumers, library.relative_pods_root)
gen.set_arc_compatibility_flag = target_definition.podfile.set_arc_compatibility_flag?
gen.save_as(path)
library.xcconfig = gen.xcconfig
......@@ -194,7 +160,7 @@ module Pod
#
def create_target_header
path = library.target_header_path
UI.message "- Creating target header at #{UI.path(path)}" do
UI.message "- Generating target header at #{UI.path(path)}" do
generator = Generator::TargetHeader.new(library.specs)
generator.save_as(path)
add_file_to_support_group(path)
......@@ -210,7 +176,7 @@ module Pod
def create_prefix_header
path = library.prefix_header_path
UI.message "- Generating prefix header at #{UI.path(path)}" do
generator = Generator::PrefixHeader.new(target_definition.platform, pods)
generator = Generator::PrefixHeader.new(library.file_accessors, library.platform)
generator.imports << library.target_header_path.basename
generator.save_as(path)
add_file_to_support_group(path)
......@@ -234,8 +200,7 @@ module Pod
if target_definition.podfile.generate_bridge_support?
path = library.bridge_support_path
UI.message "- Generating BridgeSupport metadata at #{UI.path(path)}" do
relative_headers = pods.map { |pod| pod.header_files.map {|head| sandbox.relativize(head)} }.flatten
headers = relative_headers.map { |header| sandbox.root + header }
headers = 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)
......@@ -255,7 +220,7 @@ module Pod
def create_copy_resources_script
path = library.copy_resources_script_path
UI.message "- Generating copy resources script at #{UI.path(path)}" do
resources = pods.map { |p| p.resource_files.map {|res| sandbox.relativize(res)} }.flatten
resources = library.file_accessors.map { |accessor| accessor.resources.values.flatten.map {|res| sandbox.relativize(res)} }.flatten
resources << bridge_support_file if bridge_support_file
generator = Generator::CopyResourcesScript.new(resources)
generator.save_as(path)
......@@ -272,7 +237,7 @@ module Pod
Generator::Acknowledgements.generators.each do |generator_class|
path = generator_class.path_from_basepath(basepath)
UI.message "- Generating acknowledgements at #{UI.path(path)}" do
generator = generator_class.new(target_definition, pods)
generator = generator_class.new(library.file_accessors)
generator.save_as(path)
add_file_to_support_group(path)
end
......@@ -286,7 +251,7 @@ module Pod
#
def create_dummy_source
path = library.dummy_source_path
UI.message "- Generating acknowledgements at #{UI.path(path)}" do
UI.message "- Generating dummy source file at #{UI.path(path)}" do
generator = Generator::DummySource.new(library.label)
generator.save_as(path)
file_reference = add_file_to_support_group(path)
......@@ -298,8 +263,33 @@ module Pod
private
# @return [PBXNativeTarget] the target generated by the installation
# process.
#
# @note Generated by the {#add_target} step.
#
attr_reader :target
# @!group Private helpers.
# @return [Project] the Pods project of the sandbox.
#
def project
sandbox.project
end
# @return [TargetDefinition] the target definition of the library.
#
def target_definition
library.target_definition
end
# @return [Specification::Consumer] the consumer for the specifications.
#
def spec_consumers
@spec_consumers ||= library.file_accessors.map(&:spec_consumer)
end
# @return [PBXGroup] the group where the file references to the support
# files should be stored.
#
......
......@@ -12,23 +12,25 @@ module Pod
end
@target_definition = @podfile.target_definitions[:default]
@project = Project.new
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))
source_files = config.sandbox.relativize_paths(file_accessor.source_files)
@project.add_source_files(source_files, 'BananaLib', @project.pods)
@library = Library.new(@target_definition)
@library.platform = Platform.new(:ios, '6.0')
@library.support_files_root = config.sandbox.root
@library.user_project_path = config.sandbox.root + '../user_project.xcodeproj'
@library.user_build_configurations = { 'Debug' => :debug, 'Release' => :release, 'AppStore' => :release, 'Test' => :debug }
specification = fixture_spec('banana-lib/BananaLib.podspec')
@library.specs = [specification]
@pod = LocalPod.new(specification, config.sandbox, @library.platform)
@library.local_pods = [@pod]
@library.specs = [@spec]
@library.file_accessors = [file_accessor]
@installer = TargetInstaller.new(config.sandbox, @library)
specification.prefix_header_contents = '#import "BlocksKit.h"'
@pod.stubs(:root).returns(Pathname.new(fixture('banana-lib')))
@pod.add_file_references_to_project(@project)
@spec.prefix_header_contents = '#import "BlocksKit.h"'
end
it "adds file references for the support files of the target" do
......@@ -112,7 +114,7 @@ module Pod
it "does not enable the GCC_WARN_INHIBIT_ALL_WARNINGS flag by default" do
@installer.install!
@installer.target.build_configurations.each do |config|
@installer.library.target.build_configurations.each do |config|
config.build_settings['GCC_WARN_INHIBIT_ALL_WARNINGS'].should.be.nil
end
end
......@@ -120,7 +122,7 @@ module Pod
it "enables the GCC_WARN_INHIBIT_ALL_WARNINGS flag" do
@podfile.inhibit_all_warnings!
@installer.install!
@installer.target.build_configurations.each do |config|
@installer.library.target.build_configurations.each do |config|
config.build_settings['GCC_WARN_INHIBIT_ALL_WARNINGS'].should == 'YES'
end
end
......@@ -129,14 +131,14 @@ module Pod
it 'adds the source files of each pod to the target of the Pod library' do
@installer.install!
names = @installer.target.source_build_phase.files.map { |bf| bf.file_ref.name }
names = @installer.library.target.source_build_phase.files.map { |bf| bf.file_ref.name }
names.should.include("Banana.m")
end
it '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.project['Frameworks'].children.map(&:name)
names = @installer.sandbox.project['Frameworks'].children.map(&:name)
names.sort.should == ["Foundation.framework", "QuartzCore.framework"]
end
......@@ -158,17 +160,20 @@ module Pod
end
it "creates a prefix header, including the contents of the specification's prefix header" do
@pod.top_specification.prefix_header_contents = '#import "BlocksKit.h"'
@spec.prefix_header_contents = '#import "BlocksKit.h"'
@installer.install!
prefix_header = config.sandbox.root + 'Pods-prefix.pch'
prefix_header.read.should == <<-EOS.strip_heredoc
generated = prefix_header.read
expected = <<-EOS.strip_heredoc
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import "Pods-header.h"
#import "BlocksKit.h"
#import <BananaTree/BananaTree.h>
EOS
generated.should == expected
end
it "creates a bridge support file" do
......@@ -193,7 +198,7 @@ module Pod
it "creates a dummy source to ensure the compilation of libraries with only categories" do
@installer.install!
build_files = @installer.target.source_build_phase.files
build_files = @installer.library.target.source_build_phase.files
build_file = build_files.find { |bf| bf.file_ref.name == 'Pods-dummy.m' }
build_file.should.be.not.nil
build_file.file_ref.path.should == 'Pods-dummy.m'
......
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