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
4157fa39
Commit
4157fa39
authored
Feb 16, 2013
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WIP] Start to fix hooks
parent
efb81a02
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
292 additions
and
70 deletions
+292
-70
installer_data.rb
lib/cocoapods/hooks/installer_data.rb
+108
-26
library_data.rb
lib/cocoapods/hooks/library_data.rb
+2
-2
pod_data.rb
lib/cocoapods/hooks/pod_data.rb
+48
-16
target_installer_data.rb
lib/cocoapods/hooks/target_installer_data.rb
+1
-1
installer.rb
lib/cocoapods/installer.rb
+40
-25
integration_2.rb
spec/integration_2.rb
+4
-0
installer_data_spec.rb
spec/unit/hooks/installer_data_spec.rb
+89
-0
No files found.
lib/cocoapods/hooks/installer_data.rb
View file @
4157fa39
module
Pod
module
Pod
class
Podfile
def
config
UI
.
warn
"Podfile#config is deprecated. The config is accessible from "
\
"the parameter passed to the hooks"
Config
.
instance
end
end
# The public API should return dumb data types so it is easier to satisfy its
# implicit contract.
#
module
Hooks
module
Hooks
# Stores the information of the Installer for the hooks
# Stores the information of the Installer for the hooks
#
#
class
InstallerData
class
InstallerData
include
Config
::
Mixin
public
# @return [Sandbox] sandbox the sandbox where the support files should
# @!group Public Hooks API
# be generated.
# @return [Pathname] The root of the sandbox.
#
#
attr_accessor
:sandbox
def
sandbox_root
installer
.
sandbox
.
root
end
# @return [Library] The library whose target needs to be generated.
# @return [Pod::Project] the `Pods/Pods.xcodeproj` project.
#
def
project
installer
.
pods_project
end
# @return [Array<PodData>] The list of LocalPod instances for each
# dependency sorted by name.
#
def
pods
installer
.
pods_data
end
# @return [Array<TargetInstallerData>]
#
#
attr_accessor
:libraries
def
target_installers
installer
.
target_installers_data
end
# @return [Array<TargetInstaller>]
# @return [Hash{TargetDefinition => Array<Specification>}] The
# specifications grouped by target definition.
#
# @todo Consider grouping by TargetInstallerData.
#
#
# attr_accessor :target_installers
def
specs_by_target
result
=
{}
libraries
.
each
do
|
lib
|
result
[
lib
.
target_definition
]
=
lib
.
specs
end
result
end
# @return [Hash{TargetDefinition => Array<LocalPod>}] The local pod
# @return [Hash{TargetDefinition => Array<LocalPod>}] The local pod
# instances grouped by target.
# instances grouped by target.
#
#
# attr_accessor :local_pods_by_target
def
pods_by_target
result
=
{}
libraries
.
each
do
|
lib
|
root_specs
=
lib
.
specs
.
map
{
|
spec
|
spec
.
root
}.
uniq
pods_data
=
pods
.
select
{
|
pod_data
|
root_specs
.
include?
(
pod_data
.
root_spec
)
}
result
[
lib
.
target_definition
]
=
pods_data
end
result
end
# @return [Array<PodData>] The list of LocalPod instances for each
# @see pods_by_target
# dependency sorted by name.
#
# @todo Fix the warning.
#
#
attr_accessor
:pods
def
local_pods_by_target
# UI.warn "Podfile#config is deprecated. The config is accessible from " \
# "the parameter passed to the hooks".
pods_by_target
end
# @return [Pod::Project] the `Pods/Pods.xcodeproj` project.
#-----------------------------------------------------------------------#
public
# @!group Unsafe Hooks API
#
#
attr_accessor
:project
# The interface of the following objects might change at any time.
# If there some information which is needed, please open an issue.
def
specs_by_target
# @return [Sandbox] sandbox the sandbox where the support files should
# TODO
# be generated.
{}
#
def
sandbox
installer
.
sandbox
end
end
end
# @return [Config] The config singleton used for the installation.
end
#
end
def
config
Config
.
instance
end
# TODO
#-----------------------------------------------------------------------#
module
Pod
class
Podfile
# @!group Private implementation
include
Config
::
Mixin
end
# @param [Installer] installer @see installer
end
#
def
initialize
(
installer
)
@installer
=
installer
end
private
# @return [Installer] The installer described by this instance.
#
attr_reader
:installer
# @return [Library] The library whose target needs to be generated.
#
def
libraries
installer
.
libraries
end
#-----------------------------------------------------------------------#
end
end
end
lib/cocoapods/hooks/library_data.rb
View file @
4157fa39
module
Pod
module
Pod
module
Hooks
module
Hooks
# Stores the information of
# Stores the information of
#
#
# Was target definition
# Was target definition
#
#
class
LibraryData
class
LibraryData
...
...
lib/cocoapods/hooks/pod_data.rb
View file @
4157fa39
module
Pod
module
Pod
module
Hooks
module
Hooks
class
Specification
UI
.
warn
"Specification#config is deprecated. The config is accessible from "
\
"the parameter passed to the hooks"
include
Config
::
Mixin
end
# Stores the information of the Installer for the hooks
# Stores the information of the Installer for the hooks
#
#
class
PodData
class
PodData
# @return [
Pathname
]
# @return [
String
]
#
#
attr_accessor
:root
def
name
root_spec
.
name
end
# @return [Version]
# @return [Version]
#
#
attr_accessor
:root_spec
def
version
root_spec
.
name
end
#--------------------------------------------------------------------------------#
# @return [Specification]
#
def
root_spec
file_accessors
.
first
.
spec
.
root
end
def
to_s
# @return [Array<Specification>]
root_spec
.
to_s
#
def
specs
file_accessors
.
map
(
&
:spec
)
end
end
# @return [Pathname]
#
def
root
file_accessors
.
first
.
path_list
.
root
end
# @return [Array<Pathname>]
#
def
source_files
def
source_files
[]
file_accessors
.
map
(
&
:source_files
).
flatten
.
uniq
end
end
#-----------------------------------------------------------------------
---------
#
#-----------------------------------------------------------------------#
end
# @!group Private implementation
end
end
# @param [Installer] installer @see installer
#
def
initialize
(
file_accessors
)
@file_accessors
=
file_accessors
end
def
to_s
root_spec
.
to_s
end
private
attr_reader
:file_accessors
# TODO
#-----------------------------------------------------------------------#
module
Pod
class
Specification
end
include
Config
::
Mixin
end
end
end
end
lib/cocoapods/hooks/target_installer_data.rb
View file @
4157fa39
...
@@ -13,7 +13,7 @@ module Pod
...
@@ -13,7 +13,7 @@ module Pod
#
#
attr_accessor
:library
attr_accessor
:library
#-----------------------------------------------------------------------
---------
#
#-----------------------------------------------------------------------#
# @todo This has to be removed, but this means the specs have to be
# @todo This has to be removed, but this means the specs have to be
# updated if they need a reference to the prefix header.
# updated if they need a reference to the prefix header.
...
...
lib/cocoapods/installer.rb
View file @
4157fa39
...
@@ -320,25 +320,10 @@ module Pod
...
@@ -320,25 +320,10 @@ module Pod
def
run_pre_install_hooks
def
run_pre_install_hooks
UI
.
message
"- Running pre install hooks"
do
UI
.
message
"- Running pre install hooks"
do
installed_specs
.
each
do
|
spec
|
installed_specs
.
each
do
|
spec
|
pod_data
=
Hooks
::
PodData
.
new
executed
=
spec
.
pre_install!
(
pod_data
(
spec
),
library_data
(
nil
))
pod_data
.
root
=
sandbox
.
pod_dir
(
spec
.
root
.
name
)
library_data
=
Hooks
::
LibraryData
.
new
executed
=
spec
.
pre_install!
(
pod_data
,
library_data
)
UI
.
message
"-
#{
spec
.
name
}
"
if
executed
UI
.
message
"-
#{
spec
.
name
}
"
if
executed
end
end
installer_data
=
Hooks
::
InstallerData
.
new
installer_data
.
project
=
pods_project
installer_data
.
sandbox
=
sandbox
installer_data
.
libraries
=
libraries
installer_data
.
pods
=
[]
root_specs
=
analyzer
.
specifications
.
map
{
|
spec
|
spec
.
root
}.
uniq
root_specs
.
each
do
|
spec
|
pod_data
=
Hooks
::
PodData
.
new
pod_data
.
root_spec
=
spec
pod_data
.
root
=
nil
#TODO
installer_data
.
pods
=
[]
<<
pod_data
end
executed
=
@podfile
.
pre_install!
(
installer_data
)
executed
=
@podfile
.
pre_install!
(
installer_data
)
UI
.
message
"- Podfile"
if
executed
UI
.
message
"- Podfile"
if
executed
end
end
...
@@ -351,21 +336,14 @@ module Pod
...
@@ -351,21 +336,14 @@ module Pod
#
#
# @return [void]
# @return [void]
#
#
# @todo Run the hooks only for the installed pods.
#
# @todo Print a message with the names of the specs.
#
def
run_post_install_hooks
def
run_post_install_hooks
UI
.
message
"- Running post install hooks"
do
UI
.
message
"- Running post install hooks"
do
installed_specs
.
each
do
|
spec
|
installed_specs
.
each
do
|
spec
|
target_installer_data
=
Hooks
::
TargetInstallerData
.
new
target_installer_data
=
target_installers_data
.
first
#TODO
target_installer_data
.
sandbox
=
sandbox
target_installer_data
.
library
=
libraries
.
first
#TODO
executed
=
spec
.
post_install!
(
target_installer_data
)
executed
=
spec
.
post_install!
(
target_installer_data
)
UI
.
message
"-
#{
spec
.
name
}
"
if
executed
UI
.
message
"-
#{
spec
.
name
}
"
if
executed
end
end
installer_data
=
Hooks
::
InstallerData
.
new
installer_data
.
project
=
pods_project
executed
=
@podfile
.
post_install!
(
installer_data
)
executed
=
@podfile
.
post_install!
(
installer_data
)
UI
.
message
"- Podfile"
if
executed
UI
.
message
"- Podfile"
if
executed
end
end
...
@@ -446,5 +424,42 @@ module Pod
...
@@ -446,5 +424,42 @@ module Pod
#-------------------------------------------------------------------------#
#-------------------------------------------------------------------------#
public
# @!group Hooks
def
installer_data
Hooks
::
InstallerData
.
new
(
self
)
end
def
target_installers_data
@target_installers_data
||=
libraries
.
map
do
|
lib
|
data
=
Hooks
::
TargetInstallerData
.
new
data
.
sandbox
=
sandbox
data
.
library
=
lib
data
end
end
def
pods_data
specs
=
libraries
.
map
(
&
:specs
).
flatten
root_specs
=
specs
.
map
{
|
spec
|
spec
.
root
}.
uniq
root_specs
.
map
do
|
spec
|
pod_data
(
spec
)
end
end
def
pod_data
(
spec
)
all_file_accessors
=
libraries
.
map
(
&
:file_accessors
).
flatten
.
compact
file_accessors
=
all_file_accessors
.
select
{
|
fa
|
fa
.
spec
.
root
==
spec
.
root
}
Hooks
::
PodData
.
new
(
file_accessors
)
end
def
library_data
(
library
)
Hooks
::
LibraryData
.
new
end
#-------------------------------------------------------------------------#
end
end
end
end
spec/integration_2.rb
View file @
4157fa39
...
@@ -335,10 +335,14 @@ describe "Integration take 2" do
...
@@ -335,10 +335,14 @@ describe "Integration take 2" do
check
"install --no-update --no-doc"
,
"install_podspec"
check
"install --no-update --no-doc"
,
"install_podspec"
end
end
# TODO add tests for all the hooks API
#
describe
"Runs the Podfile callbacks"
do
describe
"Runs the Podfile callbacks"
do
check
"install --no-update --no-doc"
,
"install_podfile_callbacks"
check
"install --no-update --no-doc"
,
"install_podfile_callbacks"
end
end
# TODO add tests for all the hooks API
#
describe
"Runs the specification callbacks"
do
describe
"Runs the specification callbacks"
do
check
"install --no-update --no-doc"
,
"install_spec_callbacks"
check
"install --no-update --no-doc"
,
"install_spec_callbacks"
end
end
...
...
spec/unit/hooks/installer_data_spec.rb
0 → 100644
View file @
4157fa39
require
File
.
expand_path
(
'../../../spec_helper'
,
__FILE__
)
# Stubs an object ensuring that it responds to the given method
#
def
safe_stub
(
object
,
method
,
return_value
)
object
.
should
.
respond_to?
(
method
)
object
.
stubs
(
method
).
returns
(
return_value
)
end
module
Pod
describe
Hooks
::
InstallerData
do
before
do
target_definition_1
=
Podfile
::
TargetDefinition
.
new
(
'target_1'
,
nil
,
nil
)
target_definition_2
=
Podfile
::
TargetDefinition
.
new
(
'target_2'
,
nil
,
nil
)
lib_1
=
Library
.
new
(
target_definition_1
)
lib_2
=
Library
.
new
(
target_definition_2
)
spec_1
=
Spec
.
new
(
nil
,
'Spec_1'
)
spec_2
=
Spec
.
new
(
nil
,
'Spec_2'
)
lib_1
.
specs
=
[
spec_1
]
lib_2
.
specs
=
[
spec_2
]
pods_project
=
Pod
::
Project
.
new
(
config
.
sandbox
.
project_path
)
@installer
=
Installer
.
new
(
config
.
sandbox
,
nil
,
nil
)
safe_stub
(
@installer
,
:pods_project
,
pods_project
)
safe_stub
(
@installer
,
:libraries
,
[
lib_1
,
lib_2
])
@installer_data
=
Hooks
::
InstallerData
.
new
(
@installer
)
end
#-------------------------------------------------------------------------#
describe
"Public Hooks API"
do
it
"returns the sandbox root"
do
@installer_data
.
sandbox
.
root
.
should
==
temporary_directory
+
'Pods'
end
it
"returns the pods project"
do
@installer_data
.
project
.
class
.
should
==
Pod
::
Project
end
it
"returns the pods data"
do
@installer_data
.
pods
.
map
(
&
:name
).
should
==
[
"Spec_1"
,
"Spec_2"
]
end
it
"returns the target installers data"
do
names
=
@installer_data
.
target_installers
.
map
{
|
ti_data
|
ti_data
.
target_definition
.
name
}
names
.
should
==
[
"target_1"
,
"target_2"
]
end
it
"returns the specs by target"
do
specs_by_target
=
@installer_data
.
specs_by_target
names
=
{}
specs_by_target
.
each
do
|
target
,
specs
|
names
[
target
.
name
]
=
specs
.
map
(
&
:name
)
end
names
.
should
==
{
"target_1"
=>
[
"Spec_1"
],
"target_2"
=>
[
"Spec_2"
]}
end
it
"returns the pods data grouped by target definition data"
do
pods_by_target
=
@installer_data
.
pods_by_target
names
=
{}
pods_by_target
.
each
do
|
target
,
pods_data
|
names
[
target
.
name
]
=
pods_data
.
map
(
&
:name
)
end
names
.
should
==
{
"target_1"
=>
[
"Spec_1"
],
"target_2"
=>
[
"Spec_2"
]}
end
end
#-------------------------------------------------------------------------#
describe
"Unsafe Hooks API"
do
it
"returns the sandbox"
do
@installer_data
.
sandbox
.
should
==
config
.
sandbox
end
it
"returns the config"
do
@installer_data
.
config
.
should
==
Config
.
instance
end
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