Permalink
Browse files

Only ever add a system framework once.

  • Loading branch information...
1 parent 4c49ed5 commit ae2d4b95cc5ee6c370ecec305e4040e2f3c6cec6 @alloy alloy committed Jul 2, 2012
Showing with 34 additions and 6 deletions.
  1. +11 −6 lib/xcodeproj/project.rb
  2. +23 −0 spec/project_spec.rb
View
17 lib/xcodeproj/project.rb
@@ -167,12 +167,17 @@ def files
# directory.
# @return [PBXFileReference] The file reference object.
def add_system_framework(name)
- group = groups.where('name' => 'Frameworks') || groups.new('name' => 'Frameworks')
- group.files.new({
- 'name' => "#{name}.framework",
- 'path' => "System/Library/Frameworks/#{name}.framework",
- 'sourceTree' => 'SDKROOT'
- })
+ path = "System/Library/Frameworks/#{name}.framework"
+ if file = files.where(:path => path)
+ file
+ else
+ group = groups.where('name' => 'Frameworks') || groups.new('name' => 'Frameworks')
+ group.files.new({
+ 'name' => "#{name}.framework",
+ 'path' => path,
+ 'sourceTree' => 'SDKROOT'
+ })
+ end
end
# @return [PBXObjectList<XCBuildConfiguration] A list of project wide
View
23 spec/project_spec.rb
@@ -81,6 +81,29 @@ module ProjectSpecs
@project.build_settings('Release').should == {}
end
+ it "adds a file reference, for a system framework, to the Frameworks group" do
+ group = @project.groups.where(:name => 'Frameworks')
+ file = @project.add_system_framework('QuartzCore')
+ file.group.should == group
+ file.name.should == 'QuartzCore.framework'
+ file.path.should == 'System/Library/Frameworks/QuartzCore.framework'
+ file.source_tree.should == 'SDKROOT'
+ end
+
+ it "does not add a system framework if it already exists in the project" do
+ before = @project.files.size
+
+ file = @project.add_system_framework('Foundation')
+ file.name.should == 'Foundation.framework'
+ @project.files.size.should == before
+
+ @project.groups.where(:name => 'Frameworks').name = 'Renamed Frameworks Group'
+ file = @project.add_system_framework('Foundation')
+ file.name.should == 'Foundation.framework'
+ @project.files.size.should == before
+ end
+
+ # TODO this should go to the native target spec
it "adds an `m' or `c' file to the `sources build' phase list" do
%w{ m mm c cpp }.each do |ext|
path = Pathname.new("path/to/file.#{ext}")

0 comments on commit ae2d4b9

Please sign in to comment.