Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
275dc48b
Commit
275dc48b
authored
Jun 04, 2015
by
Marius Rackwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove the Hooks API representation layer
parent
a683efde
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
12 additions
and
621 deletions
+12
-621
installer_representation.rb
lib/cocoapods/hooks/installer_representation.rb
+0
-133
library_representation.rb
lib/cocoapods/hooks/library_representation.rb
+0
-93
pod_representation.rb
lib/cocoapods/hooks/pod_representation.rb
+0
-70
installer.rb
lib/cocoapods/installer.rb
+2
-69
installer_representation_spec.rb
spec/unit/hooks/installer_representation_spec.rb
+0
-76
library_representation_spec.rb
spec/unit/hooks/library_representation_spec.rb
+0
-70
pod_representation_spec.rb
spec/unit/hooks/pod_representation_spec.rb
+0
-48
installer_spec.rb
spec/unit/installer_spec.rb
+10
-62
No files found.
lib/cocoapods/hooks/installer_representation.rb
deleted
100644 → 0
View file @
a683efde
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
lib/cocoapods/hooks/library_representation.rb
deleted
100644 → 0
View file @
a683efde
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
lib/cocoapods/hooks/pod_representation.rb
deleted
100644 → 0
View file @
a683efde
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
lib/cocoapods/installer.rb
View file @
275dc48b
...
...
@@ -694,7 +694,7 @@ module Pod
# @return [Bool] Whether the hook was run.
#
def
run_podfile_pre_install_hook
podfile
.
pre_install!
(
installer_rep
)
podfile
.
pre_install!
(
self
)
rescue
=>
e
raise
Informative
,
'An error occurred while processing the pre-install '
\
'hook of the Podfile.'
\
...
...
@@ -722,80 +722,13 @@ module Pod
# @return [Bool] Whether the hook was run.
#
def
run_podfile_post_install_hook
podfile
.
post_install!
(
installer_rep
)
podfile
.
post_install!
(
self
)
rescue
=>
e
raise
Informative
,
'An error occurred while processing the post-install '
\
'hook of the Podfile.'
\
"
\n\n
#{
e
.
message
}
\n\n
#{
e
.
backtrace
*
"
\n
"
}
"
end
#-------------------------------------------------------------------------#
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.
#
...
...
spec/unit/hooks/installer_representation_spec.rb
deleted
100644 → 0
View file @
a683efde
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
spec/unit/hooks/library_representation_spec.rb
deleted
100644 → 0
View file @
a683efde
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
spec/unit/hooks/pod_representation_spec.rb
deleted
100644 → 0
View file @
a683efde
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
spec/unit/installer_spec.rb
View file @
275dc48b
...
...
@@ -731,73 +731,21 @@ module Pod
describe
'Podfile Hooks'
do
before
do
@installer
.
send
(
:analyze
)
@specs
=
@installer
.
pod_targets
.
map
(
&
:specs
).
flatten
@spec
=
@specs
.
find
{
|
spec
|
spec
&&
spec
.
name
==
'JSONKit'
}
@installer
.
stubs
(
:installed_specs
).
returns
(
@specs
)
@
aggregate_target
=
@installer
.
aggregate_targets
.
first
podfile
=
Pod
::
Podfile
.
new
do
platform
:ios
end
config
.
integrate_targets
=
false
@
installer
=
Installer
.
new
(
config
.
sandbox
,
podfile
)
end
it
'runs the pre install hooks'
do
installer_rep
=
stub
@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
@installer
.
podfile
.
expects
(
:pre_install!
).
with
(
@installer
)
@installer
.
install!
end
it
'r
eturns the aggregate targets which use a given Pod
'
do
libs
=
@installer
.
send
(
:libraries_using_spec
,
@spec
)
libs
.
map
(
&
:name
).
should
==
[
'Pods'
]
it
'r
uns the post install hooks
'
do
@installer
.
podfile
.
expects
(
:post_install!
).
with
(
@installer
)
@installer
.
install!
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment