Commit 35db5a85 authored by Eloy Duran's avatar Eloy Duran

Refactor by using more of the new project API.

parent 38a8e724
......@@ -118,8 +118,8 @@ module Pod
'lastKnownFileType' => 'text.xcconfig'
})
app_project.targets.each do |target|
target.buildConfigurationList.buildConfigurations.each do |config|
config.baseConfigurationReference = configfile
target.buildConfigurations.each do |config|
config.baseConfiguration = configfile
end
end
app_project.main_group << configfile
......@@ -131,7 +131,7 @@ module Pod
'sourceTree' => 'BUILT_PRODUCTS_DIR'
})
app_project.objects.select_by_class(Xcode::Project::PBXFrameworksBuildPhase).each do |build_phase|
build_phase.files << libfile.build_file
build_phase.files << libfile.buildFile
end
app_project.main_group << libfile
......
......@@ -30,7 +30,7 @@ module Pod
end
end
def self.has_one(singular_attr_name, options = {})
def self.belongs_to(singular_attr_name, options = {})
uuid_name = options[:uuid] || "#{singular_attr_name}Reference"
attribute(options[:uuid] || singular_attr_name, uuid_name)
define_method(singular_attr_name) do
......@@ -42,6 +42,16 @@ module Pod
end
end
def self.has_one(singular_attr_name, options = {})
klass = options[:class]
uuid_name = options[:uuid] || "#{singular_attr_name}Reference"
define_method(singular_attr_name) do
@project.objects.select_by_class(klass).find do |object|
object.respond_to?(uuid_name) && object.send(uuid_name) == self.uuid
end
end
end
def self.isa
@isa ||= name.split('::').last
end
......@@ -80,8 +90,22 @@ module Pod
end
end
# Missing constants that begin with either `PBX' or `XC' are assumed to be
# valid classes in a Xcode project. A new PBXObject subclass is created
# for the constant and returned.
def self.const_missing(name)
if name =~ /^(PBX|XC)/
klass = Class.new(PBXObject)
const_set(name, klass)
klass
else
super
end
end
class PBXFileReference < PBXObject
attributes :path, :sourceTree, :explicitFileType, :includeInIndex
has_one :buildFile, :uuid => :fileRef, :class => Project::PBXBuildFile
def initialize(project, uuid, attributes)
is_new = uuid.nil?
......@@ -103,10 +127,6 @@ module Pod
def pathname
Pathname.new(path)
end
def build_file
@project.build_files.find { |o| o.fileRef == uuid }
end
end
class PBXGroup < PBXObject
......@@ -124,7 +144,7 @@ module Pod
end
def source_files
list_by_class(childReferences, PBXFileReference, files.select { |file| !file.build_file.nil? })
list_by_class(childReferences, PBXFileReference, files.select(&:buildFile))
end
def groups
......@@ -133,7 +153,7 @@ module Pod
def add_source_file(path, copy_header_phase = nil, compiler_flags = nil)
file = files.new('path' => path.to_s)
build_file = file.build_file
build_file = file.buildFile
if path.extname == '.h'
build_file.settings = { 'ATTRIBUTES' => ["Public"] }
# Working around a bug in Xcode 4.2 betas, remove this once the Xcode bug is fixed:
......@@ -154,17 +174,8 @@ module Pod
end
class PBXBuildFile < PBXObject
attributes :fileRef, :settings
# Takes a PBXFileReference instance and assigns its uuid to the fileRef attribute.
def file=(file)
self.fileRef = file.uuid
end
# Returns a PBXFileReference instance corresponding to the uuid in the fileRef attribute.
def file
@project.objects[fileRef]
end
attributes :settings
belongs_to :file, :uuid => :fileRef
end
class PBXBuildPhase < PBXObject
......@@ -204,8 +215,8 @@ module Pod
has_many :buildPhases, :class => PBXBuildPhase
has_many :dependencies, :singular => :dependency # TODO :class => ?
has_many :buildRules # TODO :class => ?
has_one :buildConfigurationList
has_one :product, :uuid => :productReference
belongs_to :buildConfigurationList
belongs_to :product, :uuid => :productReference
def initialize(project, *)
super
......@@ -230,11 +241,15 @@ module Pod
end
end
end
def buildConfigurations
buildConfigurationList.buildConfigurations
end
end
class XCBuildConfiguration < PBXObject
attribute :buildSettings
has_one :baseConfiguration
belongs_to :baseConfiguration
def initialize(*)
super
......@@ -259,19 +274,6 @@ module Pod
end
end
# Missing constants that begin with either `PBX' or `XC' are assumed to be
# valid classes in a Xcode project. A new PBXObject subclass is created
# for the constant and returned.
def self.const_missing(name)
if name =~ /^(PBX|XC)/
klass = Class.new(PBXObject)
const_set(name, klass)
klass
else
super
end
end
class PBXObjectList
include Enumerable
......
......@@ -180,25 +180,22 @@ else
installer = SpecHelper::Installer.new(spec)
installer.install!
installer.configure_project(projpath)
xcworkspace = temporary_directory + 'ASIHTTPRequest.xcworkspace'
workspace = Pod::Xcode::Workspace.new_from_xcworkspace(xcworkspace)
workspace.projpaths.sort.should == ['ASIHTTPRequest.xcodeproj', 'Pods/Pods.xcodeproj']
project = Pod::Xcode::Project.new(projpath)
config = project.files.find { |f| f.path =~ /Pods.xcconfig$/ }
config.should.not.equal nil
copy_resources = project.objects.select_by_class(Pod::Xcode::Project::PBXShellScriptBuildPhase).find do |ss|
ss.shellScript['PodsResources.sh']
end
copy_resources.should.not.equal nil
libPods = project.files.find { |f| f.name == 'libPods.a' }
project.targets.each do |target|
bases = target.buildConfigurationList.buildConfigurations.map(&:baseConfigurationReference)
bases.uniq[0].uuid.should == config.uuid
target.buildPhases.map(&:uuid).should.include copy_resources.uuid
end
lib = project.files.find { |f| f.path =~ /libPods.a$/ }
lib.should.not.equal nil
project.objects.select_by_class(Pod::Xcode::Project::PBXFrameworksBuildPhase).each do |build_phase|
build_phase.files.map(&:uuid).should.include lib.build_file.uuid
target.buildConfigurations.each do |config|
config.baseConfiguration.path.should == 'Pods/Pods.xcconfig'
end
link = target.buildPhases.find { |phase| phase.is_a?(Pod::Xcode::Project::PBXFrameworksBuildPhase) }
link.files.map(&:uuid).should.include libPods.buildFile.uuid
target.buildPhases.to_a.last.shellScript.should == "${SRCROOT}/Pods/PodsResources.sh\n"
end
end
......
......@@ -232,7 +232,7 @@ describe "Pod::Xcode::Project" do
it "adds a new PBXBuildFile to the objects hash when a new PBXFileReference is created" do
file = @project.files.new('name' => '/some/source/file.h')
build_file = file.build_file
build_file = file.buildFile
build_file.file = file
build_file.fileRef.should == file.uuid
build_file.isa.should == 'PBXBuildFile'
......
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