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
6d3821be
Commit
6d3821be
authored
Aug 21, 2014
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Resolver] Use the given sources
parent
d5cb0bbd
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
118 additions
and
131 deletions
+118
-131
analyzer.rb
lib/cocoapods/installer/analyzer.rb
+9
-14
resolver.rb
lib/cocoapods/resolver.rb
+35
-20
sources_manager.rb
lib/cocoapods/sources_manager.rb
+37
-35
analyzer_spec.rb
spec/unit/installer/analyzer_spec.rb
+0
-27
resolver_spec.rb
spec/unit/resolver_spec.rb
+37
-19
sources_manager_spec.rb
spec/unit/sources_manager_spec.rb
+0
-16
No files found.
lib/cocoapods/installer/analyzer.rb
View file @
6d3821be
...
...
@@ -165,21 +165,10 @@ module Pod
# Updates the source repositories unless the config indicates to skip it.
#
# @return [void]
#
def
update_repositories_if_needed
unless
config
.
skip_repo_update?
sources
=
SourcesManager
.
podfile_sources
if
sources
.
empty?
UI
.
section
'Updating spec repositories'
do
SourcesManager
.
update
end
else
sources
.
each
do
|
source
|
UI
.
section
"Updating spec repository
#{
source
}
"
do
SourcesManager
.
update
(
source
)
end
end
UI
.
section
'Updating spec repositories'
do
SourcesManager
.
update
end
end
end
...
...
@@ -328,7 +317,13 @@ module Pod
def
resolve_dependencies
specs_by_target
=
nil
UI
.
section
"Resolving dependencies of
#{
UI
.
path
podfile
.
defined_in_file
}
"
do
resolver
=
Resolver
.
new
(
sandbox
,
podfile
,
locked_dependencies
)
if
podfile
.
sources
.
empty?
sources
=
SourcesManager
.
master
else
sources
=
SourcesManager
.
sources
(
podfile
.
sources
)
end
resolver
=
Resolver
.
new
(
sandbox
,
podfile
,
locked_dependencies
,
sources
)
specs_by_target
=
resolver
.
resolve
end
specs_by_target
...
...
lib/cocoapods/resolver.rb
View file @
6d3821be
...
...
@@ -28,14 +28,21 @@ module Pod
#
attr_reader
:locked_dependencies
# @return [Array<Source>] The list of the sources which will be used for
# the resolution.
#
attr_accessor
:sources
# @param [Sandbox] sandbox @see sandbox
# @param [Podfile] podfile @see podfile
# @param [Array<Dependency>] locked_dependencies @see locked_dependencies
# @param [Array<Source>, Source] sources @see sources
#
def
initialize
(
sandbox
,
podfile
,
locked_dep
endencies
=
[]
)
def
initialize
(
sandbox
,
podfile
,
locked_dep
s
,
sources
)
@sandbox
=
sandbox
@podfile
=
podfile
@locked_dependencies
=
locked_dependencies
@locked_dependencies
=
locked_deps
@sources
=
Array
(
sources
)
end
#-------------------------------------------------------------------------#
...
...
@@ -51,14 +58,15 @@ module Pod
# definition.
#
def
resolve
@cached_sources
=
SourcesManager
.
aggregate
(
true
)
@cached_sets
=
{}
@cached_specs
=
{}
@specs_by_target
=
{}
target_definitions
=
podfile
.
target_definition_list
target_definitions
.
each
do
|
target
|
UI
.
section
"Resolving dependencies for target `
#{
target
.
name
}
' (
#{
target
.
platform
}
)"
do
title
=
"Resolving dependencies for target `
#{
target
.
name
}
' "
\
"(
#{
target
.
platform
}
)"
UI
.
section
(
title
)
do
@loaded_specs
=
[]
find_dependency_specs
(
podfile
,
target
.
dependencies
,
target
)
specs
=
cached_specs
.
values_at
(
*
@loaded_specs
).
sort_by
(
&
:name
)
...
...
@@ -83,14 +91,6 @@ module Pod
# !@ Resolution context
# @return [Source::Aggregate] A cache of the sources needed to find the
# podspecs.
#
# @note The sources are cached because frequently accessed by the
# resolver and loading them requires disk activity.
#
attr_accessor
:cached_sources
# @return [Hash<String => Set>] A cache that keeps tracks of the sets
# loaded by the resolution process.
#
...
...
@@ -168,13 +168,11 @@ module Pod
end
end
#
Loads or returns a previously initialized for the Pod of the given
# dependency.
#
@return [Set] Loads or returns a previously initialized set for the Pod
#
of the given
dependency.
#
# @param [Dependency] dependency
# the dependency for which the set is needed.
#
# @return [Set] the cached set for a given dependency.
# The dependency for which the set is needed.
#
def
find_cached_set
(
dependency
)
name
=
dependency
.
root_name
...
...
@@ -182,24 +180,41 @@ module Pod
if
dependency
.
external_source
spec
=
sandbox
.
specification
(
dependency
.
root_name
)
unless
spec
raise
StandardError
,
"[Bug] Unable to find the specification for `
#{
dependency
}
`."
raise
StandardError
,
"[Bug] Unable to find the specification "
\
"for `
#{
dependency
}
`."
end
set
=
Specification
::
Set
::
External
.
new
(
spec
)
else
set
=
cached_sources
.
search
(
dependency
)
set
=
find_set_from_sources
(
dependency
)
end
cached_sets
[
name
]
=
set
unless
set
raise
Informative
,
"Unable to find a specification for `
#{
dependency
}
`."
raise
Informative
,
"Unable to find a specification "
\
"for `
#{
dependency
}
`."
end
end
cached_sets
[
name
]
end
# @return [Set] Loads a set for the Pod of the given dependency from the
# sources. The set will be limited to the versions of the first
# source which includes the Pod.
#
# @param [Dependency] dependency
# The dependency for which the set is needed.
#
def
find_set_from_sources
(
dependency
)
source
=
sources
.
find
{
|
s
|
s
.
search
(
dependency
)
}
source
.
search
(
dependency
)
end
# Ensures that a specification is compatible with the platform of a target.
#
# @raise If the specification is not supported by the target.
#
# @todo This step is not specific to the resolution process and should be
# performed later in the analysis.
#
# @return [void]
#
def
validate_platform
(
spec
,
target
)
...
...
lib/cocoapods/sources_manager.rb
View file @
6d3821be
...
...
@@ -5,37 +5,44 @@ module Pod
class
<<
self
include
Config
::
Mixin
# @return [Array<Source>] the sources listed by the current Podfile.
# @return [Source::Aggregate] The aggregate of the sources with the given
# Pods.
#
# @param [Array<#to_s>] source_names
# The names of the sources. If not given all the sources will be
# returned.
#
def
podfile_sources
sources
=
[]
self
.
podfile_repos_dirs
.
each
do
|
repo
|
sources
<<
Source
.
new
(
repo
)
def
aggregate
(
source_names
=
nil
)
if
source_names
dirs
=
source_names
.
map
{
|
name
|
source_dir
(
name
)
}
else
dirs
=
config
.
repos_dir
.
children
.
select
(
&
:directory?
)
end
sources
<<
Source
.
new
(
master_repo_dir
)
if
sources
.
empty?
sources
Source
::
Aggregate
.
new
(
dirs
)
end
# @
param [Bool] podfile use podfile sources
# @
return [Array<Source>] The list of the sources with the given names.
#
# @
return [Source::Aggregate] the aggregate of all the sources known to
#
this installation of CocoaPod
s.
# @
param [Array<#to_s>] names
#
The names of the source
s.
#
def
aggregate
(
podfile
=
false
)
if
podfile
repos
=
podfile_repos_dirs
else
repos
=
config
.
repos_dir
.
children
.
select
(
&
:directory?
)
end
Source
::
Aggregate
.
new
(
repos
)
def
sources
(
names
)
dirs
=
names
.
map
{
|
name
|
source_dir
(
name
)
}
dirs
.
map
{
|
repo
|
Source
.
new
(
repo
)
}
end
# @return [Array<Source>]
t
he list of all the sources known to this
# @return [Array<Source>]
T
he list of all the sources known to this
# installation of CocoaPods.
#
def
all
aggregate
.
sources
dirs
=
config
.
repos_dir
.
children
.
select
(
&
:directory?
)
dirs
.
map
{
|
repo
|
Source
.
new
(
repo
)
}
end
# @return [Source] The CocoaPods Master Repo source.
#
def
master
sources
([
'master'
])
end
# @return [Array<Specification::Set>] the list of all the specification
...
...
@@ -347,23 +354,18 @@ module Pod
end
end
# @return [Array<Pathname>] directories of all specified sources in
# Podfile
# @return [Pathname] The path of the source with the given name.
#
def
podfile_repos_dirs
pathnames
=
[]
if
config
.
podfile
config
.
podfile
.
sources
.
each
do
|
source_name
|
pathnames
<<
source_repo_dir
(
source_name
)
end
end
pathnames
end
# @return [Pathname] the directory where a given CocoaPods source is stored.
# @param [String] name
# The name of the source.
#
def
source_repo_dir
(
name
)
config
.
repos_dir
+
name
def
source_dir
(
name
)
dir
=
config
.
repos_dir
+
name
if
dir
dir
else
raise
Informative
,
"Unable to find the `
#{
name
}
` repo."
end
end
end
end
...
...
spec/unit/installer/analyzer_spec.rb
View file @
6d3821be
...
...
@@ -464,33 +464,6 @@ module Pod
e
=
lambda
{
@analyzer
.
send
(
:compute_platform_for_target_definition
,
target_definition
,
user_targets
)
}.
should
.
raise
Informative
e
.
message
.
should
.
match
/Targets with different platforms/
end
end
#--------------------------------------#
describe
"#update_repositories_if_needed"
do
it
"updates the podfile repositories"
do
config
.
skip_repo_update
=
false
def
@podfile
.
sources
[
"netbe"
,
"master"
]
end
SourcesManager
.
expects
(
:update
).
with
(
"netbe"
).
once
SourcesManager
.
expects
(
:update
).
with
(
"master"
).
once
@analyzer
.
send
(
:update_repositories_if_needed
)
end
it
"updates the default repositories"
do
config
.
skip_repo_update
=
false
def
@podfile
.
sources
[]
end
SourcesManager
.
expects
(
:update
).
once
@analyzer
.
send
(
:update_repositories_if_needed
)
end
end
end
end
...
...
spec/unit/resolver_spec.rb
View file @
6d3821be
...
...
@@ -9,7 +9,7 @@ module Pod
pod
'BlocksKit'
,
'1.5.2'
end
locked_deps
=
[
Dependency
.
new
(
'BlocksKit'
,
'1.5.2'
)]
@resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
locked_deps
)
@resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
locked_deps
,
SourcesManager
.
all
)
end
it
'returns the sandbox'
do
...
...
@@ -55,7 +55,7 @@ module Pod
platform
:ios
pod
'Reachability'
,
:podspec
=>
podspec
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
podfile
,
[],
SourcesManager
.
all
)
resolver
.
resolve
specs
=
resolver
.
specs_by_target
.
values
.
flatten
specs
.
map
(
&
:to_s
).
should
==
[
'Reachability (3.0.0)'
]
...
...
@@ -70,7 +70,7 @@ module Pod
platform
:ios
,
'6.0'
pod
'BlocksKit'
,
'1.5.2'
end
@resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
)
@resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
[],
SourcesManager
.
all
)
end
it
'cross resolves dependencies'
do
...
...
@@ -80,7 +80,7 @@ module Pod
pod
'AFQuickLookView'
,
'= 0.1.0'
# requires 'AFNetworking', '>= 0.9.0'
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
[],
SourcesManager
.
all
)
specs
=
resolver
.
resolve
.
values
.
flatten
.
map
(
&
:to_s
).
sort
specs
.
should
==
[
'AFNetworking (0.9.1)'
,
'AFQuickLookView (0.1.0)'
]
end
...
...
@@ -110,7 +110,7 @@ module Pod
platform
:ios
,
'7.0'
pod
'RestKit'
,
'0.10.3'
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
[],
SourcesManager
.
all
)
resolver
.
resolve
.
values
.
flatten
.
map
(
&
:name
).
sort
.
should
==
%w(
FileMD5Hash
ISO8601DateFormatter
...
...
@@ -149,9 +149,11 @@ module Pod
end
end
config
.
sandbox
.
expects
(
:specification
).
with
(
'MainSpec'
).
returns
(
spec
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
[],
SourcesManager
.
all
)
specs
=
resolver
.
resolve
.
values
.
flatten
.
map
(
&
:name
).
sort
specs
.
should
==
%w( MainSpec/FirstSubSpec MainSpec/FirstSubSpec/SecondSubSpec )
specs
.
should
==
%w(
MainSpec/FirstSubSpec MainSpec/FirstSubSpec/SecondSubSpec
)
end
it
"marks a specification's version to be a HEAD version"
do
...
...
@@ -160,7 +162,7 @@ module Pod
pod
'FileMD5Hash'
pod
'JSONKit'
,
:head
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
podfile
,
[],
SourcesManager
.
all
)
filemd5hash
,
jsonkit
=
resolver
.
resolve
.
values
.
first
.
sort_by
(
&
:name
)
filemd5hash
.
version
.
should
.
not
.
be
.
head
jsonkit
.
version
.
should
.
be
.
head
...
...
@@ -174,7 +176,7 @@ module Pod
pod
'JSONKit'
,
'1.4'
pod
'JSONKit'
,
'1.5pre'
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
podfile
,
[],
SourcesManager
.
all
)
e
=
lambda
{
resolver
.
resolve
}.
should
.
raise
Pod
::
Informative
e
.
message
.
should
.
match
(
/Unable to satisfy the following requirements/
)
end
...
...
@@ -184,15 +186,31 @@ module Pod
platform
:ios
pod
'JSONKit'
,
'<= 1.5pre'
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
podfile
,
[],
SourcesManager
.
all
)
version
=
resolver
.
resolve
.
values
.
flatten
.
first
.
version
version
.
to_s
.
should
==
'1.5pre'
locked_deps
=
[
Dependency
.
new
(
'JSONKit'
,
'= 1.4'
)]
resolver
=
Resolver
.
new
(
config
.
sandbox
,
podfile
,
locked_deps
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
podfile
,
locked_deps
,
SourcesManager
.
all
)
version
=
resolver
.
resolve
.
values
.
flatten
.
first
.
version
version
.
to_s
.
should
==
'1.4'
end
it
'takes into account the order of the sources'
do
podfile
=
Podfile
.
new
do
platform
:ios
pod
'JSONKit'
end
sources
=
SourcesManager
.
sources
([
'master'
,
'test_repo'
])
resolver
=
Resolver
.
new
(
config
.
sandbox
,
podfile
,
[],
sources
)
version
=
resolver
.
resolve
.
values
.
flatten
.
first
.
version
version
.
to_s
.
should
.
not
==
"999.999.999"
sources
=
SourcesManager
.
sources
([
'test_repo'
,
'master'
])
resolver
=
Resolver
.
new
(
config
.
sandbox
,
podfile
,
[],
sources
)
version
=
resolver
.
resolve
.
values
.
flatten
.
first
.
version
version
.
to_s
.
should
==
"999.999.999"
end
end
#-------------------------------------------------------------------------#
...
...
@@ -205,7 +223,7 @@ module Pod
pod
'AFNetworking'
,
'1.0RC3'
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
[],
SourcesManager
.
all
)
specs
=
resolver
.
resolve
.
values
.
flatten
.
map
(
&
:to_s
).
sort
specs
.
should
==
[
'AFNetworking (1.0RC3)'
]
end
...
...
@@ -216,7 +234,7 @@ module Pod
pod
'AFNetworking'
,
'~> 1.0RC3'
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
[],
SourcesManager
.
all
)
specs
=
resolver
.
resolve
.
values
.
flatten
.
map
(
&
:to_s
).
sort
specs
.
should
!=
[
'AFNetworking (1.0RC3)'
]
specs
.
should
==
[
'AFNetworking (1.2.0)'
]
...
...
@@ -228,7 +246,7 @@ module Pod
pod
'AFNetworking'
,
'1.0'
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
[],
SourcesManager
.
all
)
specs
=
resolver
.
resolve
.
values
.
flatten
.
map
(
&
:to_s
).
sort
specs
.
should
!=
[
'AFNetworking (1.0RC3)'
]
specs
.
should
==
[
'AFNetworking (1.0)'
]
...
...
@@ -240,7 +258,7 @@ module Pod
pod
'AFNetworking'
,
'< 1.0'
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
[],
SourcesManager
.
all
)
specs
=
resolver
.
resolve
.
values
.
flatten
.
map
(
&
:to_s
).
sort
specs
.
should
!=
[
'AFNetworking (1.0RC3)'
]
specs
.
should
==
[
'AFNetworking (0.10.1)'
]
...
...
@@ -252,7 +270,7 @@ module Pod
pod
'AFNetworking'
,
'<= 1.0'
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
[],
SourcesManager
.
all
)
specs
=
resolver
.
resolve
.
values
.
flatten
.
map
(
&
:to_s
).
sort
specs
.
should
!=
[
'AFNetworking (1.0RC3)'
]
specs
.
should
==
[
'AFNetworking (1.0)'
]
...
...
@@ -264,7 +282,7 @@ module Pod
pod
'AFNetworking'
,
'> 1.0'
,
'< 1.3'
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
[],
SourcesManager
.
all
)
specs
=
resolver
.
resolve
.
values
.
flatten
.
map
(
&
:to_s
).
sort
specs
.
should
!=
[
'AFNetworking (1.0RC3)'
]
specs
.
should
==
[
'AFNetworking (1.2.1)'
]
...
...
@@ -276,7 +294,7 @@ module Pod
pod
'AFNetworking'
,
'>= 1.0'
,
'< 1.3'
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
[],
SourcesManager
.
all
)
specs
=
resolver
.
resolve
.
values
.
flatten
.
map
(
&
:to_s
).
sort
specs
.
should
!=
[
'AFNetworking (1.0RC3)'
]
specs
.
should
==
[
'AFNetworking (1.2.1)'
]
...
...
@@ -288,7 +306,7 @@ module Pod
pod
'AFNetworking'
,
'~> 1.0'
,
'< 1.3'
end
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
)
resolver
=
Resolver
.
new
(
config
.
sandbox
,
@podfile
,
[],
SourcesManager
.
all
)
specs
=
resolver
.
resolve
.
values
.
flatten
.
map
(
&
:to_s
).
sort
specs
.
should
!=
[
'AFNetworking (1.0RC3)'
]
specs
.
should
==
[
'AFNetworking (1.2.1)'
]
...
...
spec/unit/sources_manager_spec.rb
View file @
6d3821be
...
...
@@ -105,22 +105,6 @@ module Pod
path
=
SourcesManager
.
search_index_path
.
to_s
path
.
should
.
match
%r[Library/Caches/CocoaPods/search_index.yaml]
end
it
"returns the sources from podfile"
do
@podfile
=
Podfile
.
new
do
platform
:ios
source
'netbe'
source
'cocoapods'
end
SourcesManager
.
config
.
stubs
(
:podfile
).
returns
(
@podfile
)
sources
=
SourcesManager
.
podfile_sources
sources
.
map
(
&
:name
).
should
==
%w[netbe cocoapods]
end
it
"returns cocoapods source if none specified"
do
sources
=
SourcesManager
.
podfile_sources
sources
.
map
(
&
:name
).
should
==
%w[master]
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