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
794a427f
Commit
794a427f
authored
Mar 01, 2012
by
Luke Redpath
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Its not much of a refactoring, but things are a bit clearer now.
parent
7db18a2f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
84 deletions
+53
-84
project_integration.rb
lib/cocoapods/project_integration.rb
+53
-25
project_integration_spec.rb
spec/unit/project_integration_spec.rb
+0
-59
No files found.
lib/cocoapods/project_integration.rb
View file @
794a427f
...
@@ -18,44 +18,72 @@ module Pod
...
@@ -18,44 +18,72 @@ module Pod
# 3. Let the user specify the app target name as an extra argument, but this
# 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.
# seems to be a less good version of the variation on #2.
def
self
.
integrate_with_project
(
projpath
)
class
<<
self
# TODO use more of Pathname’s API here
def
integrate_with_project
(
projpath
)
root
=
File
.
dirname
(
projpath
)
root
=
File
.
dirname
(
projpath
)
xcworkspace
=
File
.
join
(
root
,
File
.
basename
(
projpath
,
'.xcodeproj'
)
+
'.xcworkspace'
)
name
=
File
.
basename
(
projpath
,
'.xcodeproj'
)
workspace
=
Xcodeproj
::
Workspace
.
new_from_xcworkspace
(
xcworkspace
)
pods_projpath
=
File
.
join
(
config
.
project_pods_root
,
'Pods.xcodeproj'
)
root
=
Pathname
.
new
(
root
).
expand_path
[
projpath
,
pods_projpath
].
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
(
xcworkspace
)
xcworkspace
=
create_workspace
(
root
,
name
,
projpath
)
app_project
=
Xcodeproj
::
Project
.
new
(
projpath
)
app_project
=
Xcodeproj
::
Project
.
new
(
projpath
)
return
if
app_project
.
files
.
find
{
|
file
|
file
.
path
=~
/libPods\.a$/
}
configfile
=
app_project
.
files
.
new
(
'path'
=>
'Pods/Pods.xcconfig'
)
return
if
project_already_integrated?
(
app_project
)
app_project
.
targets
.
each
do
|
target
|
target
.
buildConfigurations
.
each
do
|
config
|
xcconfig
=
app_project
.
files
.
new
(
'path'
=>
'Pods/Pods.xcconfig'
)
config
.
baseConfiguration
=
configfile
base_project_configurations_on_xcconfig
(
app_project
,
xcconfig
)
end
end
libfile
=
app_project
.
files
.
new_static_library
(
'Pods'
)
libfile
=
app_project
.
files
.
new_static_library
(
'Pods'
)
libfile
.
group
=
app_project
.
main_group
.
groups
.
find
{
|
g
|
g
.
name
==
'Frameworks'
}
libfile
.
group
=
app_project
.
group
(
"Frameworks"
)
app_project
.
objects
.
select_by_class
(
Xcodeproj
::
Project
::
Object
::
PBXFrameworksBuildPhase
).
each
do
|
build_phase
|
build_phase
.
files
<<
libfile
.
buildFiles
.
new
end
copy_resources
=
app_project
.
add_shell_script_build_phase
(
'Copy Pods Resources'
,
add_pods_library_to_each_target_in_project
(
app_project
,
libfile
)
%{"${SRCROOT}/Pods/Pods-resources.sh"\n}
)
app_project
.
targets
.
each
{
|
target
|
target
.
buildPhases
<<
copy_resources
}
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
)
app_project
.
save_as
(
projpath
)
unless
config
.
silent?
unless
config
.
silent?
# TODO this really shouldn't be here
puts
"[!] From now on use `
#{
File
.
basename
(
xcworkspace
)
}
' instead of `
#{
File
.
basename
(
projpath
)
}
'."
puts
"[!] From now on use `
#{
File
.
basename
(
xcworkspace
)
}
' instead of `
#{
File
.
basename
(
projpath
)
}
'."
end
end
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
)
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
.
buildConfigurations
.
each
do
|
config
|
config
.
baseConfiguration
=
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
.
buildFiles
.
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
.
buildPhases
<<
copy_resources_script_phase
}
end
end
end
end
end
end
spec/unit/project_integration_spec.rb
deleted
100644 → 0
View file @
7db18a2f
require
File
.
expand_path
(
'../../spec_helper'
,
__FILE__
)
describe
Pod
::
ProjectIntegration
do
before
do
@sample_project_path
=
SpecHelper
.
create_sample_app_copy_from_fixture
(
'SampleProject'
)
Pod
::
ProjectIntegration
.
integrate_with_project
(
@sample_project_path
)
@sample_project
=
Xcodeproj
::
Project
.
new
(
@sample_project_path
)
end
it
'creates a workspace with a name matching the project'
do
workspace_path
=
@sample_project_path
.
dirname
+
"SampleProject.xcworkspace"
workspace_path
.
should
.
exist
end
it
'adds the project being integrated to the workspace'
do
workspace
=
Xcodeproj
::
Workspace
.
new_from_xcworkspace
(
@sample_project_path
.
dirname
+
"SampleProject.xcworkspace"
)
workspace
.
should
.
include?
(
"SampleProject.xcodeproj"
)
end
it
'adds the Pods project to the workspace'
do
workspace
=
Xcodeproj
::
Workspace
.
new_from_xcworkspace
(
@sample_project_path
.
dirname
+
"SampleProject.xcworkspace"
)
workspace
.
projpaths
.
find
{
|
path
|
path
=~
/Pods.xcodeproj/
}.
should
.
not
.
be
.
nil
end
it
'adds the Pods xcconfig file to the project'
do
@sample_project
.
files
.
where
(
:path
=>
"Pods/Pods.xcconfig"
).
should
.
not
.
be
.
nil
end
it
'sets the Pods xcconfig as the base config for each build configuration'
do
xcconfig_file
=
@sample_project
.
files
.
where
(
:path
=>
"Pods/Pods.xcconfig"
)
@sample_project
.
targets
.
each
do
|
target
|
target
.
buildConfigurations
.
each
do
|
config
|
config
.
baseConfiguration
.
should
==
xcconfig_file
end
end
end
it
'adds a reference to the libPods static library'
do
static_lib
=
@sample_project
.
files
.
where
(
:name
=>
"libPods.a"
)
static_lib
.
should
.
not
.
be
.
nil
end
it
'adds the libPods static library to the "Link binary with libraries" build phase of each target'
do
@sample_project
.
targets
.
each
do
|
target
|
framework_build_phase
=
target
.
frameworks_build_phases
.
first
framework_build_phase
.
files
.
where
(
:file
=>
{
:name
=>
'libPods.a'
}).
should
.
not
.
be
.
nil
end
end
it
'adds a Copy Pods Resources build phase to each target'
do
@sample_project
.
targets
.
each
do
|
target
|
expected_phase
=
target
.
shell_script_build_phases
.
where
(
:name
=>
"Copy Pods Resources"
)
expected_phase
.
shellScript
.
strip
.
should
==
"
\"
${SRCROOT}/Pods/Pods-resources.sh
\"
"
.
strip
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