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

[TargetInstaller] Adapt for architectural changes

parent 65dcd5e2
...@@ -7,6 +7,15 @@ module Pod ...@@ -7,6 +7,15 @@ module Pod
# #
class TargetInstaller class TargetInstaller
# @return [Sandbox] sandbox the sandbox where the support files should
# be generated.
#
attr_reader :sandbox
# @return [Library] The library whose target needs to be generated.
#
attr_reader :library
# @param [Project] project @see project # @param [Project] project @see project
# @param [Library] library @see library # @param [Library] library @see library
# #
...@@ -20,8 +29,9 @@ module Pod ...@@ -20,8 +29,9 @@ module Pod
# @return [void] # @return [void]
# #
def install! def install!
UI.message "- Installing target `#{library.name}` #{library.platform}" do
add_target add_target
add_pod_references add_files_to_build_phases
create_suport_files_group create_suport_files_group
create_xcconfig_file create_xcconfig_file
...@@ -32,59 +42,6 @@ module Pod ...@@ -32,59 +42,6 @@ module Pod
create_acknowledgements create_acknowledgements
create_dummy_source create_dummy_source
end 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.
#
attr_reader :sandbox
# @return [Library] The library whose target needs to be generated.
#
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.
#
def pods
library.local_pods
end
# @return [TargetDefinition] the target definition of the library.
#
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.
#
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)
end end
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
...@@ -142,15 +99,24 @@ module Pod ...@@ -142,15 +99,24 @@ module Pod
# #
# @return [void] # @return [void]
# #
def add_pod_references def add_files_to_build_phases
pods.each do |pod| UI.message "- Adding Build files" do
pod.add_build_files_to_target(target) library.file_accessors.each do |file_accessor|
UI.message "- #{file_accessor.spec}"
pod.frameworks.each do |framework| 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) framework_ref = project.add_system_framework(framework, target)
end end
end end
end end
end
# Creates the group that holds the references to the support files # Creates the group that holds the references to the support files
# generated by this installer. # generated by this installer.
...@@ -174,7 +140,7 @@ module Pod ...@@ -174,7 +140,7 @@ module Pod
def create_xcconfig_file def create_xcconfig_file
path = library.xcconfig_path path = library.xcconfig_path
UI.message "- Generating xcconfig file at #{UI.path(path)}" do 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.set_arc_compatibility_flag = target_definition.podfile.set_arc_compatibility_flag?
gen.save_as(path) gen.save_as(path)
library.xcconfig = gen.xcconfig library.xcconfig = gen.xcconfig
...@@ -194,7 +160,7 @@ module Pod ...@@ -194,7 +160,7 @@ module Pod
# #
def create_target_header def create_target_header
path = library.target_header_path 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 = Generator::TargetHeader.new(library.specs)
generator.save_as(path) generator.save_as(path)
add_file_to_support_group(path) add_file_to_support_group(path)
...@@ -210,7 +176,7 @@ module Pod ...@@ -210,7 +176,7 @@ module Pod
def create_prefix_header def create_prefix_header
path = library.prefix_header_path path = library.prefix_header_path
UI.message "- Generating prefix header at #{UI.path(path)}" do 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.imports << library.target_header_path.basename
generator.save_as(path) generator.save_as(path)
add_file_to_support_group(path) add_file_to_support_group(path)
...@@ -234,8 +200,7 @@ module Pod ...@@ -234,8 +200,7 @@ module Pod
if target_definition.podfile.generate_bridge_support? if target_definition.podfile.generate_bridge_support?
path = library.bridge_support_path path = library.bridge_support_path
UI.message "- Generating BridgeSupport metadata at #{UI.path(path)}" do 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 = target.headers_build_phase.files.map { |bf| sandbox.root + bf.file_ref.path }
headers = relative_headers.map { |header| sandbox.root + header }
generator = Generator::BridgeSupport.new(headers) generator = Generator::BridgeSupport.new(headers)
generator.save_as(path) generator.save_as(path)
add_file_to_support_group(path) add_file_to_support_group(path)
...@@ -255,7 +220,7 @@ module Pod ...@@ -255,7 +220,7 @@ module Pod
def create_copy_resources_script def create_copy_resources_script
path = library.copy_resources_script_path path = library.copy_resources_script_path
UI.message "- Generating copy resources script at #{UI.path(path)}" do 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 resources << bridge_support_file if bridge_support_file
generator = Generator::CopyResourcesScript.new(resources) generator = Generator::CopyResourcesScript.new(resources)
generator.save_as(path) generator.save_as(path)
...@@ -272,7 +237,7 @@ module Pod ...@@ -272,7 +237,7 @@ module Pod
Generator::Acknowledgements.generators.each do |generator_class| Generator::Acknowledgements.generators.each do |generator_class|
path = generator_class.path_from_basepath(basepath) path = generator_class.path_from_basepath(basepath)
UI.message "- Generating acknowledgements at #{UI.path(path)}" do 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) generator.save_as(path)
add_file_to_support_group(path) add_file_to_support_group(path)
end end
...@@ -286,7 +251,7 @@ module Pod ...@@ -286,7 +251,7 @@ module Pod
# #
def create_dummy_source def create_dummy_source
path = library.dummy_source_path 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 = Generator::DummySource.new(library.label)
generator.save_as(path) generator.save_as(path)
file_reference = add_file_to_support_group(path) file_reference = add_file_to_support_group(path)
...@@ -298,8 +263,33 @@ module Pod ...@@ -298,8 +263,33 @@ module Pod
private private
# @return [PBXNativeTarget] the target generated by the installation
# process.
#
# @note Generated by the {#add_target} step.
#
attr_reader :target
# @!group Private helpers. # @!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 # @return [PBXGroup] the group where the file references to the support
# files should be stored. # files should be stored.
# #
......
...@@ -12,23 +12,25 @@ module Pod ...@@ -12,23 +12,25 @@ module Pod
end end
@target_definition = @podfile.target_definitions[:default] @target_definition = @podfile.target_definitions[:default]
@project = Project.new @project = Project.new
config.sandbox.project = @project 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 = Library.new(@target_definition)
@library.platform = Platform.new(:ios, '6.0') @library.platform = Platform.new(:ios, '6.0')
@library.support_files_root = config.sandbox.root @library.support_files_root = config.sandbox.root
@library.user_project_path = config.sandbox.root + '../user_project.xcodeproj' @library.user_project_path = config.sandbox.root + '../user_project.xcodeproj'
@library.user_build_configurations = { 'Debug' => :debug, 'Release' => :release, 'AppStore' => :release, 'Test' => :debug } @library.user_build_configurations = { 'Debug' => :debug, 'Release' => :release, 'AppStore' => :release, 'Test' => :debug }
specification = fixture_spec('banana-lib/BananaLib.podspec') @library.specs = [@spec]
@library.specs = [specification] @library.file_accessors = [file_accessor]
@pod = LocalPod.new(specification, config.sandbox, @library.platform)
@library.local_pods = [@pod]
@installer = TargetInstaller.new(config.sandbox, @library) @installer = TargetInstaller.new(config.sandbox, @library)
specification.prefix_header_contents = '#import "BlocksKit.h"' @spec.prefix_header_contents = '#import "BlocksKit.h"'
@pod.stubs(:root).returns(Pathname.new(fixture('banana-lib')))
@pod.add_file_references_to_project(@project)
end end
it "adds file references for the support files of the target" do it "adds file references for the support files of the target" do
...@@ -112,7 +114,7 @@ module Pod ...@@ -112,7 +114,7 @@ module Pod
it "does not enable the GCC_WARN_INHIBIT_ALL_WARNINGS flag by default" do it "does not enable the GCC_WARN_INHIBIT_ALL_WARNINGS flag by default" do
@installer.install! @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 config.build_settings['GCC_WARN_INHIBIT_ALL_WARNINGS'].should.be.nil
end end
end end
...@@ -120,7 +122,7 @@ module Pod ...@@ -120,7 +122,7 @@ module Pod
it "enables the GCC_WARN_INHIBIT_ALL_WARNINGS flag" do it "enables the GCC_WARN_INHIBIT_ALL_WARNINGS flag" do
@podfile.inhibit_all_warnings! @podfile.inhibit_all_warnings!
@installer.install! @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' config.build_settings['GCC_WARN_INHIBIT_ALL_WARNINGS'].should == 'YES'
end end
end end
...@@ -129,14 +131,14 @@ module Pod ...@@ -129,14 +131,14 @@ module Pod
it 'adds the source files of each pod to the target of the Pod library' do it 'adds the source files of each pod to the target of the Pod library' do
@installer.install! @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") names.should.include("Banana.m")
end end
it 'adds the frameworks required by to the pod to the project for informative purposes' do it 'adds the frameworks required by to the pod to the project for informative purposes' do
Specification::Consumer.any_instance.stubs(:frameworks).returns(['QuartzCore']) Specification::Consumer.any_instance.stubs(:frameworks).returns(['QuartzCore'])
@installer.install! @installer.install!
names = @installer.project['Frameworks'].children.map(&:name) names = @installer.sandbox.project['Frameworks'].children.map(&:name)
names.sort.should == ["Foundation.framework", "QuartzCore.framework"] names.sort.should == ["Foundation.framework", "QuartzCore.framework"]
end end
...@@ -158,17 +160,20 @@ module Pod ...@@ -158,17 +160,20 @@ module Pod
end end
it "creates a prefix header, including the contents of the specification's prefix header" do 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! @installer.install!
prefix_header = config.sandbox.root + 'Pods-prefix.pch' 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__ #ifdef __OBJC__
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#endif #endif
#import "Pods-header.h" #import "Pods-header.h"
#import "BlocksKit.h" #import "BlocksKit.h"
#import <BananaTree/BananaTree.h>
EOS EOS
generated.should == expected
end end
it "creates a bridge support file" do it "creates a bridge support file" do
...@@ -193,7 +198,7 @@ module Pod ...@@ -193,7 +198,7 @@ module Pod
it "creates a dummy source to ensure the compilation of libraries with only categories" do it "creates a dummy source to ensure the compilation of libraries with only categories" do
@installer.install! @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 = build_files.find { |bf| bf.file_ref.name == 'Pods-dummy.m' }
build_file.should.be.not.nil build_file.should.be.not.nil
build_file.file_ref.path.should == 'Pods-dummy.m' 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