Commit 594fd0c0 authored by Nolan Waite's avatar Nolan Waite

Factor templating out of xcodeproj

parent 268c3b29
...@@ -12,6 +12,7 @@ module Pod ...@@ -12,6 +12,7 @@ module Pod
autoload :Executable, 'cocoapods/executable' autoload :Executable, 'cocoapods/executable'
autoload :Installer, 'cocoapods/installer' autoload :Installer, 'cocoapods/installer'
autoload :Podfile, 'cocoapods/podfile' autoload :Podfile, 'cocoapods/podfile'
autoload :ProjectTemplate, 'cocoapods/project_template'
autoload :Resolver, 'cocoapods/resolver' autoload :Resolver, 'cocoapods/resolver'
autoload :Source, 'cocoapods/source' autoload :Source, 'cocoapods/source'
autoload :Spec, 'cocoapods/specification' autoload :Spec, 'cocoapods/specification'
......
...@@ -29,8 +29,12 @@ module Pod ...@@ -29,8 +29,12 @@ module Pod
}) })
end end
def template
@template ||= ProjectTemplate.new(@specification.platform)
end
def xcodeproj def xcodeproj
@xcodeproj ||= Xcode::Project.static_library(@specification.platform) @xcodeproj ||= Xcode::Project.new(template.xcodeproj_path)
end end
# TODO move xcconfig related code into the xcconfig method, like copy_resources_script and generate_bridge_support. # TODO move xcconfig related code into the xcconfig method, like copy_resources_script and generate_bridge_support.
...@@ -79,7 +83,11 @@ module Pod ...@@ -79,7 +83,11 @@ module Pod
generate_project generate_project
root = config.project_pods_root root = config.project_pods_root
xcodeproj.create_in(root) puts " * Copying contents of template directory `#{template.path}' to `#{root}'" if config.verbose?
template.copy_to(root)
pbxproj = File.join(root, 'Pods.xcodeproj')
puts " * Writing Xcode project file to `#{pbxproj}'" if config.verbose?
xcodeproj.save_as(pbxproj)
xcconfig.create_in(root) xcconfig.create_in(root)
if @specification.generate_bridge_support? if @specification.generate_bridge_support?
path = bridge_support_generator.create_in(root) path = bridge_support_generator.create_in(root)
...@@ -95,7 +103,7 @@ module Pod ...@@ -95,7 +103,7 @@ module Pod
xcworkspace = File.join(root, File.basename(projpath, '.xcodeproj') + '.xcworkspace') xcworkspace = File.join(root, File.basename(projpath, '.xcodeproj') + '.xcworkspace')
workspace = Xcode::Workspace.new_from_xcworkspace(xcworkspace) workspace = Xcode::Workspace.new_from_xcworkspace(xcworkspace)
paths = [projpath] paths = [projpath]
paths << File.join(config.project_pods_root, File.dirname(xcodeproj.template_file)) paths << File.join(config.project_pods_root, 'Pods.xcodeproj')
root = Pathname.new(root).expand_path root = Pathname.new(root).expand_path
paths.each do |path| paths.each do |path|
workspace << Pathname.new(path).expand_path.relative_path_from(root) workspace << Pathname.new(path).expand_path.relative_path_from(root)
......
require 'fileutils'
module Pod
class ProjectTemplate
def initialize(platform)
@platform = platform
end
# TODO this is a workaround for an issue with MacRuby with compiled files
# that makes the use of __FILE__ impossible.
#
#TEMPLATES_DIR = Pathname.new(File.expand_path('../../../xcode-project-templates', __FILE__))
file = $LOADED_FEATURES.find { |file| file =~ %r{cocoapods/project_template\.rbo?$} }
TEMPLATES_DIR = Pathname.new(File.expand_path('../../../xcode-project-templates', file))
def path
@path ||= case @platform
when :osx
TEMPLATES_DIR + 'cocoa-static-library'
when :ios
TEMPLATES_DIR + 'cocoa-touch-static-library'
else
raise "No Xcode project template exists for the platform `#{platform.inspect}'"
end
end
def xcodeproj_path
@xcodeproj_path = File.join(path, 'Pods.xcodeproj')
end
def copy_to(pods_root)
FileUtils.cp_r("#{path}/.", pods_root)
end
end
end
...@@ -215,42 +215,17 @@ module Pod ...@@ -215,42 +215,17 @@ module Pod
end end
end end
include Pod::Config::Mixin def initialize(xcodeproj)
file = File.join(xcodeproj, 'project.pbxproj')
# TODO this is a workaround for an issue with MacRuby with compiled files @plist = NSMutableDictionary.dictionaryWithContentsOfFile(file.to_s)
# that makes the use of __FILE__ impossible.
#
#TEMPLATES_DIR = Pathname.new(File.expand_path('../../../../xcode-project-templates', __FILE__))
file = $LOADED_FEATURES.find { |file| file =~ %r{cocoapods/xcode/project\.rbo?$} }
TEMPLATES_DIR = Pathname.new(File.expand_path('../../../../xcode-project-templates', file))
def self.static_library(platform)
case platform
when :osx
new TEMPLATES_DIR + 'cocoa-static-library'
when :ios
new TEMPLATES_DIR + 'cocoa-touch-static-library'
else
raise "No Xcode project template exists for the platform `#{platform.inspect}'"
end
end
def initialize(template_dir)
@template_dir = template_dir
file = template_dir + template_file
@template = NSMutableDictionary.dictionaryWithContentsOfFile(file.to_s)
end
def template_file
'Pods.xcodeproj/project.pbxproj'
end end
def to_hash def to_hash
@template @plist
end end
def objects_hash def objects_hash
@template['objects'] @plist['objects']
end end
def objects def objects
...@@ -301,12 +276,10 @@ module Pod ...@@ -301,12 +276,10 @@ module Pod
source_files source_files
end end
def create_in(pods_root) def save_as(projpath)
puts " * Copying contents of template directory `#{@template_dir}' to `#{pods_root}'" if config.verbose? projpath = projpath.to_s
FileUtils.cp_r("#{@template_dir}/.", pods_root) FileUtils.mkdir_p(projpath)
pbxproj = pods_root + template_file @plist.writeToFile(File.join(projpath, 'project.pbxproj'), atomically:true)
puts " * Writing Xcode project file to `#{pbxproj}'" if config.verbose?
@template.writeToFile(pbxproj.to_s, atomically:true)
end end
# TODO add comments, or even constants, describing what these magic numbers are. # TODO add comments, or even constants, describing what these magic numbers are.
......
...@@ -128,7 +128,7 @@ else ...@@ -128,7 +128,7 @@ else
installer = Pod::Installer.new(spec) installer = Pod::Installer.new(spec)
installer.generate_project installer.generate_project
project = Pod::Xcode::Project.new(config.project_pods_root) project = Pod::Xcode::Project.new(config.project_pods_root + 'Pods.xcodeproj')
project.source_files.should == installer.xcodeproj.source_files project.source_files.should == installer.xcodeproj.source_files
end end
......
...@@ -4,7 +4,8 @@ describe "Pod::Xcode::Project" do ...@@ -4,7 +4,8 @@ describe "Pod::Xcode::Project" do
extend SpecHelper::TemporaryDirectory extend SpecHelper::TemporaryDirectory
before do before do
@project = Pod::Xcode::Project.static_library(:ios) @template = Pod::ProjectTemplate.new(:ios)
@project = Pod::Xcode::Project.new(@template.xcodeproj_path)
end end
def find_objects(conditions) def find_objects(conditions)
...@@ -18,8 +19,7 @@ describe "Pod::Xcode::Project" do ...@@ -18,8 +19,7 @@ describe "Pod::Xcode::Project" do
end end
it "returns an instance initialized from the iOS static library template" do it "returns an instance initialized from the iOS static library template" do
template_dir = Pod::Xcode::Project::TEMPLATES_DIR + 'cocoa-touch-static-library' template_file = (@template.xcodeproj_path + '/project.pbxproj').to_s
template_file = (template_dir + 'Pods.xcodeproj/project.pbxproj').to_s
@project.to_hash.should == NSDictionary.dictionaryWithContentsOfFile(template_file) @project.to_hash.should == NSDictionary.dictionaryWithContentsOfFile(template_file)
end end
...@@ -178,7 +178,8 @@ describe "Pod::Xcode::Project" do ...@@ -178,7 +178,8 @@ describe "Pod::Xcode::Project" do
end end
it "saves the template with the adjusted project" do it "saves the template with the adjusted project" do
@project.create_in(temporary_directory) @template.copy_to(temporary_directory)
@project.save_as(temporary_directory + 'Pods.xcodeproj')
(temporary_directory + 'Pods-Prefix.pch').should.exist (temporary_directory + 'Pods-Prefix.pch').should.exist
(temporary_directory + 'Pods.xcconfig').should.exist (temporary_directory + 'Pods.xcconfig').should.exist
project_file = (temporary_directory + 'Pods.xcodeproj/project.pbxproj') project_file = (temporary_directory + 'Pods.xcodeproj/project.pbxproj')
......
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