Skip to content

Commit

Permalink
[Project] #add_system_framework now links against DEVELOPER_DIR.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Dec 18, 2012
1 parent 5237d20 commit 99194c3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ GEM
multi_json (~> 1.0)
bacon (1.1.0)
colored (1.2)
github-markup (0.7.4)
github-markup (0.7.5)
i18n (0.6.1)
kicker (2.6.1)
listen
listen (0.6.0)
multi_json (1.3.7)
multi_json (1.5.0)
posix-spawn (0.3.6)
pygments.rb (0.3.2)
pygments.rb (0.3.3)
posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.1.0)
rake (10.0.2)
rake (10.0.3)
redcarpet (2.2.2)
yajl-ruby (1.1.0)
yard (0.8.3)
Expand Down
8 changes: 8 additions & 0 deletions lib/xcodeproj/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ module Xcodeproj
#
module Constants

# The last known iOS SDK (stable).
#
LAST_KNOWN_IOS_SDK = '6.0'

# The last known OS X SDK (stable).
#
LAST_KNOWN_OSX_SDK = '10.8'

# The last known archive version to Xcodeproj.
#
LAST_KNOWN_ARCHIVE_VERSION = 1
Expand Down
36 changes: 25 additions & 11 deletions lib/xcodeproj/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def groups
# frameworks.name #=> 'Frameworks'
# main_group.children.include? frameworks #=> True
#
# @param [String] group_path @see PBXGroup#[]
# @param [String] group_path @see MobileCoreServices
#
# @return [PBXGroup] the group at the given subpath.
#
Expand Down Expand Up @@ -438,26 +438,40 @@ def new_group(name, path = nil)
# The file reference can then be added to the build files of a
# {PBXFrameworksBuildPhase}.
#
# @example
# @example Adding QuartzCore
#
# framework = project.add_system_framework('QuartzCore')
# framework = project.add_system_framework('QuartzCore', :ios)
#
# target = project.targets.first
# build_phase = target.frameworks_build_phases.first
# build_phase.files << framework.buildFiles.new
#
# @param [String] name The name of a framework in the SDK System
# directory.
# @return [PBXFileReference] The file reference object.
# @param [String] name
# The name of a framework.
#
# @param [Symbol] platform
# The platform reppresenting the SDK.
#
# @note This method adds a reference to the highest know SDK for the
# given platform.
#
def add_system_framework(name)
path = "System/Library/Frameworks/#{name}.framework"
if file = frameworks_group.files.first { |f| f.path == path }
# @return [PBXFileReference] The generated file reference.
#
def add_system_framework(name, platform)
if platform == :ios
base_dir = "Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS#{Constants::LAST_KNOWN_IOS_SDK}.sdk/"
elsif platform == :osx
base_dir = "Platforms/MacOSX.platform/Developer/SDKs/MacOSX#{Constants::LAST_KNOWN_OSX_SDK}.sdk/"
end
path = base_dir + "System/Library/Frameworks/#{name}.framework"

if file = frameworks_group.files.find { |f| f.path == path }
file
else
framework_ref = frameworks_group.new_file(path)
framework_ref.name = "#{name}.framework"
framework_ref.source_tree = 'SDKROOT'
framework_ref.source_tree = 'DEVELOPER_DIR'
framework_ref.last_known_file_type = "wrapper.framework"
framework_ref
end
end
Expand Down Expand Up @@ -486,7 +500,7 @@ def add_system_framework(name)
# Can be `:ios` or `:osx`.
#
def new_target(type, name, platform)
add_system_framework(platform == :ios ? 'Foundation' : 'Cocoa')
add_system_framework(platform == :ios ? 'Foundation' : 'Cocoa', platform)

# Target
target = new(PBXNativeTarget)
Expand Down
2 changes: 1 addition & 1 deletion spec/project/object/native_target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module ProjectSpecs
end

it "adds a framework in a group named 'Frameworks' in the main group to a new target" do
framework = @project.add_system_framework('QuartzCore')
framework = @project.add_system_framework('QuartzCore', :ios)
framework_files = @project.frameworks_group.files
target = @project.new_target(:static_library, 'Pods2', :ios)
target.frameworks_build_phase.files_references.should == framework_files
Expand Down
10 changes: 5 additions & 5 deletions spec/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,19 @@ module ProjectSpecs

it "adds a file reference for a system framework, to the Frameworks group" do
group = @project['Frameworks']
file = @project.add_system_framework('QuartzCore')
file = @project.add_system_framework('QuartzCore', :ios)
file.group.should == group
file.name.should == 'QuartzCore.framework'
file.path.should == 'System/Library/Frameworks/QuartzCore.framework'
file.source_tree.should == 'SDKROOT'
file.path.should.match %r|Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.+.sdk/System/Library/Frameworks/QuartzCore.framework|
file.source_tree.should == 'DEVELOPER_DIR'
end

it "does not add a system framework if it already exists in the project" do
file = @project.add_system_framework('Foundation')
file = @project.add_system_framework('Foundation', :ios)
file.name.should == 'Foundation.framework'
before = @project.frameworks_group.files.size

file = @project.add_system_framework('Foundation')
file = @project.add_system_framework('Foundation', :ios)
file.name.should == 'Foundation.framework'
@project.frameworks_group.files.size.should == before
end
Expand Down

0 comments on commit 99194c3

Please sign in to comment.