From 14cb718f2a8d47207b8b1929cf6016a2ac03ab06 Mon Sep 17 00:00:00 2001 From: Eloy Duran Date: Sun, 30 Oct 2011 19:37:58 +0100 Subject: [PATCH] Actually create a new PBXNativeTarget instance and set the defaults. --- lib/cocoapods/xcode/project.rb | 37 +++++++++++++++++++++++++++------ spec/unit/xcode/project_spec.rb | 7 +++++-- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lib/cocoapods/xcode/project.rb b/lib/cocoapods/xcode/project.rb index bea700eb9e..b1a7b415e0 100644 --- a/lib/cocoapods/xcode/project.rb +++ b/lib/cocoapods/xcode/project.rb @@ -86,13 +86,20 @@ class PBXFileReference < PBXObject def initialize(project, uuid, attributes) is_new = uuid.nil? super - self.name ||= pathname.basename.to_s + self.path = path if path # sets default name self.sourceTree ||= 'SOURCE_ROOT' if is_new @project.build_files.new.file = self end end + alias_method :_path=, :path= + def path=(path) + self._path = path + self.name ||= pathname.basename.to_s + path + end + def pathname Pathname.new(path) end @@ -190,6 +197,8 @@ class PBXShellScriptBuildPhase < PBXBuildPhase end class PBXNativeTarget < PBXObject + STATIC_LIBRARY = 'com.apple.product-type.library.static' + attributes :productName, :productType has_many :buildPhases, :class => PBXBuildPhase @@ -198,12 +207,28 @@ class PBXNativeTarget < PBXObject has_one :buildConfigurationList has_one :product, :uuid => :productReference - def initialize(project, uuid, attributes) + def initialize(project, *) super - self.buildPhaseReferences ||= [] - # TODO self.buildConfigurationList ||= new list? - self.buildRuleReferences ||= [] - self.dependencyReferences ||= [] + self.buildPhaseReferences ||= [] + self.buildRuleReferences ||= [] + self.dependencyReferences ||= [] + + unless buildConfigurationList + self.buildConfigurationList = project.objects.add(XCConfigurationList) + # TODO or should this happen in buildConfigurationList? + buildConfigurationList.buildConfigurations.new('name' => 'Debug') + buildConfigurationList.buildConfigurations.new('name' => 'Release') + end + + unless product + self.product = project.objects.add(PBXFileReference, 'sourceTree' => 'BUILT_PRODUCTS_DIR') + case productType + when STATIC_LIBRARY + product.path = "lib#{productName}.a" + product.includeInIndex = "0" # no idea what this is + product.explicitFileType = "archive.ar" + end + end end end diff --git a/spec/unit/xcode/project_spec.rb b/spec/unit/xcode/project_spec.rb index 817cdc2024..bf9abfb3b3 100644 --- a/spec/unit/xcode/project_spec.rb +++ b/spec/unit/xcode/project_spec.rb @@ -133,10 +133,13 @@ def find_object(conditions) describe "a new PBXNativeTarget" do before do - @target = @project.targets.first + @target = @project.targets.new({ + 'productName' => 'Pods', + 'productType' => Pod::Xcode::Project::PBXNativeTarget::STATIC_LIBRARY + }) end - it "returns the product name, which is the name of the binary" do + it "returns the product name, which is the name of the binary (minus prefix/suffix)" do @target.productName.should == "Pods" end