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
242da6b5
Commit
242da6b5
authored
Apr 19, 2016
by
Orta
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5163 from CocoaPods/orta-init-two
Add support for CP1.0 style target inheritence in `pod init`
parents
bd6046fc
f2fe34ce
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
17 deletions
+99
-17
CHANGELOG.md
CHANGELOG.md
+4
-1
init.rb
lib/cocoapods/command/init.rb
+48
-16
init_spec.rb
spec/functional/command/init_spec.rb
+47
-0
No files found.
CHANGELOG.md
View file @
242da6b5
...
@@ -8,7 +8,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
...
@@ -8,7 +8,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Enhancements
##### Enhancements
*
None.
*
The
`pod init`
command now uses target inheritance for test targets
in the generated Podfile.
[
Orta Therox
](
https://github.com/orta
)
[
#4714
](
https://github.com/CocoaPods/CocoaPods/issue/4714
)
##### Bug Fixes
##### Bug Fixes
...
...
lib/cocoapods/command/init.rb
View file @
242da6b5
...
@@ -58,37 +58,69 @@ module Pod
...
@@ -58,37 +58,69 @@ module Pod
podfile
<<
<<-
PLATFORM
.
strip_heredoc
podfile
<<
<<-
PLATFORM
.
strip_heredoc
# Uncomment this line to define a global platform for your project
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# platform :ios, '9.0'
# Uncomment this line if you're using Swift
# use_frameworks!
PLATFORM
PLATFORM
project
.
native_targets
.
each
do
|
target
|
# Split out the targets into app and test targets
podfile
<<
target_module
(
target
)
test_targets
,
app_targets
=
project
.
native_targets
.
sort_by
{
|
t
|
t
.
name
.
downcase
}.
partition
{
|
t
|
t
.
name
=~
/test/i
}
app_targets
.
each
do
|
app_target
|
test_targets_for_app
=
test_targets
.
select
do
|
target
|
target
.
name
.
downcase
.
start_with?
(
app_target
.
name
.
downcase
)
end
podfile
<<
target_module
(
app_target
,
test_targets_for_app
)
end
end
podfile
<<
"
\n
"
podfile
end
end
# @param [Xcodeproj::PBXTarget] target
# @param [[Xcodeproj::PBXTarget]] targets
# A target to generate a Podfile target module for.
# An array which always has a target as it's first item
# and may optionally contain related test targets
#
#
# @return [String] the text for the target module
# @return [String] the text for the target module
#
#
def
target_module
(
target
)
def
target_module
(
app
,
tests
)
target_module
=
"
\n
target '
#{
target
.
name
.
gsub
(
/'/
,
"
\\\\\'
"
)
}
' do
\n
"
target_module
=
"
\n
target '
#{
app
.
name
.
gsub
(
/'/
,
"
\\\\\'
"
)
}
' do
\n
"
if
target
.
name
=~
/tests?/i
target_module
<<
if
app
.
resolved_build_setting
(
'SWIFT_OPTIMIZATION_LEVEL'
).
values
.
any?
target_module
<<
template_contents
(
config
.
default_test_podfile_path
)
<<-
RUBY
else
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
target_module
<<
template_contents
(
config
.
default_podfile_path
)
use_frameworks!
RUBY
else
<<-
RUBY
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
RUBY
end
target_module
<<
template_contents
(
config
.
default_podfile_path
,
' '
,
"Pods for
#{
app
.
name
}
\n
"
)
tests
.
each
do
|
test
|
target_module
<<
"
\n
target '
#{
test
.
name
.
gsub
(
/'/
,
"
\\\\\'
"
)
}
' do
\n
"
target_module
<<
" inherit! :search_paths
\n
"
target_module
<<
template_contents
(
config
.
default_test_podfile_path
,
' '
,
'Pods for testing'
)
target_module
<<
"
\n
end
\n
"
end
end
target_module
<<
"
\n
end
\n
"
target_module
<<
"
\n
end
\n
"
end
end
def
template_contents
(
path
)
# @param [[Xcodeproj::PBXTarget]] targets
# An array which always has a target as it's first item
# and may optionally contain a second target as its test target
#
# @return [String] the text for the target module
#
def
template_contents
(
path
,
prefix
,
fallback
)
if
path
.
exist?
if
path
.
exist?
path
.
read
.
chomp
.
lines
.
map
{
|
line
|
"
#{
line
}
"
}.
join
(
"
\n
"
)
path
.
read
.
chomp
.
lines
.
map
{
|
line
|
"
#{
prefix
}
#{
line
}
"
}.
join
(
"
\n
"
)
else
else
''
"
#{
prefix
}
#
#{
fallback
}
"
end
end
end
end
end
end
...
...
spec/functional/command/init_spec.rb
View file @
242da6b5
...
@@ -86,6 +86,52 @@ module Pod
...
@@ -86,6 +86,52 @@ module Pod
end
end
end
end
it
'handles hooking up mulitple test targets based on an xcodeproj project'
do
Dir
.
chdir
(
temporary_directory
)
do
project
=
Xcodeproj
::
Project
.
new
(
temporary_directory
+
'test.xcodeproj'
)
project
.
new_target
(
:application
,
'App'
,
:ios
)
project
.
new_target
(
:application
,
'AppTests'
,
:ios
)
project
.
new_target
(
:application
,
'AppFeatureTests'
,
:ios
)
project
.
new_target
(
:application
,
'Swifty App'
,
:osx
,
nil
,
nil
,
:swift
)
project
.
save
run_command
(
'init'
)
expected_podfile
=
<<-
RUBY
.
strip_heredoc
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'App' do
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for App
target 'AppFeatureTests' do
inherit! :search_paths
# Pods for testing
end
target 'AppTests' do
inherit! :search_paths
# Pods for testing
end
end
target 'Swifty App' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Swifty App
end
RUBY
File
.
read
(
'Podfile'
).
should
==
expected_podfile
end
end
it
'includes default test pods in test targets in a Podfile'
do
it
'includes default test pods in test targets in a Podfile'
do
Dir
.
chdir
(
temporary_directory
)
do
Dir
.
chdir
(
temporary_directory
)
do
tmp_templates_dir
=
Pathname
.
pwd
+
'templates_dir'
tmp_templates_dir
=
Pathname
.
pwd
+
'templates_dir'
...
@@ -95,6 +141,7 @@ module Pod
...
@@ -95,6 +141,7 @@ module Pod
open
(
config
.
default_test_podfile_path
,
'w'
)
{
|
f
|
f
<<
"pod 'Kiwi'"
}
open
(
config
.
default_test_podfile_path
,
'w'
)
{
|
f
|
f
<<
"pod 'Kiwi'"
}
project
=
Xcodeproj
::
Project
.
new
(
temporary_directory
+
'test.xcodeproj'
)
project
=
Xcodeproj
::
Project
.
new
(
temporary_directory
+
'test.xcodeproj'
)
project
.
new_target
(
:application
,
'App'
,
:ios
)
project
.
new_target
(
:application
,
'AppTests'
,
:ios
)
project
.
new_target
(
:application
,
'AppTests'
,
:ios
)
project
.
save
project
.
save
...
...
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