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