Commit f2fe34ce authored by Samuel Giddins's avatar Samuel Giddins

[Init] Automatically set use_frameworks! for a target if it is likely using swift

parent fbaac42c
...@@ -58,12 +58,12 @@ module Pod ...@@ -58,12 +58,12 @@ 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
# Split out the targets into app and test targets # Split out the targets into app and test targets
test_targets, app_targets = project.native_targets.partition { |t| t.name =~ /test/i } 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| app_targets.each do |app_target|
test_targets_for_app = test_targets.select do |target| test_targets_for_app = test_targets.select do |target|
...@@ -83,12 +83,27 @@ module Pod ...@@ -83,12 +83,27 @@ module Pod
# #
def target_module(app, tests) def target_module(app, tests)
target_module = "\ntarget '#{app.name.gsub(/'/, "\\\\\'")}' do\n" target_module = "\ntarget '#{app.name.gsub(/'/, "\\\\\'")}' do\n"
target_module << template_contents(config.default_podfile_path, " ", "Pods for #{app.name}\n")
target_module << if app.resolved_build_setting('SWIFT_OPTIMIZATION_LEVEL').values.any?
<<-RUBY
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
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| tests.each do |test|
target_module << "\n target '#{test.name.gsub(/'/, "\\\\\'")}' do\n" target_module << "\n target '#{test.name.gsub(/'/, "\\\\\'")}' do\n"
target_module << " inherit! :search_paths\n" target_module << " inherit! :search_paths\n"
target_module << template_contents(config.default_test_podfile_path, " ", "Pods for testing") target_module << template_contents(config.default_test_podfile_path, ' ', 'Pods for testing')
target_module << "\n end\n" target_module << "\n end\n"
end end
...@@ -105,7 +120,7 @@ module Pod ...@@ -105,7 +120,7 @@ module Pod
if path.exist? if path.exist?
path.read.chomp.lines.map { |line| "#{prefix}#{line}" }.join("\n") path.read.chomp.lines.map { |line| "#{prefix}#{line}" }.join("\n")
else else
"#{prefix}# #{fallback}" "#{prefix}# #{fallback}"
end end
end end
end end
......
...@@ -91,7 +91,8 @@ module Pod ...@@ -91,7 +91,8 @@ module Pod
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, 'App', :ios)
project.new_target(:application, 'AppTests', :ios) project.new_target(:application, 'AppTests', :ios)
project.new_target(:application, "AppFeatureTests", :ios) project.new_target(:application, 'AppFeatureTests', :ios)
project.new_target(:application, 'Swifty App', :osx, nil, nil, :swift)
project.save project.save
run_command('init') run_command('init')
...@@ -99,30 +100,38 @@ module Pod ...@@ -99,30 +100,38 @@ module Pod
expected_podfile = <<-RUBY.strip_heredoc expected_podfile = <<-RUBY.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!
target 'App' do target 'App' do
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for App # Pods for App
target 'AppTests' do target 'AppFeatureTests' do
inherit! :search_paths inherit! :search_paths
# Pods for testing # Pods for testing
end end
target 'AppFeatureTests' do target 'AppTests' do
inherit! :search_paths inherit! :search_paths
# Pods for testing # Pods for testing
end end
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 RUBY
File.read('Podfile').should == expected_podfile File.read('Podfile').should == expected_podfile
end end
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'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment