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
50250b16
Commit
50250b16
authored
Aug 22, 2014
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Installer] Implement migrator
parent
de011ef4
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
153 additions
and
109 deletions
+153
-109
installer.rb
lib/cocoapods/installer.rb
+5
-5
migrator.rb
lib/cocoapods/installer/migrator.rb
+77
-71
target_integrator.rb
...ds/installer/user_project_integrator/target_integrator.rb
+2
-2
xcconfig_integrator.rb
...oject_integrator/target_integrator/xcconfig_integrator.rb
+12
-6
sandbox.rb
lib/cocoapods/sandbox.rb
+24
-15
abstract_external_source_spec.rb
spec/unit/external_sources/abstract_external_source_spec.rb
+2
-1
downloader_source_spec.rb
spec/unit/external_sources/downloader_source_spec.rb
+1
-1
path_source_spec.rb
spec/unit/external_sources/path_source_spec.rb
+2
-2
podspec_source_spec.rb
spec/unit/external_sources/podspec_source_spec.rb
+1
-1
migrator_spec.rb
spec/unit/installer/migrator_spec.rb
+22
-0
aggregate_target_installer_spec.rb
...aller/target_installer/aggregate_target_installer_spec.rb
+1
-0
pod_target_installer_spec.rb
...t/installer/target_installer/pod_target_installer_spec.rb
+1
-0
xcconfig_integrator_spec.rb
..._integrator/target_integrator/xcconfig_integrator_spec.rb
+0
-2
sandbox_spec.rb
spec/unit/sandbox_spec.rb
+3
-3
No files found.
lib/cocoapods/installer.rb
View file @
50250b16
...
...
@@ -87,7 +87,7 @@ module Pod
# @return [void]
#
def
install!
migrate_installation_if_needed
prepare
resolve_dependencies
download_dependencies
generate_pods_project
...
...
@@ -95,10 +95,10 @@ module Pod
perform_post_install_actions
end
def
migrate_installation_if_needed
UI
.
section
"P
erforming existing installation migration
"
do
migrator
=
Migrator
.
new
(
sandbox
)
migrator
.
migrate!
def
prepare
UI
.
section
"P
reparing
"
do
sandbox
.
prepare
Migrator
.
migrate
(
sandbox
)
end
end
...
...
lib/cocoapods/installer/migrator.rb
View file @
50250b16
require
'fileutils'
module
Pod
class
Installer
# Migrates installations performed by previous versions of CocoaPods.
#
class
Migrator
#
#
attr_reader
:installation_version
#
#
attr_reader
:sandbox
#
#
def
initialize
(
sandbox
)
@sandbox
=
sandbox
end
#
#
def
migrate!
if
sandbox
.
manifest
migrate_to_0_20
if
version_minor
(
'0.20'
)
class
<<
self
# Performs the migration.
#
# @param [Sandbox] The sandbox which should be migrated.
#
def
migrate
(
sandbox
)
if
sandbox
.
manifest
migrate_to_0_34
(
sandbox
)
if
installation_minor?
(
'0.34'
,
sandbox
)
end
end
end
#-----------------------------------------------------------------------#
private
# @!group Migration Steps
# TODO: Fix copy resources script
# TODO: Fix manifest check
# TODO: Fix xcconfig
# TODO: Group target support files
#
def
migrate_to_0_20
title_options
=
{
:verbose_prefix
=>
"-> "
.
green
}
UI
.
titled_section
(
"Migrating to CocoaPods 0.20"
.
green
,
title_options
)
do
mkdir
(
sandbox
.
generated_dir_root
)
mkdir
(
sandbox
.
headers_root
)
mkdir
(
sandbox
.
sources_root
)
sandbox
.
root
.
children
.
each
do
|
child
|
relative
=
child
.
relative_path_from
(
sandbox
.
root
)
case
relative
.
to_s
when
'Generated'
next
when
'BuildHeaders'
,
'Headers'
move
(
child
,
sandbox
.
headers_root
+
relative
)
else
if
child
.
directory?
&&
child
.
extname
!=
'.xcodeproj'
move
(
child
,
sandbox
.
sources_root
+
relative
)
# @!group Migration Steps
# Migrates from CocoaPods versions previous to 0.34.
#
def
migrate_to_0_34
(
sandbox
)
title_options
=
{
:verbose_prefix
=>
"-> "
.
green
}
UI
.
titled_section
(
"Migrating to CocoaPods 0.34"
.
green
,
title_options
)
do
delete
(
sandbox
.
root
+
'Headers'
)
make_path
(
sandbox
.
headers_root
)
sandbox
.
root
.
children
.
each
do
|
child
|
relative
=
child
.
relative_path_from
(
sandbox
.
root
)
case
relative
.
to_s
when
'Manifest.lock'
,
'Pods.xcodeproj'
,
'Sources'
,
'Headers'
,
'Target Support Files'
,
'Local Podspecs'
next
when
'BuildHeaders'
,
'PublicHeaders'
delete
(
child
)
else
move
(
child
,
sandbox
.
generated_dir_root
+
relative
)
if
child
.
directory?
&&
child
.
extname
!=
'.xcodeproj'
move
(
child
,
sandbox
.
sources_root
+
relative
)
else
delete
(
child
)
end
end
end
end
end
end
#-----------------------------------------------------------------------#
# @!group Private helpers
private
# @!group Private helpers
def
version_minor
(
target_version
)
installation_version
<
Version
.
new
(
target_version
)
end
def
installation_minor?
(
target_version
,
sandbox
)
sandbox
.
manifest
.
cocoapods_version
<
Version
.
new
(
target_version
)
end
def
installation_version
sandbox
.
manifest
.
cocoapods_version
end
# Makes a path creating any intermediate directory and printing an UI
# message.
#
# @path [#to_s] path
# The path.
#
def
make_path
(
path
)
return
if
path
.
exist?
UI
.
message
"- Making path
#{
UI
.
path
(
path
)
}
"
do
path
.
mkpath
end
end
def
mkdir
(
path
)
path
.
mkpath
end
# Moves a path to another one printing an UI message.
#
# @path [#to_s] source
# The path to move.
#
# @path [#to_s] destination
# The destination path.
#
def
move
(
source
,
destination
)
return
unless
source
.
exist?
make_path
(
destination
.
dirname
)
UI
.
message
"- Moving
#{
UI
.
path
(
source
)
}
to
#{
UI
.
path
(
destination
)
}
"
do
FileUtils
.
mv
(
source
.
to_s
,
destination
.
to_s
)
end
end
def
move
(
path
,
new_name
)
path
.
rename
(
new_name
)
# Deletes a path, including non empty directories, printing an UI
# message.
#
# @path [#to_s] path
# The path.
#
def
delete
(
path
)
return
unless
path
.
exist?
UI
.
message
"- Deleting
#{
UI
.
path
(
path
)
}
"
do
FileUtils
.
rm_rf
(
path
)
end
end
end
#-----------------------------------------------------------------------#
end
end
end
lib/cocoapods/installer/user_project_integrator/target_integrator.rb
View file @
50250b16
...
...
@@ -77,8 +77,8 @@ module Pod
native_targets_to_integrate
.
each
do
|
native_target
|
phase
=
native_target
.
shell_script_build_phases
.
select
{
|
bp
|
bp
.
name
==
phase_name
}.
first
||
native_target
.
new_shell_script_build_phase
(
phase_name
)
path
=
target
.
copy_resources_script_relative_path
phase
.
shell_script
=
%(
"#{path}"\n
)
script_
path
=
target
.
copy_resources_script_relative_path
phase
.
shell_script
=
%(
"#{script_path}"\n
)
phase
.
show_env_vars_in_log
=
'0'
end
end
...
...
lib/cocoapods/installer/user_project_integrator/target_integrator/xcconfig_integrator.rb
View file @
50250b16
...
...
@@ -41,14 +41,20 @@ module Pod
# @todo This can be removed for CocoaPods 1.0
#
def
self
.
update_from_cocoapods_0_33_1
(
pod_bundle
,
targets
)
sandbox
=
pod_bundle
.
sandbox
targets
.
map
(
&
:project
).
uniq
.
each
do
|
project
|
path
=
pod_bundle
.
xcconfig_relative_path
(
nil
)
file_ref
=
project
.
files
.
find
{
|
f
|
f
.
path
==
path
}
if
file_ref
UI
.
message
"- Removing (
#{
path
}
)"
do
file_refs
=
project
.
files
.
select
do
|
file_ref
|
path
=
file_ref
.
path
.
to_s
if
File
.
extname
(
path
)
==
'.xcconfig'
absolute_path
=
file_ref
.
real_path
.
to_s
absolute_path
.
start_with?
(
sandbox
.
root
.
to_s
)
&&
!
absolute_path
.
start_with?
(
sandbox
.
target_support_files_root
.
to_s
)
end
end
file_refs
.
uniq
.
each
do
|
file_ref
|
UI
.
message
"- Removing (
#{
file_ref
.
path
}
)"
do
file_ref
.
remove_from_project
absolute_path
=
pod_bundle
.
xcconfig_path
File
.
delete
(
absolute_path
)
if
File
.
exist?
(
absolute_path
)
end
end
end
...
...
lib/cocoapods/sandbox.rb
View file @
50250b16
...
...
@@ -60,9 +60,6 @@ module Pod
@checkout_sources
=
{}
@development_pods
=
{}
@pods_with_absolute_path
=
[]
FileUtils
.
mkdir_p
(
headers_root
)
FileUtils
.
mkdir_p
(
sources_root
)
FileUtils
.
mkdir_p
(
target_support_files_root
)
end
# @return [Lockfile] the manifest which contains the information about the
...
...
@@ -90,6 +87,19 @@ module Pod
podspe_path
.
rmtree
if
podspe_path
end
# Prepares the sandbox for a new installation removing any file that will
# be regenerated and ensuring that the directories exists.
#
def
prepare
FileUtils
.
rm_rf
(
headers_root
)
FileUtils
.
rm_rf
(
target_support_files_root
)
FileUtils
.
mkdir_p
(
headers_root
)
FileUtils
.
mkdir_p
(
sources_root
)
FileUtils
.
mkdir_p
(
specifications_root
)
FileUtils
.
mkdir_p
(
target_support_files_root
)
end
# @return [String] a string representation suitable for debugging.
#
def
inspect
...
...
@@ -166,6 +176,13 @@ module Pod
root
+
'Sources'
end
# @return [Pathname] the path for the directory where to store the
# specifications.
#
def
specifications_root
root
+
"Local Podspecs"
end
# @return [Pathname] The directory where to store the files generated by
# CocoaPods to support the umbrella targets.
#
...
...
@@ -193,15 +210,7 @@ module Pod
end
end
# @return [Pathname] the path for the directory where to store the
# specifications.
#
# @todo Migrate old installations and store the for all the pods.
# Two folders should be created `External Sources` and `Podspecs`.
#
def
specifications_dir
(
_external_source
=
false
)
root
+
"Local Podspecs"
end
# Returns the path of the specification for the Pod with the
# given name, if one is stored.
...
...
@@ -213,11 +222,11 @@ module Pod
# @return [Nil] if the podspec is not stored.
#
def
specification_path
(
name
)
path
=
specifications_
dir
+
"
#{
name
}
.podspec"
path
=
specifications_
root
+
"
#{
name
}
.podspec"
if
path
.
exist?
path
else
path
=
specifications_
dir
+
"
#{
name
}
.podspec.json"
path
=
specifications_
root
+
"
#{
name
}
.podspec.json"
if
path
.
exist?
path
else
...
...
@@ -240,7 +249,7 @@ module Pod
#
def
store_podspec
(
name
,
podspec
,
external_source
=
false
,
json
=
false
)
file_name
=
json
?
"
#{
name
}
.podspec.json"
:
"
#{
name
}
.podspec"
output_path
=
specifications_
dir
(
external_source
)
+
file_name
output_path
=
specifications_
root
+
file_name
output_path
.
dirname
.
mkpath
if
podspec
.
is_a?
(
String
)
output_path
.
open
(
'w'
)
{
|
f
|
f
.
puts
(
podspec
)
}
...
...
spec/unit/external_sources/abstract_external_source_spec.rb
View file @
50250b16
...
...
@@ -6,6 +6,7 @@ module Pod
before
do
dependency
=
Dependency
.
new
(
'Reachability'
,
:git
=>
fixture
(
'integration/Reachability'
))
@subject
=
ExternalSources
.
from_dependency
(
dependency
,
nil
)
config
.
sandbox
.
prepare
end
#--------------------------------------#
...
...
@@ -36,7 +37,7 @@ module Pod
it
'pre-downloads the Pod and stores the relevant information in the sandbox'
do
@subject
.
send
(
:pre_download
,
config
.
sandbox
)
path
=
config
.
sandbox
.
specifications_
dir
+
'Reachability.podspec'
path
=
config
.
sandbox
.
specifications_
root
+
'Reachability.podspec'
path
.
should
.
exist?
config
.
sandbox
.
predownloaded_pods
.
should
==
[
'Reachability'
]
config
.
sandbox
.
checkout_sources
.
should
==
{
...
...
spec/unit/external_sources/downloader_source_spec.rb
View file @
50250b16
...
...
@@ -13,7 +13,7 @@ module Pod
it
'creates a copy of the podspec'
do
@subject
.
fetch
(
config
.
sandbox
)
path
=
config
.
sandbox
.
specifications_
dir
+
'Reachability.podspec'
path
=
config
.
sandbox
.
specifications_
root
+
'Reachability.podspec'
path
.
should
.
exist?
end
...
...
spec/unit/external_sources/path_source_spec.rb
View file @
50250b16
...
...
@@ -12,7 +12,7 @@ module Pod
it
"creates a copy of the podspec"
do
@subject
.
fetch
(
config
.
sandbox
)
path
=
config
.
sandbox
.
specifications_
dir
+
'Reachability.podspec'
path
=
config
.
sandbox
.
specifications_
root
+
'Reachability.podspec'
path
.
should
.
exist?
end
...
...
@@ -22,7 +22,7 @@ module Pod
podfile_path
=
fixture
(
'integration/Podfile'
)
@subject
=
ExternalSources
.
from_dependency
(
dependency
,
podfile_path
)
@subject
.
fetch
(
config
.
sandbox
)
path
=
config
.
sandbox
.
specifications_
dir
+
'Reachability.podspec'
path
=
config
.
sandbox
.
specifications_
root
+
'Reachability.podspec'
path
.
should
.
exist?
end
...
...
spec/unit/external_sources/podspec_source_spec.rb
View file @
50250b16
...
...
@@ -12,7 +12,7 @@ module Pod
it
"creates a copy of the podspec"
do
@subject
.
fetch
(
config
.
sandbox
)
path
=
config
.
sandbox
.
specifications_
dir
+
'Reachability.podspec'
path
=
config
.
sandbox
.
specifications_
root
+
'Reachability.podspec'
path
.
should
.
exist?
end
...
...
spec/unit/installer/migrator_spec.rb
0 → 100644
View file @
50250b16
require
File
.
expand_path
(
'../../../spec_helper'
,
__FILE__
)
module
Pod
describe
Installer
::
Migrator
do
it
'performs a migration'
do
manifest
=
stub
(
:cocoapods_version
=>
Version
.
new
(
'0.32'
))
config
.
sandbox
.
stubs
(
:manifest
).
returns
(
manifest
)
old_path
=
config
.
sandbox
.
root
+
'ARAnalytics'
old_path
.
mkdir
Installer
::
Migrator
.
migrate
(
config
.
sandbox
)
old_path
.
should
.
not
.
exist?
(
config
.
sandbox
.
sources_root
+
'ARAnalytics'
).
should
.
exist?
end
it
"doesn't perform migrations if they are not needed"
do
manifest
=
stub
(
:cocoapods_version
=>
Version
.
new
(
'999'
))
config
.
sandbox
.
stubs
(
:manifest
).
returns
(
manifest
)
Installer
::
Migrator
.
expects
(
:migrate_to_0_34
).
never
Installer
::
Migrator
.
migrate
(
config
.
sandbox
)
end
end
end
spec/unit/installer/target_installer/aggregate_target_installer_spec.rb
View file @
50250b16
...
...
@@ -4,6 +4,7 @@ module Pod
describe
Installer
::
AggregateTargetInstaller
do
describe
'In General'
do
before
do
config
.
sandbox
.
prepare
@podfile
=
Podfile
.
new
do
platform
:ios
xcodeproj
'dummy'
...
...
spec/unit/installer/target_installer/pod_target_installer_spec.rb
View file @
50250b16
...
...
@@ -4,6 +4,7 @@ module Pod
describe
Installer
::
PodTargetInstaller
do
describe
'In General'
do
before
do
config
.
sandbox
.
prepare
@podfile
=
Podfile
.
new
do
platform
:ios
xcodeproj
'dummy'
...
...
spec/unit/installer/user_project_integrator/target_integrator/xcconfig_integrator_spec.rb
View file @
50250b16
...
...
@@ -28,8 +28,6 @@ module Pod
file_ref
=
@project
.
new_file
(
path
)
config
=
@target
.
build_configuration_list
[
'Release'
]
config
.
base_configuration_reference
=
file_ref
File
.
expects
(
:exist?
).
returns
(
true
)
File
.
expects
(
:delete
).
with
(
path
)
XCConfigIntegrator
.
integrate
(
@pod_bundle
,
[
@target
])
@project
.
files
.
find
{
|
f
|
f
.
path
==
path
}.
should
.
be
.
nil
end
...
...
spec/unit/sandbox_spec.rb
View file @
50250b16
...
...
@@ -94,8 +94,8 @@ module Pod
describe
'Specification store'
do
it
'loads the stored specification with the given name'
do
(
@sandbox
.
specifications_
dir
).
mkdir
FileUtils
.
cp
(
fixture
(
'banana-lib/BananaLib.podspec'
),
@sandbox
.
specifications_
dir
)
(
@sandbox
.
specifications_
root
).
mkdir
FileUtils
.
cp
(
fixture
(
'banana-lib/BananaLib.podspec'
),
@sandbox
.
specifications_
root
)
@sandbox
.
specification
(
'BananaLib'
).
name
.
should
==
'BananaLib'
end
...
...
@@ -112,7 +112,7 @@ module Pod
end
it
'returns the directory where to store the specifications'
do
@sandbox
.
specifications_
dir
.
should
==
temporary_directory
+
'Sandbox/Local Podspecs'
@sandbox
.
specifications_
root
.
should
==
temporary_directory
+
'Sandbox/Local Podspecs'
end
it
"returns the path to a spec file in the 'Local Podspecs' dir"
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