Skip to content
Browse files

[Project] Take into account SDKROOT while adding frameworks.

  • Loading branch information...
1 parent d2bd182 commit 72b587172e84cfd38aa9ce70c5f6075aca19973c @fabiopelosin fabiopelosin committed Dec 19, 2012
View
2 Gemfile
@@ -4,7 +4,9 @@ gemspec
group :development do
gem "rake"
+ gem "mocha", "~> 0.11.4"
gem "bacon"
+ gem "mocha-on-bacon"
gem "kicker"
end
View
7 Gemfile.lock
@@ -18,6 +18,11 @@ GEM
kicker (2.6.1)
listen
listen (0.6.0)
+ metaclass (0.0.1)
+ mocha (0.11.4)
+ metaclass (~> 0.0.1)
+ mocha-on-bacon (0.2.1)
+ mocha (>= 0.9.8)
multi_json (1.5.0)
posix-spawn (0.3.6)
pygments.rb (0.3.3)
@@ -35,6 +40,8 @@ DEPENDENCIES
bacon
github-markup
kicker
+ mocha (~> 0.11.4)
+ mocha-on-bacon
pygments.rb
rake
redcarpet
View
58 lib/xcodeproj/project.rb
@@ -449,19 +449,29 @@ def new_group(name, path = nil)
# @param [String] name
# The name of a framework.
#
- # @param [Symbol] platform
- # The platform reppresenting the SDK.
+ # @param [PBXNativeTarget] target
+ # The target for which to add the framework.
#
# @note This method adds a reference to the highest know SDK for the
# given platform.
#
# @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/"
+ def add_system_framework(name, target)
+ sdk = target.sdk
+ raise "Unable to find and SDK for the target `#{target.name}`" unless sdk
+ if sdk.include?('iphoneos')
+ if sdk == 'iphoneos'
+ base_dir = "Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS#{Constants::LAST_KNOWN_IOS_SDK}.sdk/"
+ else
+ base_dir = "Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS#{sdk.gsub('iphoneos', '')}.sdk/"
+ end
+ elsif sdk.include?('macosx')
+ if sdk == 'macosx'
+ base_dir = "Platforms/MacOSX.platform/Developer/SDKs/MacOSX#{Constants::LAST_KNOWN_OSX_SDK}.sdk/"
+ else
+ base_dir = "Platforms/MacOSX.platform/Developer/SDKs/MacOSX#{sdk.gsub('iphoneos', '')}.sdk/"
+ end
end
path = base_dir + "System/Library/Frameworks/#{name}.framework"
@@ -499,8 +509,7 @@ def add_system_framework(name, platform)
# the platform of the static library.
# Can be `:ios` or `:osx`.
#
- def new_target(type, name, platform)
- add_system_framework(platform == :ios ? 'Foundation' : 'Cocoa', platform)
+ def new_target(type, name, platform, deployment_target = nil)
# Target
target = new(PBXNativeTarget)
@@ -514,10 +523,14 @@ def new_target(type, name, platform)
product = products_group.new_static_library(name)
target.product_reference = product
+ # Frameworks
+ framework_name = (platform == :ios) ? 'Foundation' : 'Cocoa'
+ framework_ref = add_system_framework(framework_name, target)
+
# Build phases
target.build_phases << new(PBXSourcesBuildPhase)
frameworks_phase = new(PBXFrameworksBuildPhase)
- frameworks_group.files.each { |framework| frameworks_phase.add_file_reference(framework) }
+ frameworks_phase.add_file_reference(framework_ref)
target.build_phases << frameworks_phase
target
@@ -531,18 +544,18 @@ def new_target(type, name, platform)
#
# @return [XCConfigurationList] the generated configuration list.
#
- def configuration_list(platform)
+ def configuration_list(platform, deployment_target = nil)
cl = new(XCConfigurationList)
cl.default_configuration_is_visible = '0'
cl.default_configuration_name = 'Release'
release_conf = new(XCBuildConfiguration)
release_conf.name = 'Release'
- release_conf.build_settings = configuration_list_settings(platform, :release)
+ release_conf.build_settings = common_build_settings(:release, platform, deployment_target)
debug_conf = new(XCBuildConfiguration)
debug_conf.name = 'Debug'
- debug_conf.build_settings = configuration_list_settings(platform, :debug)
+ debug_conf.build_settings = common_build_settings(:debug, platform, deployment_target)
cl.build_configurations << release_conf
cl.build_configurations << debug_conf
@@ -560,13 +573,20 @@ def configuration_list(platform)
#
# @return [Hash] The common build settings
#
- def configuration_list_settings(platform, name)
+ def common_build_settings(type, platform, deployment_target = nil)
common_settings = Constants::COMMON_BUILD_SETTINGS
- bs = common_settings[:all].dup
- bs = bs.merge(common_settings[name])
- bs = bs.merge(common_settings[platform])
- bs = bs.merge(common_settings[[platform, name]])
- bs
+ settings = common_settings[:all].dup
+ settings.merge!(common_settings[type])
+ settings.merge!(common_settings[platform])
+ settings.merge!(common_settings[[platform, type]])
+ if deployment_target
+ if platform == :ios
+ settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
+ elsif platform == :osx
+ settings['MACOSX_DEPLOYMENT_TARGET'] = deployment_target
+ end
+ end
+ settings
end
end
View
11 lib/xcodeproj/project/object/native_target.rb
@@ -123,13 +123,16 @@ class AbstractTarget < AbstractObject
# @!group Helpers
+ def sdk
+ build_configurations.first.build_settings['SDKROOT'] \
+ || project.build_configurations.first.build_settings['SDKROOT']
+ end
+
# @return [Symbol] the name of the platform of the target.
#
def platform_name
- sdk = build_configurations.first.build_settings['SDKROOT']
- sdk ||= project.build_configurations.first.build_settings['SDKROOT']
- if sdk == 'iphoneos' then :ios
- elsif sdk == 'macosx' then :osx
+ if sdk.include? 'iphoneos' then :ios
+ elsif sdk.include? 'macosx' then :osx
end
end
View
7 spec/project/object/native_target_spec.rb
@@ -84,13 +84,6 @@ module ProjectSpecs
@target.new_shell_script_build_phase
@target.shell_script_build_phases.count.should == before + 1
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', :ios)
- framework_files = @project.frameworks_group.files
- target = @project.new_target(:static_library, 'Pods2', :ios)
- target.frameworks_build_phase.files_references.should == framework_files
- end
end
describe "A new Xcodeproj::Project::Object::PBXNativeTarget" do
View
22 spec/project_spec.rb
@@ -275,21 +275,31 @@ module ProjectSpecs
end
it "adds a file reference for a system framework, to the Frameworks group" do
+ target = stub(:sdk => 'iphoneos5.0')
group = @project['Frameworks']
- file = @project.add_system_framework('QuartzCore', :ios)
+ file = @project.add_system_framework('QuartzCore', target)
file.group.should == group
file.name.should == 'QuartzCore.framework'
- file.path.should.match %r|Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.+.sdk/System/Library/Frameworks/QuartzCore.framework|
+ file.path.should.match %r|Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/System/Library/Frameworks/QuartzCore.framework|
+ file.source_tree.should == 'DEVELOPER_DIR'
+ end
+
+ it "links system frameworks to the last knwon sdk if needed" do
+ target = stub(:sdk => 'iphoneos')
+ file = @project.add_system_framework('QuartzCore', target)
+ sdk_version = Xcodeproj::Constants::LAST_KNOWN_IOS_SDK
+ file.path.should.match %r|Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS#{sdk_version}.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', :ios)
- file.name.should == 'Foundation.framework'
+ target = stub(:sdk => 'iphoneos6.0')
+ file_1 = @project.add_system_framework('Foundation', target)
+ file_1.name.should == 'Foundation.framework'
before = @project.frameworks_group.files.size
- file = @project.add_system_framework('Foundation', :ios)
- file.name.should == 'Foundation.framework'
+ file_2 = @project.add_system_framework('Foundation', target)
+ file_2.should == file_1
@project.frameworks_group.files.size.should == before
end
View
3 spec/spec_helper.rb
@@ -1,7 +1,8 @@
require 'rubygems'
require 'bacon'
-
+require 'mocha-on-bacon'
require 'pathname'
+
ROOT = Pathname.new(File.expand_path('../../', __FILE__))
$:.unshift((ROOT + 'ext').to_s)

0 comments on commit 72b5871

Please sign in to comment.
Something went wrong with that request. Please try again.