Skip to content

Commit

Permalink
Actually create a new PBXNativeTarget instance and set the defaults.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Oct 30, 2011
1 parent 183f255 commit 14cb718
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
37 changes: 31 additions & 6 deletions lib/cocoapods/xcode/project.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
7 changes: 5 additions & 2 deletions spec/unit/xcode/project_spec.rb
Expand Up @@ -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

Expand Down

0 comments on commit 14cb718

Please sign in to comment.