Commit 3f2ac634 authored by Orta Therox's avatar Orta Therox Committed by Samuel Giddins

Add support for CP1.0 style target inheritance in `pod lib create`

parent bd6046fc
...@@ -62,31 +62,52 @@ module Pod ...@@ -62,31 +62,52 @@ module Pod
# use_frameworks! # use_frameworks!
PLATFORM PLATFORM
project.native_targets.each do |target| # Split out the targets into app and test targets
podfile << target_module(target) all_app_targets = project.native_targets.reject { |t| t.name =~ /tests?/i }
all_tests_targets = project.native_targets.select { |t| t.name =~ /tests?/i }
# Create an array of [app, (optional)test] target pairs
app_test_pairs = all_app_targets.map do |target|
test = all_tests_targets.find { |t| t.name.start_with? target.name }
[target, test].compact
end
app_test_pairs.each do |target_pair|
podfile << target_module(target_pair)
end end
podfile << "\n"
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 a second target as its test target
# #
# @return [String] the text for the target module # @return [String] the text for the target module
# #
def target_module(target) def target_module(targets)
target_module = "\ntarget '#{target.name.gsub(/'/, "\\\\\'")}' do\n" app = targets.first
target_module = "\ntarget '#{app.name.gsub(/'/, "\\\\\'")}' do\n"
target_module << template_contents(config.default_podfile_path, " ")
if target.name =~ /tests?/i test = targets[1]
target_module << template_contents(config.default_test_podfile_path) if test
else target_module << "\n target '#{test.name.gsub(/'/, "\\\\\'")}' do\n"
target_module << template_contents(config.default_podfile_path) target_module << " inherit! :search_paths\n"
target_module << template_contents(config.default_test_podfile_path, " ")
target_module << "\n end\n"
end end
target_module << "\nend\n" target_module << "\nend\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)
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
'' ''
end end
......
...@@ -95,6 +95,7 @@ module Pod ...@@ -95,6 +95,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
......
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