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
# use_frameworks!
PLATFORM
project.native_targets.each do |target|
podfile << target_module(target)
# Split out the targets into app and test targets
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
podfile << "\n"
end
# @param [Xcodeproj::PBXTarget] target
# A target to generate a Podfile target module for.
# @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 target_module(target)
target_module = "\ntarget '#{target.name.gsub(/'/, "\\\\\'")}' do\n"
def target_module(targets)
app = targets.first
target_module = "\ntarget '#{app.name.gsub(/'/, "\\\\\'")}' do\n"
target_module << template_contents(config.default_podfile_path, " ")
if target.name =~ /tests?/i
target_module << template_contents(config.default_test_podfile_path)
else
target_module << template_contents(config.default_podfile_path)
test = targets[1]
if 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, " ")
target_module << "\n end\n"
end
target_module << "\nend\n"
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?
path.read.chomp.lines.map { |line| " #{line}" }.join("\n")
path.read.chomp.lines.map { |line| "#{prefix}#{line}" }.join("\n")
else
''
end
......
......@@ -95,6 +95,7 @@ module Pod
open(config.default_test_podfile_path, 'w') { |f| f << "pod 'Kiwi'" }
project = Xcodeproj::Project.new(temporary_directory + 'test.xcodeproj')
project.new_target(:application, 'App', :ios)
project.new_target(:application, 'AppTests', :ios)
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