Permalink
Browse files

ProjectTemplate is really a module

  • Loading branch information...
1 parent 70858e8 commit ed6862fd28f2e8b5e7c81f68f924bb67b9013dec @nolanw nolanw committed Nov 5, 2011
Showing with 77 additions and 86 deletions.
  1. +14 −14 lib/cocoapods/installer.rb
  2. +22 −31 lib/cocoapods/project_template.rb
  3. +2 −2 spec/integration_spec.rb
  4. +39 −39 spec/unit/xcode/project_spec.rb
View
@@ -20,8 +20,8 @@ class Target
attr_reader :target
- def initialize(podfile, xcodeproj, definition)
- @podfile, @xcodeproj, @definition = podfile, xcodeproj, definition
+ def initialize(podfile, project, definition)
+ @podfile, @project, @definition = podfile, project, definition
end
def xcconfig
@@ -77,7 +77,7 @@ def prefix_header_filename
# TODO move xcconfig related code into the xcconfig method, like copy_resources_script and generate_bridge_support.
def install!
# First add the target to the project
- @target = @xcodeproj.targets.new_static_library(@definition.lib_name)
+ @target = @project.targets.new_static_library(@definition.lib_name)
user_header_search_paths = []
build_specifications.each do |spec|
@@ -101,7 +101,7 @@ def install!
# Add all the target related support files to the group, even the copy
# resources script although the project doesn't actually use them.
- support_files_group = @xcodeproj.groups.find do |group|
+ support_files_group = @project.groups.find do |group|
group.name == "Targets Support Files"
end.groups.new("name" => @definition.lib_name)
support_files_group.files.new('path' => copy_resources_filename)
@@ -132,27 +132,27 @@ def initialize(podfile)
@podfile = podfile
end
- def template
- return @template if @template
- @template = ProjectTemplate.new(@podfile.platform)
+ def project
+ return @project if @project
+ @project = ProjectTemplate.for_platform(@podfile.platform)
# First we need to resolve dependencies across *all* targets, so that the
# same correct versions of pods are being used for all targets. This
# happens when we call `build_specifications'.
build_specifications.each do |spec|
# Add all source files to the project grouped by pod
- group = @template.project.add_pod_group(spec.name)
+ group = @project.add_pod_group(spec.name)
spec.expanded_source_files.each do |path|
group.children.new('path' => path.to_s)
end
end
# Add a group to hold all the target support files
- @template.project.main_group.groups.new('name' => 'Targets Support Files')
- @template
+ @project.main_group.groups.new('name' => 'Targets Support Files')
+ @project
end
def targets
@targets ||= @podfile.targets.values.map do |target_definition|
- Target.new(@podfile, template.project, target_definition)
+ Target.new(@podfile, project, target_definition)
end
end
@@ -166,9 +166,9 @@ def install!
target.install!
target.create_files_in(root)
end
- pbxproj = File.join(root, 'Pods.xcodeproj')
- puts " * Writing Xcode project file to `#{pbxproj}'" if config.verbose?
- template.project.save_as(pbxproj)
+ projpath = File.join(root, 'Pods.xcodeproj')
+ puts " * Writing Xcode project file to `#{projpath}'" if config.verbose?
+ project.save_as(projpath)
# Post install hooks run last!
targets.each do |target|
@@ -1,71 +1,62 @@
require 'fileutils'
module Pod
- class ProjectTemplate
- def initialize(platform)
- @platform = platform
- generate_template_project!
- end
-
- attr_reader :platform
- attr_reader :project
-
- def save_to(pods_root)
- @project.save_as(File.join(pods_root, 'Pods.xcodeproj'))
- end
-
- def generate_template_project!
- @project = Xcode::Project.new
- root = @project.objects.add(Xcode::Project::PBXProject, {
+ module ProjectTemplate
+ def self.for_platform(platform)
+ project = Xcode::Project.new
+ root = project.objects.add(Xcode::Project::PBXProject, {
'attributes' => { 'LastUpgradeCheck' => '0420' },
'compatibilityVersion' => 'Xcode 3.2',
'developmentRegion' => 'English',
'hasScannedForEncodings' => '0',
'knownRegions' => ['en'],
- 'mainGroup' => @project.groups.new({ 'sourceTree' => '<group>' }).uuid,
+ 'mainGroup' => project.groups.new({ 'sourceTree' => '<group>' }).uuid,
'projectDirPath' => '',
'projectRoot' => '',
'targets' => []
})
- @project.root_object = root
- @project.main_group << @project.groups.new({
+ project.root_object = root
+ project.main_group << project.groups.new({
'name' => 'Pods',
'sourceTree' => '<group>'
})
- framework = @project.files.new({
+ framework = project.files.new({
'lastKnownFileType' => 'wrapper.framework',
'name' => platform == :ios ? 'Foundation.framework' : 'Cocoa.framework',
'path' => "System/Library/Frameworks/#{platform == :ios ? 'Framework' : 'Cocoa'}.framework",
'sourceTree' => 'SDKROOT'
})
- framework.group = @project.groups.new({
+ framework.group = project.groups.new({
'name' => 'Frameworks',
'sourceTree' => '<group>'
})
- @project.main_group << framework.group
- products = @project.groups.new({
+ project.main_group << framework.group
+ products = project.groups.new({
'name' => 'Products',
'sourceTree' => '<group>'
})
- @project.main_group << products
- @project.root_object.products = products
+ project.main_group << products
+ project.root_object.products = products
- @project.root_object.attributes['buildConfigurationList'] = @project.objects.add(Xcode::Project::XCConfigurationList, {
+ project.root_object.attributes['buildConfigurationList'] = project.objects.add(Xcode::Project::XCConfigurationList, {
'defaultConfigurationIsVisible' => '0',
'defaultConfigurationName' => 'Release',
'buildConfigurations' => [
- @project.objects.add(Xcode::Project::XCBuildConfiguration, {
+ project.objects.add(Xcode::Project::XCBuildConfiguration, {
'name' => 'Debug',
- 'buildSettings' => build_settings(:debug)
+ 'buildSettings' => build_settings(platform, :debug)
}),
- @project.objects.add(Xcode::Project::XCBuildConfiguration, {
+ project.objects.add(Xcode::Project::XCBuildConfiguration, {
'name' => 'Release',
- 'buildSettings' => build_settings(:release)
+ 'buildSettings' => build_settings(platform, :release)
})
].map(&:uuid)
}).uuid
+ project
end
+ private
+
COMMON_BUILD_SETTINGS = {
:all => {
'ALWAYS_SEARCH_USER_PATHS' => 'NO',
@@ -97,7 +88,7 @@ def generate_template_project!
'SDKROOT' => 'macosx'
}
}
- def build_settings(scheme)
+ def self.build_settings(platform, scheme)
settings = COMMON_BUILD_SETTINGS[:all].merge(COMMON_BUILD_SETTINGS[platform])
settings['COPY_PHASE_STRIP'] = scheme == :debug ? 'NO' : 'YES'
if scheme == :debug
View
@@ -77,7 +77,7 @@ def should_successfully_perform(command)
(root + 'Pods.xcconfig').read.should == installer.targets.first.xcconfig.to_s
project_file = (root + 'Pods.xcodeproj/project.pbxproj').to_s
- NSDictionary.dictionaryWithContentsOfFile(project_file).should == installer.template.project.to_hash
+ NSDictionary.dictionaryWithContentsOfFile(project_file).should == installer.project.to_hash
puts "\n[!] Compiling static library..."
Dir.chdir(config.project_pods_root) do
@@ -144,7 +144,7 @@ def should_successfully_perform(command)
installer.install!
project = Pod::Xcode::Project.new(config.project_pods_root + 'Pods.xcodeproj')
- project.source_files.should == installer.template.project.source_files
+ project.source_files.should == installer.project.source_files
end
it "creates a project with multiple targets" do
Oops, something went wrong.

0 comments on commit ed6862f

Please sign in to comment.