Commit d1ba2e80 authored by Eloy Duran's avatar Eloy Duran

+ xcode project spec

parent 3744f691
......@@ -40,8 +40,8 @@ module Pod
})
end
def xproj
@xproj ||= Xcode::Project.static_library
def xcodeproj
@xcodeproj ||= Xcode::Project.ios_static_library
end
def install!
......@@ -64,7 +64,7 @@ module Pod
def generate_project
puts "==> Creating Pods project files" unless config.silent?
source_files.each { |file| xproj.add_source_file(file) }
source_files.each { |file| xcodeproj.add_source_file(file) }
build_specification_sets.each do |set|
xcconfig << set.specification.read(:xcconfig)
end
......
......@@ -6,7 +6,7 @@ module Pod
TEMPLATES_DIR = Pathname.new(File.expand_path('../../../../xcode-project-templates', __FILE__))
# TODO see if we really need different templates for iOS and OS X
def self.static_library
def self.ios_static_library
new TEMPLATES_DIR + 'cocoa-touch-static-library'
end
......@@ -20,6 +20,16 @@ module Pod
'Pods.xcodeproj/project.pbxproj'
end
def to_hash
@template
end
def find_object(conditions)
objects.find do |_, object|
object.objectsForKeys(conditions.keys, notFoundMarker:Object.new) == conditions.values
end
end
def add_source_file(file)
file_ref_uuid = add_file_reference(file, 'SOURCE_ROOT')
add_file_to_group(file_ref_uuid, 'Pods')
......@@ -30,23 +40,7 @@ module Pod
build_file_uuid = add_build_file(file_ref_uuid)
add_file_to_list('PBXSourcesBuildPhase', build_file_uuid)
end
end
def add_framework(path)
file_ref_uuid = add_file_reference(path, 'SDKROOT')
add_file_to_group(file_ref_uuid, 'Frameworks')
build_file_uuid = add_build_file(file_ref_uuid)
add_file_to_list('PBXFrameworksBuildPhase', build_file_uuid)
end
def add_header_search_path(path)
objects_by_isa('XCBuildConfiguration').each do |_, object|
(object['buildSettings']['HEADER_SEARCH_PATHS'] ||= []) << path
end
end
def to_hash
@template
file_ref_uuid
end
def create_in(pods_root)
......
require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Xcode::Project" do
extend SpecHelper::TemporaryDirectory
before do
@project = Pod::Xcode::Project.ios_static_library
end
it "returns an instance initialized from the iOS static library template" do
template_dir = Pod::Xcode::Project::TEMPLATES_DIR + 'cocoa-touch-static-library'
template_file = (template_dir + 'Pods.xcodeproj/project.pbxproj').to_s
@project.to_hash.should == NSDictionary.dictionaryWithContentsOfFile(template_file)
end
it "adds an `m' or `c' file as a build file and adds it to the `sources build' phase list" do
build_file_uuids = []
%w{ m mm c cpp }.each do |ext|
path = Pathname.new("path/to/file.#{ext}")
file_ref_uuid = @project.add_source_file(path)
@project.to_hash['objects'][file_ref_uuid].should == {
'name' => path.basename.to_s,
'isa' => 'PBXFileReference',
'sourceTree' => 'SOURCE_ROOT',
'path' => path.to_s
}
build_file_uuid, _ = @project.find_object({
'isa' => 'PBXBuildFile',
'fileRef' => file_ref_uuid
})
build_file_uuids << build_file_uuid
_, object = @project.find_object('isa' => 'PBXSourcesBuildPhase')
object['files'].should == build_file_uuids
_, object = @project.find_object('isa' => 'PBXHeadersBuildPhase')
object['files'].should.not.include build_file_uuid
end
end
it "adds a `h' file as a build file and adds it to the `headers build' phase list" do
path = Pathname.new("path/to/file.h")
file_ref_uuid = @project.add_source_file(path)
@project.to_hash['objects'][file_ref_uuid].should == {
'name' => path.basename.to_s,
'isa' => 'PBXFileReference',
'sourceTree' => 'SOURCE_ROOT',
'path' => path.to_s
}
build_file_uuid, _ = @project.find_object({
'isa' => 'PBXBuildFile',
'fileRef' => file_ref_uuid
})
_, object = @project.find_object('isa' => 'PBXHeadersBuildPhase')
object['files'].should == [build_file_uuid]
_, object = @project.find_object('isa' => 'PBXSourcesBuildPhase')
object['files'].should.not.include build_file_uuid
end
it "saves the template with the adjusted project" do
@project.create_in(temporary_directory)
(temporary_directory + 'Pods-Prefix.pch').should.exist
(temporary_directory + 'Pods.xcconfig').should.exist
project_file = (temporary_directory + 'Pods.xcodeproj/project.pbxproj')
NSDictionary.dictionaryWithContentsOfFile(project_file.to_s).should == @project.to_hash
end
end
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