Skip to content
Browse files

Clean template related code a bit by using the API.

  • Loading branch information...
1 parent 9ee4b9b commit 9ea008e3a9fa3203a941cfca612adc10d7197817 @alloy committed Nov 6, 2011
Showing with 22 additions and 30 deletions.
  1. +1 −10 lib/cocoapods/installer.rb
  2. +4 −13 lib/cocoapods/project_template.rb
  3. +17 −7 lib/cocoapods/xcode/project.rb
View
11 lib/cocoapods/installer.rb
@@ -212,26 +212,17 @@ def configure_project(projpath)
config.baseConfiguration = configfile
end
end
- app_project.main_group << configfile
- libfile = app_project.files.new({
- 'path' => 'libPods.a',
- 'lastKnownFileType' => 'archive.ar',
- 'includeInIndex' => '0',
- 'sourceTree' => 'BUILT_PRODUCTS_DIR'
- })
+ libfile = app_project.files.new_static_library('Pods')
app_project.objects.select_by_class(Xcode::Project::PBXFrameworksBuildPhase).each do |build_phase|
build_phase.files << libfile.buildFiles.new
end
- app_project.main_group << libfile
copy_resources = app_project.objects.add(Xcode::Project::PBXShellScriptBuildPhase, {
'name' => 'Copy Pods Resources',
- 'buildActionMask' => '2147483647',
'files' => [],
'inputPaths' => [],
'outputPaths' => [],
- 'runOnlyForDeploymentPostprocessing' => '0',
'shellPath' => '/bin/sh',
'shellScript' => "${SRCROOT}/Pods/Pods-resources.sh\n"
})
View
17 lib/cocoapods/project_template.rb
@@ -10,31 +10,22 @@ def self.for_platform(platform)
'developmentRegion' => 'English',
'hasScannedForEncodings' => '0',
'knownRegions' => ['en'],
- 'mainGroup' => project.groups.new({ 'sourceTree' => '<group>' }).uuid,
+ 'mainGroup' => project.groups.new.uuid,
'projectDirPath' => '',
'projectRoot' => '',
'targets' => []
})
project.root_object = root
- project.main_group << project.groups.new({
- 'name' => 'Pods',
- 'sourceTree' => '<group>'
- })
+ project.main_group << project.groups.new('name' => 'Pods')
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({
- 'name' => 'Frameworks',
- 'sourceTree' => '<group>'
- })
+ framework.group = project.groups.new('name' => 'Frameworks')
project.main_group << framework.group
- products = project.groups.new({
- 'name' => 'Products',
- 'sourceTree' => '<group>'
- })
+ products = project.groups.new('name' => 'Products')
project.main_group << products
project.root_object.products = products
View
24 lib/cocoapods/xcode/project.rb
@@ -238,6 +238,15 @@ class PBXFileReference < PBXObject
has_many :buildFiles, :inverse_of => :file
has_one :group, :inverse_of => :children
+ def self.new_static_library(project, productName)
+ new(project, nil, {
+ "path" => "lib#{productName}.a",
+ "includeInIndex" => "0", # no idea what this is
+ "explicitFileType" => "archive.ar",
+ "sourceTree" => "BUILT_PRODUCTS_DIR",
+ })
+ end
+
def initialize(project, uuid, attributes)
is_new = uuid.nil?
super
@@ -359,9 +368,7 @@ class PBXNativeTarget < PBXObject
def self.new_static_library(project, productName)
# TODO should probably switch the uuid and attributes argument
target = new(project, nil, 'productType' => STATIC_LIBRARY, 'productName' => productName)
- target.product.path = "lib#{productName}.a"
- target.product.includeInIndex = "0" # no idea what this is
- target.product.explicitFileType = "archive.ar"
+ target.product = project.files.new_static_library(productName)
target.buildPhases.add(PBXSourcesBuildPhase)
buildPhase = target.buildPhases.add(PBXFrameworksBuildPhase)
@@ -373,6 +380,8 @@ def self.new_static_library(project, productName)
target
end
+ # You need to specify a product. For a static library you can use
+ # PBXFileReference.new_static_library.
def initialize(project, *)
super
self.name ||= productName
@@ -386,11 +395,12 @@ def initialize(project, *)
buildConfigurationList.buildConfigurations.new('name' => 'Debug')
buildConfigurationList.buildConfigurations.new('name' => 'Release')
end
+ end
- unless product
- self.product = project.files.new('sourceTree' => 'BUILT_PRODUCTS_DIR')
- product.group = project.products
- end
+ alias_method :_product=, :product=
+ def product=(product)
+ self._product = product
+ product.group = @project.products
end
def buildConfigurations

0 comments on commit 9ea008e

Please sign in to comment.
Something went wrong with that request. Please try again.