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
07fad458
Commit
07fad458
authored
Mar 26, 2012
by
Eloy Duran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Pod::Project::Integrator for upcoming work.
parent
23692ea0
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
126 additions
and
108 deletions
+126
-108
cocoapods.rb
lib/cocoapods.rb
+0
-1
install.rb
lib/cocoapods/command/install.rb
+1
-4
installer.rb
lib/cocoapods/installer.rb
+4
-2
project.rb
lib/cocoapods/project.rb
+2
-0
integrator.rb
lib/cocoapods/project/integrator.rb
+81
-0
project_integration.rb
lib/cocoapods/project_integration.rb
+0
-90
integrator_spec.rb
spec/functional/project/integrator_spec.rb
+34
-3
integration_spec.rb
spec/integration_spec.rb
+2
-4
fixture.rb
spec/spec_helper/fixture.rb
+2
-4
No files found.
lib/cocoapods.rb
View file @
07fad458
...
@@ -16,7 +16,6 @@ module Pod
...
@@ -16,7 +16,6 @@ module Pod
autoload
:Platform
,
'cocoapods/platform'
autoload
:Platform
,
'cocoapods/platform'
autoload
:Podfile
,
'cocoapods/podfile'
autoload
:Podfile
,
'cocoapods/podfile'
autoload
:Project
,
'cocoapods/project'
autoload
:Project
,
'cocoapods/project'
autoload
:ProjectIntegration
,
'cocoapods/project_integration'
autoload
:Resolver
,
'cocoapods/resolver'
autoload
:Resolver
,
'cocoapods/resolver'
autoload
:Sandbox
,
'cocoapods/sandbox'
autoload
:Sandbox
,
'cocoapods/sandbox'
autoload
:Source
,
'cocoapods/source'
autoload
:Source
,
'cocoapods/source'
...
...
lib/cocoapods/command/install.rb
View file @
07fad458
...
@@ -41,10 +41,7 @@ module Pod
...
@@ -41,10 +41,7 @@ module Pod
if
@update_repo
if
@update_repo
Repo
.
new
(
ARGV
.
new
([
"update"
])).
run
Repo
.
new
(
ARGV
.
new
([
"update"
])).
run
end
end
installer
=
Installer
.
new
(
podfile
)
Installer
.
new
(
podfile
,
@projpath
).
install!
installer
.
install!
ProjectIntegration
.
integrate_with_project
(
@projpath
)
if
@projpath
end
end
end
end
end
end
...
...
lib/cocoapods/installer.rb
View file @
07fad458
...
@@ -6,8 +6,8 @@ module Pod
...
@@ -6,8 +6,8 @@ module Pod
attr_reader
:sandbox
attr_reader
:sandbox
def
initialize
(
podfile
)
def
initialize
(
podfile
,
user_project_path
=
nil
)
@podfile
=
podfile
@podfile
,
@user_project_path
=
podfile
,
user_project_path
# FIXME: pass this into the installer as a parameter
# FIXME: pass this into the installer as a parameter
@sandbox
=
Sandbox
.
new
(
config
.
project_pods_root
)
@sandbox
=
Sandbox
.
new
(
config
.
project_pods_root
)
@resolver
=
Resolver
.
new
(
@podfile
,
@sandbox
)
@resolver
=
Resolver
.
new
(
@podfile
,
@sandbox
)
...
@@ -87,6 +87,8 @@ module Pod
...
@@ -87,6 +87,8 @@ module Pod
puts
"* Writing Xcode project file to `
#{
@sandbox
.
project_path
}
'"
if
config
.
verbose?
puts
"* Writing Xcode project file to `
#{
@sandbox
.
project_path
}
'"
if
config
.
verbose?
project
.
save_as
(
@sandbox
.
project_path
)
project
.
save_as
(
@sandbox
.
project_path
)
Project
::
Integrator
.
new
(
@user_project_path
).
integrate!
if
@user_project_path
end
end
def
run_post_install_hooks
def
run_post_install_hooks
...
...
lib/cocoapods/project.rb
View file @
07fad458
...
@@ -12,6 +12,8 @@ end
...
@@ -12,6 +12,8 @@ end
module
Pod
module
Pod
class
Project
<
Xcodeproj
::
Project
class
Project
<
Xcodeproj
::
Project
autoload
:Integrator
,
'cocoapods/project/integrator'
# Shortcut access to the `Pods' PBXGroup.
# Shortcut access to the `Pods' PBXGroup.
def
pods
def
pods
groups
.
find
{
|
g
|
g
.
name
==
'Pods'
}
||
groups
.
new
({
'name'
=>
'Pods'
})
groups
.
find
{
|
g
|
g
.
name
==
'Pods'
}
||
groups
.
new
({
'name'
=>
'Pods'
})
...
...
lib/cocoapods/project/integrator.rb
0 → 100644
View file @
07fad458
require
'xcodeproj/workspace'
require
'xcodeproj/project'
module
Pod
class
Project
class
Integrator
include
Pod
::
Config
::
Mixin
attr_reader
:user_project_path
,
:user_project
def
initialize
(
user_project_path
)
@user_project_path
=
user_project_path
@user_project
=
Xcodeproj
::
Project
.
new
(
user_project_path
)
end
def
integrate!
create_workspace!
return
if
project_already_integrated?
base_user_project_configurations_on_xcconfig
add_pods_library_to_each_target
add_copy_resources_script_phase_to_each_target
@user_project
.
save_as
(
user_project_path
)
unless
config
.
silent?
# TODO this really shouldn't be here
puts
"[!] From now on use `
#{
xcworkspace_path
.
basename
}
' instead of `
#{
user_project_path
.
basename
}
'."
end
end
def
workspace_path
config
.
project_root
+
"
#{
user_project_path
.
basename
(
'.xcodeproj'
)
}
.xcworkspace"
end
def
pods_project_path
config
.
project_root
+
"Pods/Pods.xcodeproj"
end
def
create_workspace!
workspace
=
Xcodeproj
::
Workspace
.
new_from_xcworkspace
(
workspace_path
)
[
user_project_path
,
pods_project_path
].
each
do
|
project_path
|
project_path
=
project_path
.
relative_path_from
(
config
.
project_root
).
to_s
workspace
<<
project_path
unless
workspace
.
include?
(
project_path
)
end
workspace
.
save_as
(
workspace_path
)
end
def
project_already_integrated?
@user_project
.
files
.
find
{
|
file
|
file
.
path
=~
/libPods\.a$/
}
end
def
base_user_project_configurations_on_xcconfig
xcconfig
=
@user_project
.
files
.
new
(
'path'
=>
'Pods/Pods.xcconfig'
)
user_project
.
targets
.
each
do
|
target
|
target
.
build_configurations
.
each
do
|
config
|
config
.
base_configuration
=
xcconfig
end
end
end
def
add_pods_library_to_each_target
pods_library
=
@user_project
.
group
(
"Frameworks"
).
files
.
new_static_library
(
'Pods'
)
@user_project
.
targets
.
each
do
|
target
|
target
.
frameworks_build_phases
.
each
do
|
build_phase
|
build_phase
.
files
<<
pods_library
.
build_files
.
new
end
end
end
def
add_copy_resources_script_phase_to_each_target
@user_project
.
targets
.
each
do
|
target
|
phase
=
target
.
shell_script_build_phases
.
new
phase
.
name
=
'Copy Pods Resources'
phase
.
shell_script
=
%{"${SRCROOT}/Pods/Pods-resources.sh"\n}
end
end
end
end
end
lib/cocoapods/project_integration.rb
deleted
100644 → 0
View file @
23692ea0
require
'xcodeproj/workspace'
require
'xcodeproj/project'
module
Pod
class
ProjectIntegration
extend
Pod
::
Config
::
Mixin
# For now this assumes just one pods target, i.e. only libPods.a.
# Not sure yet if we should try to be smart with apps that have multiple
# targets and try to map pod targets to those app targets.
#
# Possible options are:
# 1. Only cater to the most simple setup
# 2. Try to automagically figure it out by name. For example, a pod target
# called `:some_target' could map to an app target called `SomeTarget'.
# (A variation would be to not even camelize the target name, but simply
# let the user specify it with the proper case.)
# 3. Let the user specify the app target name as an extra argument, but this
# seems to be a less good version of the variation on #2.
class
<<
self
def
integrate_with_project
(
projpath
)
root
=
File
.
dirname
(
projpath
)
name
=
File
.
basename
(
projpath
,
'.xcodeproj'
)
xcworkspace
=
create_workspace
(
root
,
name
,
projpath
)
app_project
=
Xcodeproj
::
Project
.
new
(
projpath
)
return
if
project_already_integrated?
(
app_project
)
xcconfig
=
app_project
.
files
.
new
(
'path'
=>
'Pods/Pods.xcconfig'
)
base_project_configurations_on_xcconfig
(
app_project
,
xcconfig
)
libfile
=
app_project
.
files
.
new_static_library
(
'Pods'
)
libfile
.
group
=
app_project
.
group
(
"Frameworks"
)
add_pods_library_to_each_target_in_project
(
app_project
,
libfile
)
copy_resources
=
app_project
.
add_shell_script_build_phase
(
'Copy Pods Resources'
,
%{"${SRCROOT}/Pods/Pods-resources.sh"\n}
)
add_copy_resources_script_phase_to_each_target_in_project
(
app_project
,
copy_resources
)
app_project
.
save_as
(
projpath
)
unless
config
.
silent?
# TODO this really shouldn't be here
puts
"[!] From now on use `
#{
File
.
basename
(
xcworkspace
)
}
' instead of `
#{
File
.
basename
(
projpath
)
}
'."
end
end
def
create_workspace
(
in_directory
,
name
,
project_path
)
workspace_path
=
File
.
join
(
in_directory
,
name
+
'.xcworkspace'
)
workspace
=
Xcodeproj
::
Workspace
.
new_from_xcworkspace
(
workspace_path
)
pods_project_path
=
File
.
join
(
config
.
project_pods_root
,
'Pods.xcodeproj'
)
root
=
Pathname
.
new
(
in_directory
).
expand_path
[
project_path
,
pods_project_path
].
each
do
|
path
|
path
=
Pathname
.
new
(
path
).
expand_path
.
relative_path_from
(
root
).
to_s
workspace
<<
path
unless
workspace
.
include?
(
path
)
end
workspace
.
save_as
(
workspace_path
)
workspace_path
end
def
project_already_integrated?
(
project
)
project
.
files
.
find
{
|
file
|
file
.
path
=~
/libPods\.a$/
}
end
def
base_project_configurations_on_xcconfig
(
project
,
xcconfig_file
)
project
.
targets
.
each
do
|
target
|
target
.
build_configurations
.
each
do
|
config
|
config
.
base_configuration
=
xcconfig_file
end
end
end
def
add_pods_library_to_each_target_in_project
(
project
,
pods_library
)
project
.
targets
.
each
do
|
target
|
target
.
frameworks_build_phases
.
each
do
|
build_phase
|
build_phase
.
files
<<
pods_library
.
build_files
.
new
end
end
end
def
add_copy_resources_script_phase_to_each_target_in_project
(
project
,
copy_resources_script_phase
)
project
.
targets
.
each
{
|
target
|
target
.
build_phases
<<
copy_resources_script_phase
}
end
end
end
end
spec/functional/project
_integration
_spec.rb
→
spec/functional/project
/integrator
_spec.rb
View file @
07fad458
require
File
.
expand_path
(
'../../spec_helper'
,
__FILE__
)
require
File
.
expand_path
(
'../../../spec_helper'
,
__FILE__
)
describe
Pod
::
Project
::
Integrator
,
'TODO UNIT SPECS!'
do
extend
SpecHelper
::
TemporaryDirectory
before
do
@sample_project_path
=
SpecHelper
.
create_sample_app_copy_from_fixture
(
'SampleProject'
)
config
.
project_root
=
@sample_project_path
.
dirname
@integrator
=
Pod
::
Project
::
Integrator
.
new
(
@sample_project_path
)
@sample_project
=
Xcodeproj
::
Project
.
new
(
@sample_project_path
)
end
after
do
config
.
project_root
=
nil
end
it
"returns the path to the workspace in the project's root"
do
@integrator
.
workspace_path
.
should
==
config
.
project_root
+
'SampleProject.xcworkspace'
end
it
"returns the path to the Pods.xcodeproj document"
do
@integrator
.
pods_project_path
.
should
==
config
.
project_root
+
'Pods/Pods.xcodeproj'
end
end
describe
Pod
::
Project
::
Integrator
do
extend
SpecHelper
::
TemporaryDirectory
describe
Pod
::
ProjectIntegration
do
before
do
before
do
@sample_project_path
=
SpecHelper
.
create_sample_app_copy_from_fixture
(
'SampleProject'
)
@sample_project_path
=
SpecHelper
.
create_sample_app_copy_from_fixture
(
'SampleProject'
)
Pod
::
ProjectIntegration
.
integrate_with_project
(
@sample_project_path
)
config
.
project_root
=
@sample_project_path
.
dirname
@integrator
=
Pod
::
Project
::
Integrator
.
new
(
@sample_project_path
)
@integrator
.
integrate!
@sample_project
=
Xcodeproj
::
Project
.
new
(
@sample_project_path
)
@sample_project
=
Xcodeproj
::
Project
.
new
(
@sample_project_path
)
end
end
after
do
config
.
project_root
=
nil
end
it
'creates a workspace with a name matching the project'
do
it
'creates a workspace with a name matching the project'
do
workspace_path
=
@sample_project_path
.
dirname
+
"SampleProject.xcworkspace"
workspace_path
=
@sample_project_path
.
dirname
+
"SampleProject.xcworkspace"
workspace_path
.
should
.
exist
workspace_path
.
should
.
exist
...
...
spec/integration_spec.rb
View file @
07fad458
...
@@ -363,12 +363,10 @@ else
...
@@ -363,12 +363,10 @@ else
self
.
platform
platform
self
.
platform
platform
dependency
'SSZipArchive'
dependency
'SSZipArchive'
end
end
installer
=
SpecHelper
::
Installer
.
new
(
spec
)
installer
=
SpecHelper
::
Installer
.
new
(
spec
,
projpath
)
installer
.
install!
installer
.
install!
Pod
::
ProjectIntegration
.
integrate_with_project
(
projpath
)
xcworkspace
=
temporary_directory
+
'ASIHTTPRequest.xcworkspace'
workspace
=
Xcodeproj
::
Workspace
.
new_from_xcworkspace
(
temporary_directory
+
'ASIHTTPRequest.xcworkspace'
)
workspace
=
Xcodeproj
::
Workspace
.
new_from_xcworkspace
(
xcworkspace
)
workspace
.
projpaths
.
sort
.
should
==
[
'ASIHTTPRequest.xcodeproj'
,
'Pods/Pods.xcodeproj'
]
workspace
.
projpaths
.
sort
.
should
==
[
'ASIHTTPRequest.xcodeproj'
,
'Pods/Pods.xcodeproj'
]
project
=
Pod
::
Project
.
new
(
projpath
)
project
=
Pod
::
Project
.
new
(
projpath
)
...
...
spec/spec_helper/fixture.rb
View file @
07fad458
...
@@ -4,10 +4,8 @@ module SpecHelper
...
@@ -4,10 +4,8 @@ module SpecHelper
end
end
def
self
.
create_sample_app_copy_from_fixture
(
fixture_name
)
def
self
.
create_sample_app_copy_from_fixture
(
fixture_name
)
tmp_dir
=
Pathname
.
new
(
Dir
.
mktmpdir
)
fixture_copy_path
=
temporary_directory
+
fixture_name
fixture_path
=
ROOT
+
"spec/fixtures/
#{
fixture_name
}
"
FileUtils
.
cp_r
(
fixture
(
fixture_name
),
temporary_directory
)
fixture_copy_path
=
tmp_dir
+
fixture_name
FileUtils
.
cp_r
(
fixture_path
,
tmp_dir
)
fixture_copy_path
+
"
#{
fixture_name
}
.xcodeproj"
fixture_copy_path
+
"
#{
fixture_name
}
.xcodeproj"
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