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

Factor templating out of xcodeproj

parent 268c3b29
......@@ -12,6 +12,7 @@ module Pod
autoload :Executable, 'cocoapods/executable'
autoload :Installer, 'cocoapods/installer'
autoload :Podfile, 'cocoapods/podfile'
autoload :ProjectTemplate, 'cocoapods/project_template'
autoload :Resolver, 'cocoapods/resolver'
autoload :Source, 'cocoapods/source'
autoload :Spec, 'cocoapods/specification'
......
......@@ -29,8 +29,12 @@ module Pod
})
end
def template
@template ||= ProjectTemplate.new(@specification.platform)
end
def xcodeproj
@xcodeproj ||= Xcode::Project.static_library(@specification.platform)
@xcodeproj ||= Xcode::Project.new(template.xcodeproj_path)
end
# TODO move xcconfig related code into the xcconfig method, like copy_resources_script and generate_bridge_support.
......@@ -79,7 +83,11 @@ module Pod
generate_project
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)
if @specification.generate_bridge_support?
path = bridge_support_generator.create_in(root)
......@@ -95,7 +103,7 @@ module Pod
xcworkspace = File.join(root, File.basename(projpath, '.xcodeproj') + '.xcworkspace')
workspace = Xcode::Workspace.new_from_xcworkspace(xcworkspace)
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
paths.each do |path|
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
end
end
include Pod::Config::Mixin
# 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/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'
def initialize(xcodeproj)
file = File.join(xcodeproj, 'project.pbxproj')
@plist = NSMutableDictionary.dictionaryWithContentsOfFile(file.to_s)
end
def to_hash
@template
@plist
end
def objects_hash
@template['objects']
@plist['objects']
end
def objects
......@@ -301,12 +276,10 @@ module Pod
source_files
end
def create_in(pods_root)
puts " * Copying contents of template directory `#{@template_dir}' to `#{pods_root}'" if config.verbose?
FileUtils.cp_r("#{@template_dir}/.", pods_root)
pbxproj = pods_root + template_file
puts " * Writing Xcode project file to `#{pbxproj}'" if config.verbose?
@template.writeToFile(pbxproj.to_s, atomically:true)
def save_as(projpath)
projpath = projpath.to_s
FileUtils.mkdir_p(projpath)
@plist.writeToFile(File.join(projpath, 'project.pbxproj'), atomically:true)
end
# TODO add comments, or even constants, describing what these magic numbers are.
......
......@@ -128,7 +128,7 @@ else
installer = Pod::Installer.new(spec)
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
end
......
......@@ -4,7 +4,8 @@ describe "Pod::Xcode::Project" do
extend SpecHelper::TemporaryDirectory
before do
@project = Pod::Xcode::Project.static_library(:ios)
@template = Pod::ProjectTemplate.new(:ios)
@project = Pod::Xcode::Project.new(@template.xcodeproj_path)
end
def find_objects(conditions)
......@@ -18,8 +19,7 @@ describe "Pod::Xcode::Project" do
end
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_dir + 'Pods.xcodeproj/project.pbxproj').to_s
template_file = (@template.xcodeproj_path + '/project.pbxproj').to_s
@project.to_hash.should == NSDictionary.dictionaryWithContentsOfFile(template_file)
end
......@@ -178,7 +178,8 @@ describe "Pod::Xcode::Project" do
end
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.xcconfig').should.exist
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