Commit d691d0bb authored by Fabio Pelosin's avatar Fabio Pelosin

Clean-up

parent 602d23f6
...@@ -2,151 +2,145 @@ module Pod ...@@ -2,151 +2,145 @@ module Pod
class Installer class Installer
class PodsProjectGenerator 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.
# #
class FileReferencesInstaller class FileReferencesInstaller
# @return [Sandbox] The sandbox of the installation. # @return [Sandbox] The sandbox of the installation.
# #
attr_reader :sandbox attr_reader :sandbox
# @return [Array<Library>] The libraries of the installation. # @return [Array<Library>] The libraries of the installation.
# #
attr_reader :pod_targets attr_reader :pod_targets
# @param [Sandbox] sandbox @see sandbox # @param [Sandbox] sandbox @see sandbox
# @param [Array<Library>] libraries @see libraries # @param [Array<Library>] libraries @see libraries
# @param [Project] libraries @see libraries # @param [Project] libraries @see libraries
# #
def initialize(sandbox, pod_targets) def initialize(sandbox, pod_targets)
@sandbox = sandbox @sandbox = sandbox
@pod_targets = pod_targets @pod_targets = pod_targets
end end
# Installs the file references. # Installs the file references.
# #
# @return [void] # @return [void]
# #
def install! def install!
refresh_file_accessors refresh_file_accessors
add_source_files_references add_source_files_references
add_frameworks_bundles add_frameworks_bundles
add_vendored_libraries add_vendored_libraries
add_resources add_resources
end end
#-----------------------------------------------------------------------#
private private
# @!group Installation Steps # @!group Installation Steps
#---------------------------------------------------------------------#
# Reads the file accessors contents from the file system. # Reads the file accessors contents from the file system.
# #
# @note The contents of the file accessors are modified by the clean # @note The contents of the file accessors are modified by the clean
# step of the #{PodSourceInstaller} and by the pre install hooks. # step of the #{PodSourceInstaller} and by the pre install hooks.
# #
# @return [void] # @return [void]
# #
def refresh_file_accessors def refresh_file_accessors
file_accessors.each do |fa| file_accessors.each do |fa|
fa.path_list.read_file_system fa.path_list.read_file_system
end
end end
end
# Adds the source files of the Pods to the Pods project. # Adds the source files of the Pods to the Pods project.
# #
# @note The source files are grouped by Pod and in turn by subspec # @note The source files are grouped by Pod and in turn by subspec
# (recursively). # (recursively).
# #
# @return [void] # @return [void]
# #
def add_source_files_references def add_source_files_references
UI.message "- Adding source files" do UI.message "- Adding source files" do
add_file_accessors_paths_to_pods_group(:source_files, :source_files) add_file_accessors_paths_to_pods_group(:source_files, :source_files)
end
end end
end
# Adds the bundled frameworks to the Pods project # Adds the bundled frameworks to the Pods project
# #
# @return [void] # @return [void]
# #
def add_frameworks_bundles def add_frameworks_bundles
UI.message "- Adding frameworks" do UI.message "- Adding frameworks" do
add_file_accessors_paths_to_pods_group(:vendored_frameworks, :frameworks_and_libraries) add_file_accessors_paths_to_pods_group(:vendored_frameworks, :frameworks_and_libraries)
end
end end
end
# Adds the bundled libraries to the Pods project # Adds the bundled libraries to the Pods project
# #
# @return [void] # @return [void]
# #
def add_vendored_libraries def add_vendored_libraries
UI.message "- Adding libraries" do UI.message "- Adding libraries" do
add_file_accessors_paths_to_pods_group(:vendored_libraries, :frameworks_and_libraries) add_file_accessors_paths_to_pods_group(:vendored_libraries, :frameworks_and_libraries)
end
end end
end
# Adds the resources of the Pods to the Pods project. # Adds the resources of the Pods to the Pods project.
# #
# @note The source files are grouped by Pod and in turn by subspec # @note The source files are grouped by Pod and in turn by subspec
# (recursively) in the resources group. # (recursively) in the resources group.
# #
# @return [void] # @return [void]
# #
def add_resources def add_resources
UI.message "- Adding resources" do UI.message "- Adding resources" do
add_file_accessors_paths_to_pods_group(:resources, :resources) add_file_accessors_paths_to_pods_group(:resources, :resources)
add_file_accessors_paths_to_pods_group(:resource_bundle_files, :resources) add_file_accessors_paths_to_pods_group(:resource_bundle_files, :resources)
end
end end
end
#-----------------------------------------------------------------------#
private private
# @!group Private Helpers # @!group Private Helpers
#---------------------------------------------------------------------#
# TODO
#
def pods_project
sandbox.project
end
# @return [Array<Sandbox::FileAccessor>] The file accessors for all the # @return [Array<Sandbox::FileAccessor>] The file accessors for all the
# specs platform combinations. # specs platform combinations.
# #
def file_accessors def file_accessors
@file_accessors ||= pod_targets.map(&:file_accessors).flatten.compact @file_accessors ||= pod_targets.map(&:file_accessors).flatten.compact
end end
# Adds file references to the list of the paths returned by the file # Adds file references to the list of the paths returned by the file
# accessor with the given key to the given group of the Pods project. # accessor with the given key to the given group of the Pods project.
# #
# @param [Symbol] file_accessor_key # @param [Symbol] file_accessor_key
# The method of the file accessor which would return the list of # The method of the file accessor which would return the list of
# the paths. # the paths.
# #
# @param [Symbol] group_key # @param [Symbol] group_key
# The key of the group of the Pods project. # The key of the group of the Pods project.
# #
# @return [void] # @return [void]
# #
def add_file_accessors_paths_to_pods_group(file_accessor_key, group_key) def add_file_accessors_paths_to_pods_group(file_accessor_key, group_key)
file_accessors.each do |file_accessor| file_accessors.each do |file_accessor|
paths = file_accessor.send(file_accessor_key) paths = file_accessor.send(file_accessor_key)
paths.each do |path| paths.each do |path|
group = pods_project.group_for_spec(file_accessor.spec.name, group_key) group = sandbox.project.group_for_spec(file_accessor.spec.name, group_key)
pods_project.add_file_reference(path, group) sandbox.project.add_file_reference(path, group)
end
end end
end end
end
#-----------------------------------------------------------------------# #---------------------------------------------------------------------#
end
end end
end end
end end
end
...@@ -2,132 +2,132 @@ module Pod ...@@ -2,132 +2,132 @@ module Pod
class Installer class Installer
class PodsProjectGenerator 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
# by the target. # by the target.
# #
class TargetInstaller class TargetInstaller
# @return [Sandbox] sandbox the sandbox where the support files should # @return [Sandbox] sandbox the sandbox where the support files should
# be generated. # be generated.
# #
attr_reader :sandbox attr_reader :sandbox
# @return [Library] The library whose target needs to be generated.
#
attr_reader :library
# @param [Project] project @see project
# @param [Library] library @see library
#
def initialize(sandbox, library)
@sandbox = sandbox
@library = library
end
# @return [Library] The library whose target needs to be generated.
#
attr_reader :library
# @param [Project] project @see project private
# @param [Library] library @see library
#
def initialize(sandbox, library)
@sandbox = sandbox
@library = library
end
private # @!group Installation steps
#---------------------------------------------------------------------#
#-----------------------------------------------------------------------# # Adds the target for the library to the Pods project with the
# appropriate build configurations.
#
# @note The `PODS_HEADERS_SEARCH_PATHS` overrides the xcconfig.
#
# @return [void]
#
def add_target
name = library.label
platform = library.platform.name
deployment_target = library.platform.deployment_target.to_s
@target = project.new_target(:static_library, name, platform, deployment_target)
# @!group Installation steps settings = {}
if library.platform.requires_legacy_ios_archs?
settings['ARCHS'] = "armv6 armv7"
end
# Adds the target for the library to the Pods project with the @target.build_settings('Debug').merge!(settings)
# appropriate build configurations. @target.build_settings('Release').merge!(settings)
#
# @note The `PODS_HEADERS_SEARCH_PATHS` overrides the xcconfig.
#
# @return [void]
#
def add_target
name = library.label
platform = library.platform.name
deployment_target = library.platform.deployment_target.to_s
@target = project.new_target(:static_library, name, platform, deployment_target)
settings = {}
if library.platform.requires_legacy_ios_archs?
settings['ARCHS'] = "armv6 armv7"
end
@target.build_settings('Debug').merge!(settings) library.user_build_configurations.each do |bc_name, type|
@target.build_settings('Release').merge!(settings) @target.add_build_configuration(bc_name, type)
end
library.user_build_configurations.each do |bc_name, type| library.target = @target
@target.add_build_configuration(bc_name, type)
end end
library.target = @target # Creates the group that holds the references to the support files
end # generated by this installer.
#
# Creates the group that holds the references to the support files # @return [void]
# generated by this installer. #
# def create_suport_files_group
# @return [void] @support_files_group = project.support_files_group.new_group(library.name)
#
def create_suport_files_group
@support_files_group = project.support_files_group.new_group(library.name)
end
# Generates a dummy source file for each target so libraries that contain
# only categories build.
#
# @return [void]
#
def create_dummy_source
path = library.dummy_source_path
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)
target.source_build_phase.add_file_reference(file_reference)
end end
end
# @return [PBXNativeTarget] the target generated by the installation # Generates a dummy source file for each target so libraries that contain
# process. # only categories build.
# #
# @note Generated by the {#add_target} step. # @return [void]
# #
attr_reader :target def create_dummy_source
path = library.dummy_source_path
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)
target.source_build_phase.add_file_reference(file_reference)
end
end
private # @return [PBXNativeTarget] the target generated by the installation
# process.
#
# @note Generated by the {#add_target} step.
#
attr_reader :target
#-----------------------------------------------------------------------#
# @!group Private helpers. private
# @return [Project] the Pods project of the sandbox. # @!group Private helpers.
# #---------------------------------------------------------------------#
def project
sandbox.project
end
# @return [TargetDefinition] the target definition of the library. # @return [Project] the Pods project of the sandbox.
# #
def target_definition def project
library.target_definition sandbox.project
end end
# @return [PBXGroup] the group where the file references to the support # @return [TargetDefinition] the target definition of the library.
# files should be stored. #
# def target_definition
attr_reader :support_files_group library.target_definition
end
# Adds a reference to the given file in the support group of this target. # @return [PBXGroup] the group where the file references to the support
# # files should be stored.
# @param [Pathname] path #
# The path of the file to which the reference should be added. attr_reader :support_files_group
#
# @return [PBXFileReference] the file reference of the added file. # Adds a reference to the given file in the support group of this target.
# #
def add_file_to_support_group(path) # @param [Pathname] path
support_files_group.new_file(path) # The path of the file to which the reference should be added.
end #
# @return [PBXFileReference] the file reference of the added file.
#
def add_file_to_support_group(path)
support_files_group.new_file(path)
end
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
end
end end
end end
end end
end
...@@ -9,7 +9,7 @@ module Pod ...@@ -9,7 +9,7 @@ module Pod
@pod_target.file_accessors = [@file_accessor] @pod_target.file_accessors = [@file_accessor]
config.sandbox.project = Project.new(config.sandbox.project_path) config.sandbox.project = Project.new(config.sandbox.project_path)
config.sandbox.project.add_pod_group('BananaLib', fixture('banana-lib')) config.sandbox.project.add_pod_group('BananaLib', fixture('banana-lib'))
@installer = Installer::PodsProjectGenerator::FileReferencesInstaller.new(config.sandbox, [@pod_target]) @sut = Installer::PodsProjectGenerator::FileReferencesInstaller.new(config.sandbox, [@pod_target])
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -19,18 +19,18 @@ module Pod ...@@ -19,18 +19,18 @@ module Pod
it "adds the files references of the source files the Pods project" do it "adds the files references of the source files the Pods project" do
@file_accessor.path_list.read_file_system @file_accessor.path_list.read_file_system
@file_accessor.path_list.expects(:read_file_system) @file_accessor.path_list.expects(:read_file_system)
@installer.install! @sut.install!
end end
it "adds the files references of the source files the Pods project" do it "adds the files references of the source files the Pods project" do
@installer.install! @sut.install!
file_ref = config.sandbox.project['Pods/BananaLib/Source Files/Banana.m'] file_ref = config.sandbox.project['Pods/BananaLib/Source Files/Banana.m']
file_ref.should.be.not.nil file_ref.should.be.not.nil
file_ref.path.should == "Classes/Banana.m" file_ref.path.should == "Classes/Banana.m"
end end
it "adds the file references of the frameworks of the project" do it "adds the file references of the frameworks of the project" do
@installer.install! @sut.install!
group = config.sandbox.project.group_for_spec('BananaLib', :frameworks_and_libraries) group = config.sandbox.project.group_for_spec('BananaLib', :frameworks_and_libraries)
file_ref = group['Bananalib.framework'] file_ref = group['Bananalib.framework']
file_ref.should.be.not.nil file_ref.should.be.not.nil
...@@ -38,7 +38,7 @@ module Pod ...@@ -38,7 +38,7 @@ module Pod
end end
it "adds the file references of the libraries of the project" do it "adds the file references of the libraries of the project" do
@installer.install! @sut.install!
group = config.sandbox.project.group_for_spec('BananaLib', :frameworks_and_libraries) group = config.sandbox.project.group_for_spec('BananaLib', :frameworks_and_libraries)
file_ref = group['libBananalib.a'] file_ref = group['libBananalib.a']
file_ref.should.be.not.nil file_ref.should.be.not.nil
...@@ -46,7 +46,7 @@ module Pod ...@@ -46,7 +46,7 @@ module Pod
end end
it "adds the files references of the resources the Pods project" do it "adds the files references of the resources the Pods project" do
@installer.install! @sut.install!
file_ref = config.sandbox.project['Pods/BananaLib/Resources/logo-sidebar.png'] file_ref = config.sandbox.project['Pods/BananaLib/Resources/logo-sidebar.png']
file_ref.should.be.not.nil file_ref.should.be.not.nil
file_ref.path.should == "Resources/logo-sidebar.png" file_ref.path.should == "Resources/logo-sidebar.png"
...@@ -64,23 +64,23 @@ module Pod ...@@ -64,23 +64,23 @@ 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::PodsProjectGenerator::FileReferencesInstaller.new(config.sandbox, [pod_target_1, pod_target_2]) @sut = Installer::PodsProjectGenerator::FileReferencesInstaller.new(config.sandbox, [pod_target_1, pod_target_2])
roots = installer.send(:file_accessors).map { |fa| fa.path_list.root } roots = @sut.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
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::PodsProjectGenerator::FileReferencesInstaller.new(config.sandbox, [pod_target_1]) @sut = Installer::PodsProjectGenerator::FileReferencesInstaller.new(config.sandbox, [pod_target_1])
roots = installer.send(:file_accessors).should == [] roots = @sut.send(:file_accessors).should == []
end end
end end
describe "#add_file_accessors_paths_to_pods_group" do describe "#add_file_accessors_paths_to_pods_group" do
it "adds the paths of the paths of the file accessor corresponding to the given key to the Pods project" do it "adds the paths of the paths of the file accessor corresponding to the given key to the Pods project" do
@installer.send(:add_file_accessors_paths_to_pods_group, :source_files, :source_files) @sut.send(:add_file_accessors_paths_to_pods_group, :source_files, :source_files)
group = config.sandbox.project.group_for_spec('BananaLib', :source_files) group = config.sandbox.project.group_for_spec('BananaLib', :source_files)
group.children.map(&:name).sort.should == ["Banana.h", "Banana.m", "BananaPrivate.h"] group.children.map(&:name).sort.should == ["Banana.h", "Banana.m", "BananaPrivate.h"]
end 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