Commit 05d0f7de authored by Fabio Pelosin's avatar Fabio Pelosin

[Generator::XCConfig] Favor composition over inheritance

parent 3488a3d7
...@@ -7,7 +7,7 @@ GIT ...@@ -7,7 +7,7 @@ GIT
GIT GIT
remote: https://github.com/CocoaPods/Core.git remote: https://github.com/CocoaPods/Core.git
revision: d8a57fcaac6b8c4feec99c1f284a5097566a63a4 revision: d5eaba7a0462494b273519160f47241b7fd60c57
branch: feature-frameworks-bundles branch: feature-frameworks-bundles
specs: specs:
cocoapods-core (0.22.3) cocoapods-core (0.22.3)
......
...@@ -42,9 +42,6 @@ module Pod ...@@ -42,9 +42,6 @@ module Pod
autoload :PrefixHeader, 'cocoapods/generator/prefix_header' autoload :PrefixHeader, 'cocoapods/generator/prefix_header'
autoload :TargetEnvironmentHeader, 'cocoapods/generator/target_environment_header' autoload :TargetEnvironmentHeader, 'cocoapods/generator/target_environment_header'
autoload :XCConfig, 'cocoapods/generator/xcconfig' autoload :XCConfig, 'cocoapods/generator/xcconfig'
autoload :AggregateXCConfig, 'cocoapods/generator/xcconfig/aggregate_xcconfig'
autoload :PublicPodXCConfig, 'cocoapods/generator/xcconfig/public_pod_xcconfig'
autoload :PrivatePodXCConfig, 'cocoapods/generator/xcconfig/private_pod_xcconfig'
end end
module Hooks module Hooks
......
...@@ -5,145 +5,12 @@ module Pod ...@@ -5,145 +5,12 @@ module Pod
# for each Pod and for each Pod target definition. The aggregates the # for each Pod and for each Pod target definition. The aggregates the
# configurations of the Pods and define target specific settings. # configurations of the Pods and define target specific settings.
# #
class XCConfig module XCConfig
# @return [Target] the target represented by this xcconfig. autoload :AggregateXCConfig, 'cocoapods/generator/xcconfig/aggregate_xcconfig'
# autoload :PublicPodXCConfig, 'cocoapods/generator/xcconfig/public_pod_xcconfig'
attr_reader :target autoload :PrivatePodXCConfig, 'cocoapods/generator/xcconfig/private_pod_xcconfig'
autoload :XCConfigHelper, 'cocoapods/generator/xcconfig/xcconfig_helper'
# @param [Target] target @see target
#
def initialize(target)
@target = target
end
# @return [Sandbox] the sandbox of this target.
#
def sandbox
target.sandbox
end
# @return [Xcodeproj::Config] The generated xcconfig.
#
attr_reader :xcconfig
# Generates and saves the xcconfig to the given path.
#
# @param [Pathname] path
# the path where the prefix header should be stored.
#
# @return [void]
#
def save_as(path)
generate.save_as(path)
end
#-----------------------------------------------------------------------#
# @!group Private helpers.
private
# @return [String] the default linker flags. `-ObjC` is always included
# while `-fobjc-arc` is included only if requested in the
# Podfile.
#
def default_ld_flags
ld_flags = '-ObjC'
if target.target_definition.podfile.set_arc_compatibility_flag? and
target.spec_consumers.any? { |consumer| consumer.requires_arc? }
ld_flags << ' -fobjc-arc'
end
ld_flags
end
# Converts an array of strings to a single string where the each string
# is surrounded by double quotes and separated by a space. Used to
# represent strings in a xcconfig file.
#
# @param [Array<String>] strings
# a list of strings.
#
# @return [String] the resulting string.
#
def quote(strings)
strings.sort.map { |s| %W|"#{s}"| }.join(" ")
end
# Configures the given Xcconfig according to the build settings of the
# given Specification.
#
# @param [Specification::Consumer] consumer
# The consumer of the specification.
#
# @param [Xcodeproj::Config] xcconfig
# The xcconfig to edit.
#
def add_spec_build_settings_to_xcconfig(consumer, xcconfig)
xcconfig.merge!(consumer.xcconfig)
xcconfig.libraries.merge(consumer.libraries)
xcconfig.frameworks.merge(consumer.frameworks)
xcconfig.weak_frameworks.merge(consumer.weak_frameworks)
add_developers_frameworks_if_needed(consumer, xcconfig)
end
# Configures the given Xcconfig with the the build settings for the given
# framework path.
#
# @param [Pathanme] framework_path
# The path of the framework.
#
# @param [Xcodeproj::Config] xcconfig
# The xcconfig to edit.
#
def add_framework_build_settings(framework_path, xcconfig)
name = File.basename(framework_path, ".framework")
dirname = File.dirname(framework_path).sub(sandbox.root.to_s, '$(PODS_ROOT)')
build_settings = {
'OTHER_LDFLAGS' => "-framework #{name}",
'FRAMEWORK_SEARCH_PATHS' => quote([dirname])
}
xcconfig.merge!(build_settings)
end
# @return [Array<String>] The search paths for the developer frameworks.
#
# @todo Inheritance should be properly handled in Xcconfigs.
#
DEVELOPER_FRAMEWORKS_SEARCH_PATHS = [
'$(inherited)',
'"$(SDKROOT)/Developer/Library/Frameworks"',
'"$(DEVELOPER_LIBRARY_DIR)/Frameworks"'
]
# Adds the search paths of the developer frameworks to the specification
# if needed. This is done because the `SenTestingKit` requires them and
# adding them to each specification which requires it is repetitive and
# error prone.
#
# @param [Specification::Consumer] consumer
# The consumer of the specification.
#
# @param [Xcodeproj::Config] xcconfig
# The xcconfig to edit.
#
# @return [void]
#
def add_developers_frameworks_if_needed(consumer, xcconfig)
if xcconfig.frameworks.include?('SenTestingKit')
search_paths = xcconfig.attributes['FRAMEWORK_SEARCH_PATHS'] ||= ''
DEVELOPER_FRAMEWORKS_SEARCH_PATHS.each do |search_path|
unless search_paths.include?(search_path)
search_paths << ' ' unless search_paths.empty?
search_paths << search_path
end
end
end
end
#-----------------------------------------------------------------------#
end end
end end
......
module Pod module Pod
module Generator module Generator
module XCConfig
# Generates the xcconfigs for the aggregate targets. # Generates the xcconfigs for the aggregate targets.
# #
class AggregateXCConfig < XCConfig class AggregateXCConfig
# @return [Target] the target represented by this xcconfig.
#
attr_reader :target
# @param [Target] target @see target
#
def initialize(target)
@target = target
end
# @return [Xcodeproj::Config] The generated xcconfig.
#
attr_reader :xcconfig
# Generates and saves the xcconfig to the given path.
#
# @param [Pathname] path
# the path where the prefix header should be stored.
#
# @return [void]
#
def save_as(path)
generate.save_as(path)
end
# Generates the xcconfig. # Generates the xcconfig.
# #
...@@ -19,17 +45,17 @@ module Pod ...@@ -19,17 +45,17 @@ module Pod
# #
def generate def generate
@xcconfig = Xcodeproj::Config.new({ @xcconfig = Xcodeproj::Config.new({
'OTHER_LDFLAGS' => default_ld_flags, 'OTHER_LDFLAGS' => XCConfigHelper.default_ld_flags(target),
'HEADER_SEARCH_PATHS' => quote(sandbox.public_headers.search_paths), 'HEADER_SEARCH_PATHS' => XCConfigHelper.quote(target.sandbox.public_headers.search_paths),
'PODS_ROOT' => target.relative_pods_root, 'PODS_ROOT' => target.relative_pods_root,
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1', 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1',
}) })
target.pod_targets.each do |pod_target| target.pod_targets.each do |pod_target|
pod_target.file_accessors.each do |file_accessor| pod_target.file_accessors.each do |file_accessor|
add_spec_build_settings_to_xcconfig(file_accessor.spec_consumer, @xcconfig) XCConfigHelper.add_spec_build_settings_to_xcconfig(file_accessor.spec_consumer, @xcconfig)
file_accessor.framework_bundles.each do |framework_bundle| file_accessor.framework_bundles.each do |framework_bundle|
add_framework_build_settings(framework_bundle, @xcconfig) XCConfigHelper.add_framework_build_settings(framework_bundle, @xcconfig, target.sandbox.root)
end end
end end
end end
...@@ -48,3 +74,4 @@ module Pod ...@@ -48,3 +74,4 @@ module Pod
end end
end end
end end
end
module Pod module Pod
module Generator module Generator
module XCConfig
# Generates the private xcconfigs for the pod targets. # Generates the private xcconfigs for the pod targets.
# #
...@@ -7,7 +8,11 @@ module Pod ...@@ -7,7 +8,11 @@ module Pod
# values of the public namespaced xcconfig with the default private # values of the public namespaced xcconfig with the default private
# configuration values required by CocoaPods. # configuration values required by CocoaPods.
# #
class PrivatePodXCConfig < XCConfig class PrivatePodXCConfig
# @return [Target] the target represented by this xcconfig.
#
attr_reader :target
# @return [Xcodeproj::Config] The public xcconfig which this one will # @return [Xcodeproj::Config] The public xcconfig which this one will
# use. # use.
...@@ -18,19 +23,35 @@ module Pod ...@@ -18,19 +23,35 @@ module Pod
# @param [Xcodeproj::Config] public_xcconfig @see public_xcconfig # @param [Xcodeproj::Config] public_xcconfig @see public_xcconfig
# #
def initialize(target, public_xcconfig) def initialize(target, public_xcconfig)
super(target) @target = target
@public_xcconfig = public_xcconfig @public_xcconfig = public_xcconfig
end end
# @return [Xcodeproj::Config] The generated xcconfig.
#
attr_reader :xcconfig
# Generates and saves the xcconfig to the given path.
#
# @param [Pathname] path
# the path where the prefix header should be stored.
#
# @return [void]
#
def save_as(path)
generate.save_as(path)
end
# Generates the xcconfig. # Generates the xcconfig.
# #
# @return [Xcodeproj::Config] # @return [Xcodeproj::Config]
# #
def generate def generate
search_pahts = target.build_headers.search_paths.concat(target.sandbox.public_headers.search_paths)
config = { config = {
'OTHER_LDFLAGS' => default_ld_flags, 'OTHER_LDFLAGS' => XCConfigHelper.default_ld_flags(target),
'PODS_ROOT' => '${SRCROOT}', 'PODS_ROOT' => '${SRCROOT}',
'HEADER_SEARCH_PATHS' => quote(target.build_headers.search_paths) + ' ' + quote(sandbox.public_headers.search_paths), 'HEADER_SEARCH_PATHS' => XCConfigHelper.quote(search_pahts),
'GCC_PREPROCESSOR_DEFINITIONS' => 'COCOAPODS=1', 'GCC_PREPROCESSOR_DEFINITIONS' => 'COCOAPODS=1',
# 'USE_HEADERMAP' => 'NO' # 'USE_HEADERMAP' => 'NO'
} }
...@@ -93,3 +114,4 @@ module Pod ...@@ -93,3 +114,4 @@ module Pod
end end
end end
end end
end
module Pod module Pod
module Generator module Generator
module XCConfig
# Generates the public xcconfigs for the pod targets. # Generates the public xcconfigs for the pod targets.
# #
...@@ -8,7 +9,21 @@ module Pod ...@@ -8,7 +9,21 @@ module Pod
# xcconfig includes the standard podspec defined values including # xcconfig includes the standard podspec defined values including
# libraries, frameworks, weak frameworks and xcconfig overrides. # libraries, frameworks, weak frameworks and xcconfig overrides.
# #
class PublicPodXCConfig < XCConfig class PublicPodXCConfig
# @return [Target] the target represented by this xcconfig.
#
attr_reader :target
# @param [Target] target @see target
#
def initialize(target)
@target = target
end
# @return [Xcodeproj::Config] The generated xcconfig.
#
attr_reader :xcconfig
# Generates and saves the xcconfig to the given path. # Generates and saves the xcconfig to the given path.
# #
...@@ -28,9 +43,9 @@ module Pod ...@@ -28,9 +43,9 @@ module Pod
def generate def generate
@xcconfig = Xcodeproj::Config.new @xcconfig = Xcodeproj::Config.new
target.file_accessors.each do |file_accessor| target.file_accessors.each do |file_accessor|
add_spec_build_settings_to_xcconfig(file_accessor.spec_consumer, @xcconfig) XCConfigHelper.add_spec_build_settings_to_xcconfig(file_accessor.spec_consumer, @xcconfig)
file_accessor.framework_bundles.each do |framework_bundle| file_accessor.framework_bundles.each do |framework_bundle|
add_framework_build_settings(framework_bundle, @xcconfig) XCConfigHelper.add_framework_build_settings(framework_bundle, @xcconfig, target.sandbox.root)
end end
end end
@xcconfig @xcconfig
...@@ -41,3 +56,4 @@ module Pod ...@@ -41,3 +56,4 @@ module Pod
end end
end end
end end
end
module Pod
module Generator
module XCConfig
# Stores the shared logic of the classes of the XCConfig module.
#
module XCConfigHelper
# Converts an array of strings to a single string where the each string
# is surrounded by double quotes and separated by a space. Used to
# represent strings in a xcconfig file.
#
# @param [Array<String>] strings
# a list of strings.
#
# @return [String] the resulting string.
#
def self.quote(strings)
strings.sort.map { |s| %W|"#{s}"| }.join(" ")
end
# @return [String] the default linker flags. `-ObjC` is always included
# while `-fobjc-arc` is included only if requested in the
# Podfile.
#
def self.default_ld_flags(target)
ld_flags = '-ObjC'
if target.target_definition.podfile.set_arc_compatibility_flag? and
target.spec_consumers.any? { |consumer| consumer.requires_arc? }
ld_flags << ' -fobjc-arc'
end
ld_flags
end
# Configures the given Xcconfig according to the build settings of the
# given Specification.
#
# @param [Specification::Consumer] consumer
# The consumer of the specification.
#
# @param [Xcodeproj::Config] xcconfig
# The xcconfig to edit.
#
def self.add_spec_build_settings_to_xcconfig(consumer, xcconfig)
xcconfig.merge!(consumer.xcconfig)
xcconfig.libraries.merge(consumer.libraries)
xcconfig.frameworks.merge(consumer.frameworks)
xcconfig.weak_frameworks.merge(consumer.weak_frameworks)
add_developers_frameworks_if_needed(xcconfig)
end
# Configures the given Xcconfig with the the build settings for the given
# framework path.
#
# @param [Pathanme] framework_path
# The path of the framework.
#
# @param [Xcodeproj::Config] xcconfig
# The xcconfig to edit.
#
def self.add_framework_build_settings(framework_path, xcconfig, sandbox_root)
name = File.basename(framework_path, ".framework")
dirname = File.dirname(framework_path).sub(sandbox_root.to_s, '$(PODS_ROOT)')
build_settings = {
'OTHER_LDFLAGS' => "-framework #{name}",
'FRAMEWORK_SEARCH_PATHS' => quote([dirname])
}
xcconfig.merge!(build_settings)
end
# @return [Array<String>] The search paths for the developer frameworks.
#
DEVELOPER_FRAMEWORKS_SEARCH_PATHS = [
'$(inherited)',
'"$(SDKROOT)/Developer/Library/Frameworks"',
'"$(DEVELOPER_LIBRARY_DIR)/Frameworks"'
]
# Adds the search paths of the developer frameworks to the specification
# if needed. This is done because the `SenTestingKit` requires them and
# adding them to each specification which requires it is repetitive and
# error prone.
#
# @param [Xcodeproj::Config] xcconfig
# The xcconfig to edit.
#
# @return [void]
#
def self.add_developers_frameworks_if_needed(xcconfig)
if xcconfig.frameworks.include?('SenTestingKit')
search_paths = xcconfig.attributes['FRAMEWORK_SEARCH_PATHS'] ||= ''
DEVELOPER_FRAMEWORKS_SEARCH_PATHS.each do |search_path|
unless search_paths.include?(search_path)
search_paths << ' ' unless search_paths.empty?
search_paths << search_path
end
end
end
end
#---------------------------------------------------------------------#
end
end
end
end
...@@ -34,7 +34,7 @@ module Pod ...@@ -34,7 +34,7 @@ module Pod
def create_xcconfig_file def create_xcconfig_file
path = library.xcconfig_path path = library.xcconfig_path
UI.message "- Generating xcconfig file at #{UI.path(path)}" do UI.message "- Generating xcconfig file at #{UI.path(path)}" do
gen = Generator::AggregateXCConfig.new(library) gen = Generator::XCConfig::AggregateXCConfig.new(library)
gen.save_as(path) gen.save_as(path)
library.xcconfig = gen.xcconfig library.xcconfig = gen.xcconfig
xcconfig_file_ref = add_file_to_support_group(path) xcconfig_file_ref = add_file_to_support_group(path)
......
...@@ -55,7 +55,7 @@ module Pod ...@@ -55,7 +55,7 @@ module Pod
# #
def create_xcconfig_file def create_xcconfig_file
path = library.xcconfig_path path = library.xcconfig_path
public_gen = Generator::PublicPodXCConfig.new(library) public_gen = Generator::XCConfig::PublicPodXCConfig.new(library)
UI.message "- Generating public xcconfig file at #{UI.path(path)}" do UI.message "- Generating public xcconfig file at #{UI.path(path)}" do
public_gen.save_as(path) public_gen.save_as(path)
# #
...@@ -67,7 +67,7 @@ module Pod ...@@ -67,7 +67,7 @@ module Pod
end end
path = library.xcconfig_private_path path = library.xcconfig_private_path
private_gen = Generator::PrivatePodXCConfig.new(library, public_gen.xcconfig) private_gen = Generator::XCConfig::PrivatePodXCConfig.new(library, public_gen.xcconfig)
UI.message "- Generating private xcconfig file at #{UI.path(path)}" do UI.message "- Generating private xcconfig file at #{UI.path(path)}" do
private_gen.save_as(path) private_gen.save_as(path)
xcconfig_file_ref = add_file_to_support_group(path) xcconfig_file_ref = add_file_to_support_group(path)
......
require File.expand_path('../../../../spec_helper', __FILE__) require File.expand_path('../../../../spec_helper', __FILE__)
module Pod module Pod
describe Generator::AggregateXCConfig do module Generator
module XCConfig
describe AggregateXCConfig do
before do before do
@spec = fixture_spec('banana-lib/BananaLib.podspec') @spec = fixture_spec('banana-lib/BananaLib.podspec')
@consumer = @spec.consumer(:ios) @consumer = @spec.consumer(:ios)
...@@ -13,11 +16,7 @@ module Pod ...@@ -13,11 +16,7 @@ module Pod
@pod_target.stubs(:platform).returns(:ios) @pod_target.stubs(:platform).returns(:ios)
@pod_target.stubs(:spec_consumers).returns([@consumer]) @pod_target.stubs(:spec_consumers).returns([@consumer])
@target.pod_targets = [@pod_target] @target.pod_targets = [@pod_target]
@generator = Generator::AggregateXCConfig.new(@target) @generator = AggregateXCConfig.new(@target)
end
it "returns the sandbox" do
@generator.sandbox.class.should == Sandbox
end end
it "returns the path of the pods root relative to the user project" do it "returns the path of the pods root relative to the user project" do
...@@ -82,4 +81,6 @@ module Pod ...@@ -82,4 +81,6 @@ module Pod
end end
end end
end
end
end end
require File.expand_path('../../../../spec_helper', __FILE__) require File.expand_path('../../../../spec_helper', __FILE__)
module Pod module Pod
describe Generator::PrivatePodXCConfig do module Generator
module XCConfig
describe PrivatePodXCConfig do
describe "in general" do describe "in general" do
before do before do
...@@ -11,14 +13,7 @@ module Pod ...@@ -11,14 +13,7 @@ module Pod
@pod_target = PodTarget.new([@spec], target_definition, config.sandbox) @pod_target = PodTarget.new([@spec], target_definition, config.sandbox)
@pod_target.stubs(:platform).returns(:ios) @pod_target.stubs(:platform).returns(:ios)
public_xcconfig = Xcodeproj::Config.new({"OTHER_LDFLAGS"=>"-framework SystemConfiguration"}) public_xcconfig = Xcodeproj::Config.new({"OTHER_LDFLAGS"=>"-framework SystemConfiguration"})
@generator = Generator::PrivatePodXCConfig.new(@pod_target, public_xcconfig) @generator = PrivatePodXCConfig.new(@pod_target, public_xcconfig)
end
it "returns the sandbox" do
@generator.sandbox.class.should == Sandbox
end
before do
@podfile = Podfile.new @podfile = Podfile.new
@pod_target.target_definition.stubs(:podfile).returns(@podfile) @pod_target.target_definition.stubs(:podfile).returns(@podfile)
@xcconfig = @generator.generate @xcconfig = @generator.generate
...@@ -81,7 +76,7 @@ module Pod ...@@ -81,7 +76,7 @@ module Pod
describe "Private Helpers" do describe "Private Helpers" do
before do before do
@sut = Generator::PrivatePodXCConfig.new(stub(), stub()) @sut = PrivatePodXCConfig.new(stub(), stub())
end end
#----------------------------------------# #----------------------------------------#
...@@ -132,4 +127,6 @@ module Pod ...@@ -132,4 +127,6 @@ module Pod
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
end end
end
end
end end
require File.expand_path('../../../../spec_helper', __FILE__) require File.expand_path('../../../../spec_helper', __FILE__)
module Pod module Pod
describe Generator::PublicPodXCConfig do module Generator
module XCConfig
describe PublicPodXCConfig do
before do before do
@spec = fixture_spec('banana-lib/BananaLib.podspec') @spec = fixture_spec('banana-lib/BananaLib.podspec')
@target_definition = Podfile::TargetDefinition.new('Pods', nil) @target_definition = Podfile::TargetDefinition.new('Pods', nil)
@pod_target = PodTarget.new([@spec], @target_definition, config.sandbox) @pod_target = PodTarget.new([@spec], @target_definition, config.sandbox)
@pod_target.stubs(:platform).returns(:ios) @pod_target.stubs(:platform).returns(:ios)
@generator = Generator::PublicPodXCConfig.new(@pod_target) @generator = PublicPodXCConfig.new(@pod_target)
@podfile = Podfile.new @podfile = Podfile.new
@spec.xcconfig = { 'OTHER_LDFLAGS' => '-no_compact_unwind' } @spec.xcconfig = { 'OTHER_LDFLAGS' => '-no_compact_unwind' }
...@@ -55,7 +58,7 @@ module Pod ...@@ -55,7 +58,7 @@ module Pod
spec = fixture_spec('banana-lib/BananaLib.podspec') spec = fixture_spec('banana-lib/BananaLib.podspec')
pod_target = PodTarget.new([@spec, spec], @target_definition, config.sandbox) pod_target = PodTarget.new([@spec, spec], @target_definition, config.sandbox)
pod_target.stubs(:platform).returns(:ios) pod_target.stubs(:platform).returns(:ios)
generator = Generator::PublicPodXCConfig.new(pod_target) generator = PublicPodXCConfig.new(pod_target)
spec.frameworks = ['SenTestingKit'] spec.frameworks = ['SenTestingKit']
file_accessors = [Sandbox::FileAccessor.new(nil, spec.consumer(:ios))] file_accessors = [Sandbox::FileAccessor.new(nil, spec.consumer(:ios))]
pod_target.stubs(:file_accessors).returns(file_accessors) pod_target.stubs(:file_accessors).returns(file_accessors)
...@@ -88,4 +91,6 @@ module Pod ...@@ -88,4 +91,6 @@ module Pod
end end
end end
end
end
end end
require File.expand_path('../../../../spec_helper', __FILE__)
module Pod
module Generator
module XCConfig
describe XCConfigHelper do
before do
@sut = XCConfigHelper
end
#---------------------------------------------------------------------#
describe "::default_ld_flags" do
it "returns the default linker flags" do
podfile = stub( :set_arc_compatibility_flag? => false )
target_definition = stub( :podfile => podfile )
target = stub( :target_definition => target_definition )
result = @sut.default_ld_flags(target)
result.should == '-ObjC'
end
it "includes the ARC compatibility flag if required by the Podfile" do
podfile = stub( :set_arc_compatibility_flag? => true )
target_definition = stub( :podfile => podfile )
spec_consumer = stub( :requires_arc? => true )
target = stub( :target_definition => target_definition, :spec_consumers => [spec_consumer] )
result = @sut.default_ld_flags(target)
result.should == '-ObjC -fobjc-arc'
end
end
#---------------------------------------------------------------------#
describe "::quote" do
it "quotes strings" do
result = @sut.quote(['string1', 'string2'])
result.should == '"string1" "string2"'
end
end
#---------------------------------------------------------------------#
describe "::add_spec_build_settings_to_xcconfig" do
it "adds the build settings of the consumer" do
xcconfig = Xcodeproj::Config.new
consumer = stub({
:xcconfig => { 'OTHER_LDFLAGS' => '-framework SenTestingKit' },
:libraries => [],
:frameworks => [],
:weak_frameworks => [],
})
@sut.add_spec_build_settings_to_xcconfig(consumer, xcconfig)
xcconfig.to_hash['OTHER_LDFLAGS'].should == '-framework SenTestingKit'
end
it "adds the libraries of the xcconfig" do
xcconfig = Xcodeproj::Config.new
consumer = stub({
:xcconfig => {},
:libraries => ['xml2'],
:frameworks => [],
:weak_frameworks => [],
})
@sut.add_spec_build_settings_to_xcconfig(consumer, xcconfig)
xcconfig.to_hash['OTHER_LDFLAGS'].should == '-lxml2'
end
it "adds the frameworks of the xcconfig" do
xcconfig = Xcodeproj::Config.new
consumer = stub({
:xcconfig => {},
:libraries => [],
:frameworks => ['CoreAnimation'],
:weak_frameworks => [],
})
@sut.add_spec_build_settings_to_xcconfig(consumer, xcconfig)
xcconfig.to_hash['OTHER_LDFLAGS'].should == '-framework CoreAnimation'
end
it "adds the weak frameworks of the xcconfig" do
xcconfig = Xcodeproj::Config.new
consumer = stub({
:xcconfig => {},
:libraries => [],
:frameworks => [],
:weak_frameworks => ['iAd'],
})
@sut.add_spec_build_settings_to_xcconfig(consumer, xcconfig)
xcconfig.to_hash['OTHER_LDFLAGS'].should == '-weak_framework iAd'
end
it "adds the developer frameworks search paths if needed" do
xcconfig = Xcodeproj::Config.new
consumer = stub({
:xcconfig => {},
:libraries => [],
:frameworks => ['SenTestingKit'],
:weak_frameworks => [],
})
@sut.add_spec_build_settings_to_xcconfig(consumer, xcconfig)
xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should.include('DEVELOPER_LIBRARY_DIR')
end
end
#---------------------------------------------------------------------#
describe "::add_framework_build_settings" do
it "adds the build settings of a framework to the given xcconfig" do
framework_path = config.sandbox.root + 'Parse/Parse.framework'
xcconfig = Xcodeproj::Config.new
@sut.add_framework_build_settings(framework_path, xcconfig, config.sandbox.root)
hash_config = xcconfig.to_hash
hash_config['OTHER_LDFLAGS'].should == "-framework Parse"
hash_config['FRAMEWORK_SEARCH_PATHS'].should == '"$(PODS_ROOT)/Parse"'
end
it "doesn't ovverides exiting linker flags" do
framework_path = config.sandbox.root + 'Parse/Parse.framework'
xcconfig = Xcodeproj::Config.new( { 'OTHER_LDFLAGS' => '-framework CoreAnimation' } )
@sut.add_framework_build_settings(framework_path, xcconfig, config.sandbox.root)
hash_config = xcconfig.to_hash
hash_config['OTHER_LDFLAGS'].should == "-framework CoreAnimation -framework Parse"
end
it "doesn't ovverides exiting frameworks search paths" do
framework_path = config.sandbox.root + 'Parse/Parse.framework'
xcconfig = Xcodeproj::Config.new( { 'FRAMEWORK_SEARCH_PATHS' => '"path/to/frameworks"' } )
@sut.add_framework_build_settings(framework_path, xcconfig, config.sandbox.root)
hash_config = xcconfig.to_hash
hash_config['FRAMEWORK_SEARCH_PATHS'].should == '"path/to/frameworks" "$(PODS_ROOT)/Parse"'
end
end
#---------------------------------------------------------------------#
describe "::add_framework_build_settings" do
it "adds the developer frameworks search paths to the xcconfig if SenTestingKit has been detected" do
xcconfig = Xcodeproj::Config.new({'OTHER_LDFLAGS' => '-framework SenTestingKit'})
@sut.add_developers_frameworks_if_needed(xcconfig)
frameworks_search_paths = xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS']
frameworks_search_paths.should.include?('$(inherited)')
frameworks_search_paths.should.include?('"$(SDKROOT)/Developer/Library/Frameworks"')
frameworks_search_paths.should.include?('"$(DEVELOPER_LIBRARY_DIR)/Frameworks"')
end
end
#---------------------------------------------------------------------#
end
end
end
end
...@@ -3,38 +3,5 @@ require File.expand_path('../../../spec_helper', __FILE__) ...@@ -3,38 +3,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
module Pod module Pod
describe Generator::XCConfig do describe Generator::XCConfig do
before do
target = stub(:sandbox => config.sandbox)
@sut = Generator::XCConfig.new(target)
end
describe "#add_framework_build_settings" do
it "adds the build settings of a framework to the given xcconfig" do
framework_path = config.sandbox.root + 'Parse/Parse.framework'
xcconfig = Xcodeproj::Config.new
@sut.send(:add_framework_build_settings, framework_path, xcconfig)
hash_config = xcconfig.to_hash
hash_config['OTHER_LDFLAGS'].should == "-framework Parse"
hash_config['FRAMEWORK_SEARCH_PATHS'].should == '"$(PODS_ROOT)/Parse"'
end
it "doesn't ovverides exiting linker flags" do
framework_path = config.sandbox.root + 'Parse/Parse.framework'
xcconfig = Xcodeproj::Config.new( { 'OTHER_LDFLAGS' => '-framework CoreAnimation' } )
@sut.send(:add_framework_build_settings, framework_path, xcconfig)
hash_config = xcconfig.to_hash
hash_config['OTHER_LDFLAGS'].should == "-framework CoreAnimation -framework Parse"
end
it "doesn't ovverides exiting frameworks search paths" do
framework_path = config.sandbox.root + 'Parse/Parse.framework'
xcconfig = Xcodeproj::Config.new( { 'FRAMEWORK_SEARCH_PATHS' => '"path/to/frameworks"' } )
@sut.send(:add_framework_build_settings, framework_path, xcconfig)
hash_config = xcconfig.to_hash
hash_config['FRAMEWORK_SEARCH_PATHS'].should == '"path/to/frameworks" "$(PODS_ROOT)/Parse"'
end
end
end end
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