Commit b2589060 authored by Eloy Duran's avatar Eloy Duran

Add specs for adding individual pods to groups in the Xcode project.

parent 0d580d52
......@@ -17,18 +17,17 @@ module Pod
end
def source_files
source_files = Hash.new
source_files = {}
build_specification_sets.each do |set|
spec = set.specification
spec_files = []
source_files[spec.name] = []
spec.source_files.each do |pattern|
pattern = spec.pod_destroot + pattern
pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory?
pattern.glob.each do |file|
spec_files << file.relative_path_from(config.project_pods_root)
source_files[spec.name] << file.relative_path_from(config.project_pods_root)
end
end
source_files[spec.name] = spec_files
end
source_files
end
......
......@@ -41,16 +41,19 @@ module Pod
find_objects(conditions).first
end
IGNORE_GROUPS = ['Pods', 'Frameworks', 'Products', 'Supporting Files']
def source_files
conditions = { 'isa' => 'PBXFileReference', 'sourceTree' => 'SOURCE_ROOT' }
find_objects(conditions).map do |_, object|
if %w{ .h .m .mm .c .cpp }.include?(File.extname(object['path']))
Pathname.new(object['path'])
source_files = {}
find_objects('isa' => 'PBXGroup').each do |_, object|
next if object['name'].nil? || IGNORE_GROUPS.include?(object['name'])
source_files[object['name']] = object['children'].map do |uuid|
Pathname.new(objects[uuid]['path'])
end
end.compact
end
source_files
end
def add_source_file(file, group = 'Pods', compiler_flags = nil)
def add_source_file(file, group, compiler_flags = nil)
file_ref_uuid = add_file_reference(file, 'SOURCE_ROOT')
add_object_to_group(file_ref_uuid, group)
if file.extname == '.h'
......@@ -75,6 +78,7 @@ module Pod
"children" => []
})
add_object_to_group(group_uuid, 'Pods')
group_uuid
end
def create_in(pods_root)
......
......@@ -17,7 +17,7 @@ describe "Pod::Installer" do
[
'ASIHTTPRequest',
['Classes'],
"{Classes,External/Reachability}/*.{h,m}",
{ 'ASIHTTPRequest' => "Classes/*.{h,m}", 'Reachability' => "External/Reachability/*.{h,m}" },
{
"USER_HEADER_SEARCH_PATHS" => "$(BUILT_PRODUCTS_DIR)/Pods",
"ALWAYS_SEARCH_USER_PATHS" => "YES",
......@@ -25,39 +25,44 @@ describe "Pod::Installer" do
"-framework MobileCoreServices -l z.1"
}
],
[
'Reachability',
["External/Reachability/*.h", "External/Reachability/*.m"],
"External/Reachability/*.{h,m}",
{
"USER_HEADER_SEARCH_PATHS" => "$(BUILT_PRODUCTS_DIR)/Pods",
"ALWAYS_SEARCH_USER_PATHS" => "YES"
}
],
[
'ASIWebPageRequest',
['**/ASIWebPageRequest.*'],
"{Classes,Classes/ASIWebPageRequest,External/Reachability}/*.{h,m}",
{
"USER_HEADER_SEARCH_PATHS" => "$(BUILT_PRODUCTS_DIR)/Pods",
"ALWAYS_SEARCH_USER_PATHS" => "YES",
"HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2",
"OTHER_LDFLAGS" => "-l xml2.2.7.3 -framework SystemConfiguration " \
"-framework CFNetwork -framework MobileCoreServices -l z.1"
}
],
].each do |name, patterns, expected_pattern, xcconfig|
#[
#'Reachability',
#["External/Reachability/*.h", "External/Reachability/*.m"],
#{ 'Reachability' => "External/Reachability/*.{h,m}", },
#{
#"USER_HEADER_SEARCH_PATHS" => "$(BUILT_PRODUCTS_DIR)/Pods",
#"ALWAYS_SEARCH_USER_PATHS" => "YES"
#}
#],
#[
#'ASIWebPageRequest',
#['**/ASIWebPageRequest.*'],
#{ 'ASIHTTPRequest' => "Classes/*.{h,m}", 'ASIWebPageRequest' => "Classes/ASIWebPageRequest/*.{h,m}", 'Reachability' => "External/Reachability/*.{h,m}" },
#{
#"USER_HEADER_SEARCH_PATHS" => "$(BUILT_PRODUCTS_DIR)/Pods",
#"ALWAYS_SEARCH_USER_PATHS" => "YES",
#"HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2",
#"OTHER_LDFLAGS" => "-l xml2.2.7.3 -framework SystemConfiguration " \
#"-framework CFNetwork -framework MobileCoreServices -l z.1"
#}
#],
].each do |name, patterns, expected_patterns, xcconfig|
Pod::Source.reset!
Pod::Spec::Set.reset!
installer = Pod::Installer.new(Pod::Spec.new { |s| s.dependency(name); s.source_files = *patterns })
expected = (stubbed_destroot(installer) + expected_pattern).glob.map do |file|
destroot = stubbed_destroot(installer)
installer.generate_project
expected_patterns.each do |name, pattern|
expected = (destroot + pattern).glob.map do |file|
file.relative_path_from(config.project_pods_root)
end
installer.generate_project
installer.source_files.size.should == expected.size
installer.source_files.sort.should == expected.sort
installer.xcodeproj.source_files.size.should == expected.size
installer.xcodeproj.source_files.sort.should == expected.sort
installer.source_files[name].size.should == expected.size
installer.source_files[name].sort.should == expected.sort
installer.xcodeproj.source_files[name].size.should == expected.size
installer.xcodeproj.source_files[name].sort.should == expected.sort
end
installer.xcconfig.to_hash.should == xcconfig
end
end
......
......@@ -13,23 +13,40 @@ describe "Pod::Xcode::Project" do
@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 = []
it "adds a group to the `Pods' group" do
@project.add_group('JSONKit')
@project.find_object({
'isa' => 'PBXGroup',
'name' => 'JSONKit',
'sourceTree' => '<group>',
'children' => []
}).should.not == nil
end
it "adds an `m' or `c' file as a build file, adds it to the specified group, and adds it to the `sources build' phase list" do
file_ref_uuids, build_file_uuids = [], []
group_uuid = @project.add_group('SomeGroup')
group = @project.to_hash['objects'][group_uuid]
%w{ m mm c cpp }.each do |ext|
path = Pathname.new("path/to/file.#{ext}")
file_ref_uuid = @project.add_source_file(path)
file_ref_uuid = @project.add_source_file(path, 'SomeGroup')
@project.to_hash['objects'][file_ref_uuid].should == {
'name' => path.basename.to_s,
'isa' => 'PBXFileReference',
'sourceTree' => 'SOURCE_ROOT',
'path' => path.to_s
}
file_ref_uuids << file_ref_uuid
build_file_uuid, _ = @project.find_object({
'isa' => 'PBXBuildFile',
'fileRef' => file_ref_uuid
})
build_file_uuids << build_file_uuid
group['children'].should == file_ref_uuids
_, object = @project.find_object('isa' => 'PBXSourcesBuildPhase')
object['files'].should == build_file_uuids
......@@ -42,7 +59,7 @@ describe "Pod::Xcode::Project" 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, '-fno-obj-arc')
file_ref_uuid = @project.add_source_file(path, 'Pods', '-fno-obj-arc')
@project.find_object({
'isa' => 'PBXBuildFile',
'fileRef' => file_ref_uuid,
......@@ -52,8 +69,9 @@ describe "Pod::Xcode::Project" do
end
it "adds a `h' file as a build file and adds it to the `headers build' phase list" do
@project.add_group('SomeGroup')
path = Pathname.new("path/to/file.h")
file_ref_uuid = @project.add_source_file(path)
file_ref_uuid = @project.add_source_file(path, 'SomeGroup')
@project.to_hash['objects'][file_ref_uuid].should == {
'name' => path.basename.to_s,
'isa' => 'PBXFileReference',
......@@ -82,8 +100,9 @@ describe "Pod::Xcode::Project" do
end
it "returns all source files" do
@project.add_group('SomeGroup')
files = [Pathname.new('/some/file.h'), Pathname.new('/some/file.m')]
files.each { |file| @project.add_source_file(file) }
@project.source_files.sort.should == files.sort
files.each { |file| @project.add_source_file(file, 'SomeGroup') }
@project.source_files['SomeGroup'].sort.should == files.sort
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