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
b09aaebd
Commit
b09aaebd
authored
Nov 27, 2011
by
Eloy Duran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Contain the cached sets in the Resolver itself.
parent
2e872f0f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
91 deletions
+63
-91
installer.rb
lib/cocoapods/installer.rb
+13
-8
target_installer.rb
lib/cocoapods/installer/target_installer.rb
+4
-0
resolver.rb
lib/cocoapods/resolver.rb
+24
-39
integration_spec.rb
spec/integration_spec.rb
+2
-5
resolver_spec.rb
spec/unit/resolver_spec.rb
+20
-39
No files found.
lib/cocoapods/installer.rb
View file @
b09aaebd
...
...
@@ -17,6 +17,11 @@ module Pod
config
.
project_root
+
'Podfile.lock'
end
def
dependency_specifications
# Resolve *all* dependencies first.
@dependency_specifications
||=
@resolver
.
resolve
end
def
project
return
@project
if
@project
@project
=
Pod
::
Project
.
for_platform
(
@podfile
.
platform
)
...
...
@@ -126,28 +131,28 @@ module Pod
end
end
def
dependen
t
_specifications_for_each_target_definition
@dependen
t
_specifications_for_each_target_definition
||=
@resolver
.
resolve
def
dependen
cy
_specifications_for_each_target_definition
@dependen
cy
_specifications_for_each_target_definition
||=
@resolver
.
resolve
end
def
dependen
t
_specifications
dependen
t
_specifications_for_each_target_definition
.
values
.
flatten
def
dependen
cy
_specifications
dependen
cy
_specifications_for_each_target_definition
.
values
.
flatten
end
def
activated_specifications
dependen
t
_specifications
.
reject
do
|
spec
|
dependen
cy
_specifications
.
reject
do
|
spec
|
# Don't activate specs which are only wrappers of subspecs, or share
# source with another pod but aren't activated themselves.
spec
.
wrapper?
||
@resolver
.
c
ontext
.
sets
[
spec
.
name
].
only_part_of_other_pod?
spec
.
wrapper?
||
@resolver
.
c
ached_
sets
[
spec
.
name
].
only_part_of_other_pod?
end
end
def
activated_specifications_for_target
(
target_definition
)
dependen
t
_specifications_for_each_target_definition
[
target_definition
]
dependen
cy
_specifications_for_each_target_definition
[
target_definition
]
end
def
download_only_specifications
dependen
t
_specifications
-
activated_specifications
dependen
cy
_specifications
-
activated_specifications
end
end
end
lib/cocoapods/installer/target_installer.rb
View file @
b09aaebd
...
...
@@ -9,6 +9,10 @@ module Pod
@podfile
,
@project
,
@target_definition
=
podfile
,
project
,
target_definition
end
def
dependency_specifications
@dependency_specifications
||=
@resolver
.
resolve
(
@definition
.
dependencies
)
end
def
xcconfig
@xcconfig
||=
Xcodeproj
::
Config
.
new
({
# In a workspace this is where the static library headers should be found.
...
...
lib/cocoapods/resolver.rb
View file @
b09aaebd
module
Pod
class
Resolver
# A Resolver::Context caches specification sets and is used by the resolver
# to ensure that extra dependencies on a set are added to the same instance.
#
# In addition, the context is later on used by Specification to lookup other
# specs, like the on they are a part of.
class
Context
attr_reader
:sources
,
:sets
,
:sandbox
def
initialize
(
sandbox
)
@sandbox
=
sandbox
@sets
=
{}
@sources
=
Source
::
Aggregate
.
new
end
def
find_dependency_set
(
dependency
)
@sets
[
dependency
.
name
]
||=
begin
if
dependency
.
specification
Specification
::
Set
::
External
.
new
(
dependency
.
specification
)
elsif
external_source
=
dependency
.
external_source
specification
=
external_source
.
specification_from_sandbox
(
@sandbox
)
Specification
::
Set
::
External
.
new
(
specification
)
else
@sources
.
search
(
dependency
)
end
end
end
end
attr_reader
:podfile
,
:sandbox
attr_accessor
:c
ontext
attr_accessor
:c
ached_sets
,
:cached_sources
def
initialize
(
podfile
,
sandbox
)
@podfile
=
podfile
@sandbox
=
sandbox
@context
=
Context
.
new
(
@sandbox
)
@cached_sets
=
{}
@cached_sources
=
Source
::
Aggregate
.
new
end
def
resolve
...
...
@@ -47,11 +20,11 @@ module Pod
result
end
# Specification doesn't need to know more about
a
context, so we assign
# Specification doesn't need to know more about
the
context, so we assign
# the other specification, of which this pod is a part, to the spec.
@specs
.
values
.
sort_by
(
&
:name
).
each
do
|
spec
|
if
spec
.
part_of_other_pod?
spec
.
part_of_specification
=
@c
ontext
.
sets
[
spec
.
part_of
.
name
].
specification
spec
.
part_of_specification
=
@c
ached_
sets
[
spec
.
part_of
.
name
].
specification
end
end
...
...
@@ -60,12 +33,24 @@ module Pod
private
# this can be called with anything that has dependencies
# e.g. a Specification or a Podfile.
def
find_dependency_sets
(
specification
,
dependencies
=
nil
)
(
dependencies
||
specification
.
dependencies
).
each
do
|
dependency
|
set
=
@context
.
find_dependency_set
(
dependency
)
set
.
required_by
(
specification
)
def
find_cached_set
(
dependency
)
@cached_sets
[
dependency
.
name
]
||=
begin
if
dependency
.
specification
Specification
::
Set
::
External
.
new
(
dependency
.
specification
)
elsif
external_source
=
dependency
.
external_source
specification
=
external_source
.
specification_from_sandbox
(
@sandbox
)
Specification
::
Set
::
External
.
new
(
specification
)
else
@cached_sources
.
search
(
dependency
)
end
end
end
def
find_dependency_sets
(
dependent_specification
,
dependencies
)
dependencies
.
each
do
|
dependency
|
set
=
find_cached_set
(
dependency
)
set
.
required_by
(
dependent_specification
)
# Ensure we don't resolve the same spec twice
unless
@loaded_specs
.
include?
(
dependency
.
name
)
# Get a reference to the spec that’s actually being loaded.
# If it’s a subspec dependency, e.g. 'RestKit/Network', then
...
...
@@ -81,7 +66,7 @@ module Pod
@specs
[
spec
.
name
]
=
spec
# And recursively load the dependencies of the spec.
find_dependency_sets
(
spec
)
find_dependency_sets
(
spec
,
spec
.
dependencies
)
end
end
end
...
...
spec/integration_spec.rb
View file @
b09aaebd
...
...
@@ -298,12 +298,9 @@ else
project
=
Xcodeproj
::
Project
.
new
(
config
.
project_pods_root
+
'Pods.xcodeproj'
)
project
.
targets
.
each
do
|
target
|
#target.source_build_phase
phase
=
target
.
buildPhases
.
find
{
|
phase
|
phase
.
is_a?
(
Xcodeproj
::
Project
::
PBXSourcesBuildPhase
)
}
phase
=
target
.
build_phases
.
find
{
|
phase
|
phase
.
is_a?
(
Xcodeproj
::
Project
::
Object
::
PBXSourcesBuildPhase
)
}
files
=
phase
.
files
.
map
(
&
:file
).
map
(
&
:name
)
p
target
.
productName
p
files
case
target
.
productName
case
target
.
product_name
when
'Pods'
files
.
should
.
include
"ASIHTTPRequest.m"
files
.
should
.
not
.
include
"SSZipArchive.m"
...
...
spec/unit/resolver_spec.rb
View file @
b09aaebd
require
File
.
expand_path
(
'../../spec_helper'
,
__FILE__
)
class
StubbedSet
<
Pod
::
Specification
::
Set
attr_accessor
:stub_platform
def
specification
spec
=
super
spec
.
platform
=
@stub_platform
spec
end
end
class
StubbedContext
<
Pod
::
Resolver
::
Context
attr_accessor
:stub_platform
def
find_dependency_set
(
dependency
)
set
=
StubbedSet
.
new
(
super
.
pod_dir
)
set
.
stub_platform
=
@stub_platform
set
end
end
describe
"Pod::Resolver"
do
before
do
Pod
::
Spec
::
Set
.
reset!
...
...
@@ -32,16 +12,16 @@ describe "Pod::Resolver" do
dependency
'ASIWebPageRequest'
end
config
.
rootspec
=
@podfile
@resolver
=
Pod
::
Resolver
.
new
(
@podfile
,
stub
(
'sandbox'
))
end
after
do
Pod
::
Config
.
instance
=
@config_before
end
it
"has a ResolveContext which holds global state, such as cached specification sets"
do
resolver
=
Pod
::
Resolver
.
new
(
@podfile
,
stub
(
'sandbox'
))
resolver
.
resolve
resolver
.
context
.
sets
.
values
.
sort_by
(
&
:name
).
should
==
[
it
"holds the context state, such as cached specification sets"
do
@resolver
.
resolve
@resolver
.
cached_sets
.
values
.
sort_by
(
&
:name
).
should
==
[
Pod
::
Spec
::
Set
.
new
(
config
.
repos_dir
+
'master/ASIHTTPRequest'
),
Pod
::
Spec
::
Set
.
new
(
config
.
repos_dir
+
'master/ASIWebPageRequest'
),
Pod
::
Spec
::
Set
.
new
(
config
.
repos_dir
+
'master/Reachability'
),
...
...
@@ -49,35 +29,36 @@ describe "Pod::Resolver" do
end
it
"returns all specs needed for the dependency"
do
specs
=
Pod
::
Resolver
.
new
(
@podfile
,
stub
(
'sandbox'
))
.
resolve
.
values
.
flatten
specs
=
@resolver
.
resolve
.
values
.
flatten
specs
.
map
(
&
:class
).
uniq
.
should
==
[
Pod
::
Specification
]
specs
.
map
(
&
:name
).
sort
.
should
==
%w{ ASIHTTPRequest ASIWebPageRequest Reachability }
end
it
"does not raise if all dependencies match the platform of the root spec (Podfile)"
do
resolver
=
Pod
::
Resolver
.
new
(
@podfile
,
stub
(
'sandbox'
))
@podfile
.
platform
:ios
lambda
{
resolver
.
resolve
}.
should
.
not
.
raise
lambda
{
@
resolver
.
resolve
}.
should
.
not
.
raise
@podfile
.
platform
:osx
lambda
{
resolver
.
resolve
}.
should
.
not
.
raise
lambda
{
@
resolver
.
resolve
}.
should
.
not
.
raise
end
it
"raises once any of the dependencies does not match the platform of the root spec (Podfile)"
do
resolver
=
Pod
::
Resolver
.
new
(
config
.
rootspec
,
stub
(
'sandbox'
))
context
=
resolver
.
context
=
StubbedContext
.
new
(
resolver
.
sandbox
)
set
=
Pod
::
Spec
::
Set
.
new
(
config
.
repos_dir
+
'master/ASIHTTPRequest'
)
@resolver
.
cached_sets
[
'ASIHTTPRequest'
]
=
set
def
set
.
stub_platform
=
(
platform
);
@stubbed_platform
=
platform
;
end
def
set
.
specification
;
spec
=
super
;
spec
.
platform
=
@stubbed_platform
;
spec
;
end
@podfile
.
platform
:ios
contex
t
.
stub_platform
=
:ios
lambda
{
resolver
.
resolve
}.
should
.
not
.
raise
contex
t
.
stub_platform
=
:osx
lambda
{
resolver
.
resolve
}.
should
.
raise
Pod
::
Informative
se
t
.
stub_platform
=
:ios
lambda
{
@
resolver
.
resolve
}.
should
.
not
.
raise
se
t
.
stub_platform
=
:osx
lambda
{
@
resolver
.
resolve
}.
should
.
raise
Pod
::
Informative
@podfile
.
platform
:osx
contex
t
.
stub_platform
=
:osx
lambda
{
resolver
.
resolve
}.
should
.
not
.
raise
contex
t
.
stub_platform
=
:ios
lambda
{
resolver
.
resolve
}.
should
.
raise
Pod
::
Informative
se
t
.
stub_platform
=
:osx
lambda
{
@
resolver
.
resolve
}.
should
.
not
.
raise
se
t
.
stub_platform
=
:ios
lambda
{
@
resolver
.
resolve
}.
should
.
raise
Pod
::
Informative
end
it
"resolves subspecs"
do
...
...
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