Commit d4dc2702 authored by Marius Rackwitz's avatar Marius Rackwitz

Merge pull request #3649 from CocoaPods/mr-remove-hooks-representations

Remove the Hooks API representation artifacts
parents a683efde 39fef8b6
...@@ -12,6 +12,12 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -12,6 +12,12 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Samuel Giddins](https://github.com/segiddins) [Samuel Giddins](https://github.com/segiddins)
[#2390](https://github.com/CocoaPods/CocoaPods/issues/2390) [#2390](https://github.com/CocoaPods/CocoaPods/issues/2390)
* The `Installer` is passed directly to the `pre_install` and `post_install`
hooks defined in the Podfile, instead of the previously used
`Hooks::InstallerRepresentation`.
[Marius Rackwitz](https://github.com/mrackwitz)
[#3648](https://github.com/CocoaPods/CocoaPods/issues/3648)
##### Enhancements ##### Enhancements
* New commands `pod cache list` and `pod cache clean` allows you to see the * New commands `pod cache list` and `pod cache clean` allows you to see the
......
module Pod
# @todo: Remove by CocoaPods 1.0
#
class Podfile
def config
UI.warn 'Podfile#config is deprecated. The config is accessible from ' \
'the parameter passed to the hooks'
Config.instance
end
class TargetDefinition
def copy_resources_script_name
UI.warn 'TargetDefinition#copy_resources_script_name is deprecated. ' \
'The value is accessible directly from the representation of the ' \
'library using the #copy_resources_script_path method.'
Config.instance.sandbox.root + "#{label}-resources.sh"
end
end
end
module Hooks
# The installer representation to pass to the hooks.
#
class InstallerRepresentation
public
# @!group Public Hooks API
# @return [Pathname] The root of the sandbox.
#
def sandbox_root
installer.sandbox.root
end
# @return [Pod::Project] the `Pods/Pods.xcodeproj` project.
#
# @note This value is not yet set in the pre install callbacks.
#
def project
installer.pods_project
end
# @return [Array<PodRepresentation>] The representation of the Pods.
#
def pods
installer.pod_reps
end
# @return [Array<LibraryRepresentation>] The representation of the
# libraries.
#
def libraries
installer.library_reps
end
# @return [Hash{LibraryRepresentation => Array<Specification>}] The
# specifications grouped by target definition.
#
def specs_by_lib
result = {}
installer.aggregate_targets.each do |aggregate_target|
result[installer.library_rep(aggregate_target)] = aggregate_target.specs
end
result
end
# @return [Hash{LibraryRepresentation => Array<PodRepresentation>}] The
# local pod instances grouped by target.
#
def pods_by_lib
result = {}
installer.aggregate_targets.map(&:pod_targets).flatten.each do |lib|
pod_names = [lib.root_spec.name]
pod_reps = pods.select { |rep| pod_names.include?(rep.name) }
result[lib.target_definition] = pod_reps
end
result
end
#-----------------------------------------------------------------------#
public
# @!group Compatibility
#
# The following aliases provides compatibility with CP < 0.17
alias_method :target_installers, :libraries
alias_method :specs_by_target, :specs_by_lib
alias_method :local_pods_by_target, :pods_by_lib
#-----------------------------------------------------------------------#
public
# @!group Unsafe Hooks API
#
# The interface of the following objects might change at any time.
# If there some information which is needed, please open an issue.
# @return [Sandbox] sandbox the sandbox where the support files should
# be generated.
#
def sandbox
installer.sandbox
end
# @return [Config] The config singleton used for the installation.
#
def config
Config.instance
end
# @return [Installer] The installer described by this instance.
#
attr_reader :installer
#-----------------------------------------------------------------------#
# @!group Private implementation
# Initialize a new instance
#
# @param [Installer] installer @see installer
#
def initialize(installer)
@installer = installer
end
#-----------------------------------------------------------------------#
end
end
end
module Pod
module Hooks
class LibraryRepresentation
# Stores the information of the target installer
#-----------------------------------------------------------------------#
# @return [String] The name of the Pods library.
#
def name
library.name
end
# @return [Array<Dependency>] The dependencies of this library.
#
def dependencies
target_definition.dependencies
end
# @return [Pathname] The path of the Pods dir.
#
def sandbox_dir
sandbox.root
end
# @return [Pathname] The path of the prefix_header
#
def prefix_header_path
UI.warn 'LibraryRepresentation#prefix_header_path is deprecated. ' \
'Use the specification `prefix_header_contents` attribute.'
library.prefix_header_path
end
alias_method :prefix_header_filename, :prefix_header_path
# @return [Pathname] The path of the script used to copy the resources.
#
def copy_resources_script_path
library.copy_resources_script_path
end
# @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
#-----------------------------------------------------------------------#
public
# @!group Unsafe Hooks API
# @return [Sandbox] sandbox the sandbox where the support files should
# be generated.
#
attr_reader :sandbox
# @return [Target] The library whose target needs to be generated.
#
attr_reader :library
# @return [PBXNativeTarget] The target generated by the installation
# process.
#
def target
library.native_target
end
#-----------------------------------------------------------------------#
# @!group Private implementation
# Initialize a new instance
#
# @param [Sandbox] sandbox @see sandbox
# @param [Target] library @see library
#
def initialize(sandbox, library)
@sandbox = sandbox
@library = library
raise '[BUG]' unless library.is_a?(AggregateTarget)
end
#-----------------------------------------------------------------------#
end
end
end
module Pod
class Specification
def config
UI.warn "[#{name}] Specification#config is deprecated. The config is accessible from " \
'the parameter passed to the hooks'
Config.instance
end
end
module Hooks
# Stores the information of the Installer for the hooks
#
class PodRepresentation
# @return [String] the name of the pod
#
attr_accessor :name
# @return [Version] the version
#
def version
root_spec.version
end
# @return [Specification] the root spec
#
def root_spec
file_accessors.first.spec.root
end
# @return [Array<Specification>] the specs
#
def specs
file_accessors.map(&:spec).uniq
end
# @return [Pathname] the root path
#
def root
file_accessors.first.path_list.root
end
# @return [Array<Pathname>] the source files
#
def source_files
file_accessors.map(&:source_files).flatten.uniq
end
#-----------------------------------------------------------------------#
# @!group Private implementation
# @param [Installer] installer @see installer
#
def initialize(name, file_accessors)
@name = name
@file_accessors = file_accessors
end
def to_s
root_spec.to_s
end
private
attr_reader :file_accessors
#-----------------------------------------------------------------------#
end
end
end
...@@ -168,11 +168,19 @@ module Pod ...@@ -168,11 +168,19 @@ module Pod
# #
attr_reader :names_of_pods_to_install attr_reader :names_of_pods_to_install
# @return [Array<AggregateTarget>] The Podfile targets containing library # @return [Array<AggregateTarget>] The model representations of an
# dependencies. # aggregation of pod targets generated for a target definition
# in the Podfile as result of the analyzer.
# #
attr_reader :aggregate_targets attr_reader :aggregate_targets
# @return [Array<PodTarget>] The model representations of pod targets
# generated as result of the analyzer.
#
def pod_targets
aggregate_targets.map(&:pod_targets).flatten
end
# @return [Array<Specification>] The specifications that where installed. # @return [Array<Specification>] The specifications that where installed.
# #
attr_accessor :installed_specs attr_accessor :installed_specs
...@@ -694,7 +702,7 @@ module Pod ...@@ -694,7 +702,7 @@ module Pod
# @return [Bool] Whether the hook was run. # @return [Bool] Whether the hook was run.
# #
def run_podfile_pre_install_hook def run_podfile_pre_install_hook
podfile.pre_install!(installer_rep) podfile.pre_install!(self)
rescue => e rescue => e
raise Informative, 'An error occurred while processing the pre-install ' \ raise Informative, 'An error occurred while processing the pre-install ' \
'hook of the Podfile.' \ 'hook of the Podfile.' \
...@@ -722,7 +730,7 @@ module Pod ...@@ -722,7 +730,7 @@ module Pod
# @return [Bool] Whether the hook was run. # @return [Bool] Whether the hook was run.
# #
def run_podfile_post_install_hook def run_podfile_post_install_hook
podfile.post_install!(installer_rep) podfile.post_install!(self)
rescue => e rescue => e
raise Informative, 'An error occurred while processing the post-install ' \ raise Informative, 'An error occurred while processing the post-install ' \
'hook of the Podfile.' \ 'hook of the Podfile.' \
...@@ -731,80 +739,6 @@ module Pod ...@@ -731,80 +739,6 @@ module Pod
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
public
# @!group Hooks Data
# Creates a hook representation for this installer.
#
# @return [InstallerRepresentation]
#
def installer_rep
Hooks::InstallerRepresentation.new(self)
end
# Creates a hook representation for a Pod.
#
# @param [String] pod
# The name of the pod.
#
# @return [PodRepresentation]
#
def pod_rep(pod)
all_file_accessors = pod_targets.map(&:file_accessors).flatten.compact
file_accessors = all_file_accessors.select { |fa| fa.spec.root.name == pod }
Hooks::PodRepresentation.new(pod, file_accessors)
end
# Creates a hook representation for a given aggregate target.
#
# @param [AggregateTarget] aggregate_target
# the aggregate target
#
# @return [LibraryRepresentation]
#
def library_rep(aggregate_target)
Hooks::LibraryRepresentation.new(sandbox, aggregate_target)
end
# Creates hook representations for all aggregate targets.
#
# @return [Array<LibraryRepresentation>]
#
def library_reps
@library_reps ||= aggregate_targets.map { |lib| library_rep(lib) }
end
# Creates hook representations for all #root_specs.
#
# @return [Array<PodRepresentation>]
#
def pod_reps
root_specs.sort_by(&:name).map { |spec| pod_rep(spec.name) }
end
# Returns the libraries which use the given specification.
#
# @param [Specification] spec
# The specification for which the client libraries are needed.
#
# @return [Array<Library>] The library.
#
def libraries_using_spec(spec)
aggregate_targets.select do |aggregate_target|
aggregate_target.pod_targets.any? { |pod_target| pod_target.specs.include?(spec) }
end
end
# @return [Array<Library>] The libraries generated by the installation
# process.
#
def pod_targets
aggregate_targets.map(&:pod_targets).flatten
end
#-------------------------------------------------------------------------#
private private
# @!group Private helpers # @!group Private helpers
......
Subproject commit 89a4128624a7b36711f8705338e3f63250dabc69 Subproject commit f0e07c4d947f26ecadbeb88cc996fb74875306fc
require File.expand_path('../../../spec_helper', __FILE__)
def safe_stub(object, method, return_value = nil)
object.should.respond_to(method)
object.expects(method).returns(return_value)
end
module Pod
describe Hooks::InstallerRepresentation do
before do
podfile = Pod::Podfile.new do
platform :ios
pod 'JSONKit'
end
config.integrate_targets = false
@installer = Installer.new(config.sandbox, podfile)
@installer.send(:analyze)
@specs = @installer.aggregate_targets.first.pod_targets.first.specs
@installer.stubs(:installed_specs).returns(@specs)
@rep = Hooks::InstallerRepresentation.new(@installer)
end
#-------------------------------------------------------------------------#
describe 'Public Hooks API' do
it 'returns the sandbox root' do
@rep.sandbox_root.should == config.sandbox.root
end
it 'returns the pods project' do
project = stub
safe_stub(@installer, :pods_project, project)
@rep.project.should == project
end
it 'the hook representation of the pods' do
@rep.pods.map(&:name).should == ['JSONKit']
end
it 'the hook representation of the libraries' do
@rep.libraries.map(&:name).sort.should == ['Pods'].sort
end
it 'returns the specs by library representation' do
specs_by_lib = @rep.specs_by_lib
lib_rep = specs_by_lib.keys.first
lib_rep.name.should == 'Pods'
specs_by_lib.should == { lib_rep => @specs }
end
it 'returns the pods representation by library representation' do
pods_by_lib = @rep.pods_by_lib
target_definition = @installer.aggregate_targets.first.pod_targets.first.target_definition
pods_by_lib[target_definition].map(&:name).should == ['JSONKit']
end
end
#-------------------------------------------------------------------------#
describe 'Unsafe Hooks API' do
it 'returns the sandbox' do
@rep.sandbox.should == config.sandbox
end
it 'returns the config' do
@rep.config.should == config
end
it 'returns the installer' do
@rep.installer.should == @installer
end
end
#-------------------------------------------------------------------------#
end
end
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Hooks::LibraryRepresentation do
before do
@target_definition = Podfile::TargetDefinition.new('MyApp', nil)
@spec = Spec.new
@spec.name = 'RestKit'
@lib = AggregateTarget.new(@target_definition, config.sandbox)
@rep = Hooks::LibraryRepresentation.new(config.sandbox, @lib)
end
#-------------------------------------------------------------------------#
describe 'Public Hooks API' do
it 'returns the name' do
@rep.name.should == 'Pods-MyApp'
end
it 'returns the dependencies' do
@target_definition.store_pod('AFNetworking')
@rep.dependencies.should == [Dependency.new('AFNetworking')]
end
it 'returns the sandbox dir' do
@rep.sandbox_dir.should == temporary_directory + 'Pods'
end
it 'returns the path of the prefix header' do
@rep.prefix_header_path.should == temporary_directory +
'Pods/Target Support Files/Pods-MyApp/Pods-MyApp-prefix.pch'
end
it 'returns the path of the copy resources script' do
@rep.copy_resources_script_path.should == temporary_directory +
'Pods/Target Support Files/Pods-MyApp/Pods-MyApp-resources.sh'
end
it 'returns the pods project' do
project = stub
config.sandbox.project = project
@rep.project.should == project
end
it 'returns the target definition' do
@rep.target_definition.should == @target_definition
end
end
#-------------------------------------------------------------------------#
describe 'Unsafe Hooks API' do
it 'returns the sandbox' do
@rep.sandbox.should == config.sandbox
end
it 'returns the library' do
@rep.library.should == @lib
end
it 'returns the native target' do
target = stub
@lib.native_target = target
@rep.target.should == target
end
end
#-------------------------------------------------------------------------#
end
end
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Hooks::PodRepresentation do
before do
@spec = fixture_spec('banana-lib/BananaLib.podspec')
@root = fixture('banana-lib')
@file_accessor = Sandbox::FileAccessor.new(Sandbox::PathList.new(@root), @spec.consumer(:ios))
@rep = Hooks::PodRepresentation.new('BananaLib', [@file_accessor])
end
#-------------------------------------------------------------------------#
describe 'Public Hooks API' do
it 'returns the name' do
@rep.name.should == 'BananaLib'
end
it 'returns the version' do
@rep.version.should == Version.new('1.0')
end
it 'returns the root specification' do
@rep.root_spec.should == @spec
end
it 'returns all the activated specifications' do
@rep.specs.should == [@spec]
end
it 'returns the directory where the pod is stored' do
@rep.root.should == @root
end
it 'returns the source files' do
source_files = @rep.source_files.map { |sf| sf.relative_path_from(@root).to_s }.sort
source_files.should == [
'Classes/Banana.h',
'Classes/Banana.m',
'Classes/BananaPrivate.h',
'Classes/BananaTrace.d',
]
end
end
#-------------------------------------------------------------------------#
end
end
...@@ -731,73 +731,21 @@ module Pod ...@@ -731,73 +731,21 @@ module Pod
describe 'Podfile Hooks' do describe 'Podfile Hooks' do
before do before do
@installer.send(:analyze) podfile = Pod::Podfile.new do
@specs = @installer.pod_targets.map(&:specs).flatten platform :ios
@spec = @specs.find { |spec| spec && spec.name == 'JSONKit' } end
@installer.stubs(:installed_specs).returns(@specs) config.integrate_targets = false
@aggregate_target = @installer.aggregate_targets.first @installer = Installer.new(config.sandbox, podfile)
end end
it 'runs the pre install hooks' do it 'runs the pre install hooks' do
installer_rep = stub @installer.podfile.expects(:pre_install!).with(@installer)
@installer.install!
@installer.expects(:installer_rep).returns(installer_rep)
@installer.podfile.expects(:pre_install!).with(installer_rep)
@installer.send(:run_podfile_pre_install_hooks)
end
it 'run_podfile_post_install_hooks' do
installer_rep = stub
@installer.expects(:installer_rep).returns(installer_rep)
@installer.podfile.expects(:post_install!).with(installer_rep)
@installer.send(:run_podfile_post_install_hooks)
end
it 'calls the hooks in the specs for each target' do
pod_target_ios = PodTarget.new([@spec], nil, config.sandbox)
pod_target_osx = PodTarget.new([@spec], nil, config.sandbox)
pod_target_ios.stubs(:name).returns('label')
pod_target_osx.stubs(:name).returns('label')
@installer.stubs(:pod_targets).returns([pod_target_ios, pod_target_osx])
@installer.stubs(:installer_rep).returns(stub)
@installer.podfile.expects(:pre_install!)
@installer.send(:run_podfile_pre_install_hooks)
@installer.send(:run_podfile_post_install_hooks)
end
it 'returns the hook representation of the installer' do
rep = @installer.send(:installer_rep)
rep.sandbox_root.should == @installer.sandbox.root
end
it 'returns the hook representation of a pod' do
file_accessor = stub(:spec => @spec)
@aggregate_target.pod_targets.first.stubs(:file_accessors).returns([file_accessor])
rep = @installer.send(:pod_rep, 'JSONKit')
rep.name.should == 'JSONKit'
rep.root_spec.should == @spec
end
it 'returns the hook representation of an aggregate target' do
rep = @installer.send(:library_rep, @aggregate_target)
rep.send(:library).name.should == 'Pods'
end
it 'returns the hook representation of all the pods' do
reps = @installer.send(:pod_reps)
reps.map(&:name).should == ['JSONKit']
end
it 'returns the hook representation of all the aggregate target' do
reps = @installer.send(:library_reps)
reps.map(&:name).sort.should == ['Pods'].sort
end end
it 'returns the aggregate targets which use a given Pod' do it 'runs the post install hooks' do
libs = @installer.send(:libraries_using_spec, @spec) @installer.podfile.expects(:post_install!).with(@installer)
libs.map(&:name).should == ['Pods'] @installer.install!
end end
end end
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