Commit f831dc85 authored by Eloy Duran's avatar Eloy Duran

Finish creating a static iOS library programmatically and make all specs green.

parent beb77b4a
......@@ -37,7 +37,11 @@ module Pod
unless @xcodeproj
@xcodeproj = Xcode::Project.new(template.xcodeproj_path)
target = @xcodeproj.targets.new_static_library('Pods')
p target.attributes
# TODO should create one programatically
xcconfig_file = @xcodeproj.files.find { |file| file.path == 'Pods.xcconfig' }
target.buildConfigurations.each do |config|
config.baseConfiguration = xcconfig_file
end
end
@xcodeproj
end
......@@ -46,21 +50,22 @@ module Pod
def generate_project
puts "==> Generating Xcode project and xcconfig" unless config.silent?
user_header_search_paths = []
target = xcodeproj.targets.first
build_specifications.each do |spec|
xcconfig.merge!(spec.xcconfig)
group = xcodeproj.add_pod_group(spec.name)
# Only add implementation files to the compile phase
spec.implementation_files.each do |file|
group.add_source_file(file, nil, spec.compiler_flags)
group << target.add_source_file(file, nil, spec.compiler_flags)
end
# Add header files to a `copy header build phase` for each destination
# directory in the pod's header directory.
spec.copy_header_mappings.each do |header_dir, files|
copy_phase = xcodeproj.add_copy_header_build_phase(spec.name, header_dir)
copy_phase = target.copy_files_build_phases.new_pod_dir(spec.name, header_dir)
files.each do |file|
group.add_source_file(file, copy_phase)
group << target.add_source_file(file, copy_phase)
end
end
......@@ -71,7 +76,9 @@ module Pod
end
def copy_resources_script
@copy_resources_script ||= Xcode::CopyResourcesScript.new(build_specifications.map { |spec| spec.expanded_resources }.flatten)
@copy_resources_script ||= Xcode::CopyResourcesScript.new(build_specifications.map do |spec|
spec.expanded_resources
end.flatten)
end
def bridge_support_generator
......@@ -136,7 +143,7 @@ module Pod
'sourceTree' => 'BUILT_PRODUCTS_DIR'
})
app_project.objects.select_by_class(Xcode::Project::PBXFrameworksBuildPhase).each do |build_phase|
build_phase.files << libfile.buildFile
build_phase.files << libfile.buildFiles.new
end
app_project.main_group << libfile
......
......@@ -77,7 +77,13 @@ module Pod
attributes :isa, :name
def initialize(project, uuid, attributes)
@project, @uuid, @attributes = project, uuid || generate_uuid, attributes
@project, @attributes = project, attributes
unless uuid
# Add new objects to the main hash with a unique UUID
begin; uuid = generate_uuid; end while @project.objects_hash.has_key?(uuid)
@project.objects_hash[uuid] = @attributes
end
@uuid = uuid
self.isa ||= self.class.isa
end
......@@ -139,7 +145,6 @@ module Pod
self.sourceTree ||= 'SOURCE_ROOT'
if is_new
@project.main_group.children << self
@project.build_files.new.file = self
end
end
......@@ -293,6 +298,10 @@ module Pod
buildPhases.select_by_class(PBXCopyFilesBuildPhase)
end
def frameworks_build_phases
buildPhases.select_by_class(PBXFrameworksBuildPhase)
end
def add_source_file(path, copy_header_phase = nil, compiler_flags = nil)
file = @project.files.new('path' => path.to_s)
buildFile = file.buildFiles.new
......@@ -313,7 +322,7 @@ module Pod
class XCBuildConfiguration < PBXObject
attribute :buildSettings
belongs_to :baseConfiguration
belongs_to :baseConfiguration, :uuid => :baseConfigurationReference
def initialize(*)
super
......@@ -323,6 +332,9 @@ module Pod
'GCC_PRECOMPILE_PREFIX_HEADER' => 'YES',
'GCC_PREFIX_HEADER' => 'Pods-Prefix.pch',
'GCC_VERSION' => 'com.apple.compilers.llvm.clang.1_0',
# TODO not sure if this specific flag is needed, but the OTHER_LDFLAGS option *has* to
# be overriden so that it does not use those from the xcconfig (for CocoaPods specific).
'OTHER_LDFLAGS' => '-ObjC',
'PRODUCT_NAME' => '$(TARGET_NAME)',
'SKIP_INSTALL' => 'YES',
}.merge(buildSettings || {})
......@@ -338,6 +350,10 @@ module Pod
end
end
class PBXProject < PBXObject
has_many :targets, :class => PBXNativeTarget
end
class PBXObjectList
include Enumerable
......@@ -345,7 +361,7 @@ module Pod
@represented_class = represented_class
@project = project
@scoped_hash = scoped.is_a?(Array) ? scoped.inject({}) { |h, o| h[o.uuid] = o.attributes; h } : scoped
@callback = new_object_callback || lambda { |o| add_object(o) }
@callback = new_object_callback
end
def empty?
......@@ -360,7 +376,6 @@ module Pod
def add(klass, hash = {})
object = klass.new(@project, nil, hash)
add_object(object)
@callback.call(object) if @callback
object
end
......@@ -410,21 +425,12 @@ module Pod
object = @represented_class.send(name, @project, *args)
# The callbacks are only for PBXObject instances instantiated
# from the class method that we forwarded the message to.
if object.is_a?(PBXObject)
add_object(object)
@callback.call(object)
end
@callback.call(object) if object.is_a?(PBXObject)
object
else
super
end
end
private
def add_object(object)
@project.objects_hash[object.uuid] = object.attributes
end
end
def initialize(xcodeproj)
......@@ -444,13 +450,17 @@ module Pod
@objects ||= PBXObjectList.new(PBXObject, self, objects_hash)
end
# TODO This should probably be the actual Project class (PBXProject).
def project_object
objects[@plist['rootObject']]
end
def groups
objects.select_by_class(PBXGroup)
end
def main_group
project = objects[@plist['rootObject']]
objects[project.attributes['mainGroup']]
objects[project_object.attributes['mainGroup']]
end
# Shortcut access to the `Pods' PBXGroup.
......@@ -472,7 +482,9 @@ module Pod
end
def targets
objects.select_by_class(PBXNativeTarget)
# Better to check the project object for targets to ensure they are
# actually there so the project will work
project_object.targets
end
IGNORE_GROUPS = ['Pods', 'Frameworks', 'Products', 'Supporting Files']
......
......@@ -192,10 +192,11 @@ else
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
phase = target.frameworks_build_phases.first
phase.files.map { |buildFile| buildFile.file }.should.include libPods
target.buildPhases.to_a.last.shellScript.should == "${SRCROOT}/Pods/PodsResources.sh\n"
# should be the last phase
target.buildPhases.last.shellScript.should == "${SRCROOT}/Pods/PodsResources.sh\n"
end
end
......
......@@ -33,7 +33,7 @@ describe "Pod::Xcode::Project" do
describe "PBXObject" do
before do
@object = Pod::Xcode::Project::PBXObject.new(@project.objects, nil, 'name' => 'AnObject')
@object = Pod::Xcode::Project::PBXObject.new(@project, nil, 'name' => 'AnObject')
end
it "merges the class name into the attributes" do
......@@ -52,6 +52,10 @@ describe "Pod::Xcode::Project" do
@object.uuid.size.should == 24
@object.uuid.should == @object.uuid
end
it "adds the object to the objects hash" do
@project.objects_hash[@object.uuid].should == @object.attributes
end
end
describe "a PBXFileReference" do
......@@ -180,8 +184,7 @@ describe "Pod::Xcode::Project" do
'DSTROOT' => '/tmp/Pods.dst',
'GCC_PRECOMPILE_PREFIX_HEADER' => 'YES',
'GCC_PREFIX_HEADER' => 'Pods-Prefix.pch',
# Removed from the default XCBuildConfiguration#buildSettings
#'OTHER_LDFLAGS' => '-ObjC',
'OTHER_LDFLAGS' => '-ObjC',
'GCC_VERSION' => 'com.apple.compilers.llvm.clang.1_0',
'PRODUCT_NAME' => '$(TARGET_NAME)',
'SKIP_INSTALL' => 'YES',
......
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