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,21 +23,37 @@ module Pod ...@@ -18,21 +23,37 @@ 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'
} }
xcconfig_hash = add_xcconfig_namespaced_keys(public_xcconfig.to_hash, config, target.xcconfig_prefix) xcconfig_hash = add_xcconfig_namespaced_keys(public_xcconfig.to_hash, config, target.xcconfig_prefix)
...@@ -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
before do module XCConfig
@spec = fixture_spec('banana-lib/BananaLib.podspec') describe AggregateXCConfig do
@consumer = @spec.consumer(:ios)
target_definition = Podfile::TargetDefinition.new('Pods', nil) before do
@target = AggregateTarget.new(target_definition, config.sandbox) @spec = fixture_spec('banana-lib/BananaLib.podspec')
@target.client_root = config.sandbox.root.dirname @consumer = @spec.consumer(:ios)
@target.stubs(:platform).returns(:ios) target_definition = Podfile::TargetDefinition.new('Pods', nil)
@pod_target = PodTarget.new([@spec], target_definition, config.sandbox) @target = AggregateTarget.new(target_definition, config.sandbox)
@pod_target.stubs(:platform).returns(:ios) @target.client_root = config.sandbox.root.dirname
@pod_target.stubs(:spec_consumers).returns([@consumer]) @target.stubs(:platform).returns(:ios)
@target.pod_targets = [@pod_target] @pod_target = PodTarget.new([@spec], target_definition, config.sandbox)
@generator = Generator::AggregateXCConfig.new(@target) @pod_target.stubs(:platform).returns(:ios)
@pod_target.stubs(:spec_consumers).returns([@consumer])
@target.pod_targets = [@pod_target]
@generator = AggregateXCConfig.new(@target)
end
it "returns the path of the pods root relative to the user project" do
@generator.target.relative_pods_root.should == '${SRCROOT}/Pods'
end
#-----------------------------------------------------------------------#
before do
@podfile = Podfile.new
@target.target_definition.stubs(:podfile).returns(@podfile)
@xcconfig = @generator.generate
end
it "generates the xcconfig" do
@xcconfig.class.should == Xcodeproj::Config
end
it "configures the project to load all members that implement Objective-c classes or categories from the static library" do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-ObjC'
end
it 'does not add the -fobjc-arc to OTHER_LDFLAGS by default as Xcode 4.3.2 does not support it' do
@consumer.stubs(:requires_arc?).returns(true)
@xcconfig.to_hash['OTHER_LDFLAGS'].should.not.include("-fobjc-arc")
end
it 'adds the -fobjc-arc to OTHER_LDFLAGS if any pods require arc and the podfile explicitly requires it' do
@podfile.stubs(:set_arc_compatibility_flag?).returns(true)
@consumer.stubs(:requires_arc?).returns(true)
@xcconfig = @generator.generate
@xcconfig.to_hash['OTHER_LDFLAGS'].split(" ").should.include("-fobjc-arc")
end
it "sets the PODS_ROOT build variable" do
@xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}/Pods'
end
it 'adds the sandbox public headers search paths to the xcconfig, with quotes' do
expected = "\"#{config.sandbox.public_headers.search_paths.join('" "')}\""
@xcconfig.to_hash['HEADER_SEARCH_PATHS'].should == expected
end
it 'adds the COCOAPODS macro definition' do
@xcconfig.to_hash['GCC_PREPROCESSOR_DEFINITIONS'].should.include 'COCOAPODS=1'
end
it 'inherits the parent GCC_PREPROCESSOR_DEFINITIONS value' do
@xcconfig.to_hash['GCC_PREPROCESSOR_DEFINITIONS'].should.include '$(inherited)'
end
#-----------------------------------------------------------------------#
before do
@path = temporary_directory + 'sample.xcconfig'
@generator.save_as(@path)
end
it "saves the xcconfig" do
generated = Xcodeproj::Config.new(@path)
generated.class.should == Xcodeproj::Config
end
end
end end
it "returns the sandbox" do
@generator.sandbox.class.should == Sandbox
end
it "returns the path of the pods root relative to the user project" do
@generator.target.relative_pods_root.should == '${SRCROOT}/Pods'
end
#-----------------------------------------------------------------------#
before do
@podfile = Podfile.new
@target.target_definition.stubs(:podfile).returns(@podfile)
@xcconfig = @generator.generate
end
it "generates the xcconfig" do
@xcconfig.class.should == Xcodeproj::Config
end
it "configures the project to load all members that implement Objective-c classes or categories from the static library" do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-ObjC'
end
it 'does not add the -fobjc-arc to OTHER_LDFLAGS by default as Xcode 4.3.2 does not support it' do
@consumer.stubs(:requires_arc?).returns(true)
@xcconfig.to_hash['OTHER_LDFLAGS'].should.not.include("-fobjc-arc")
end
it 'adds the -fobjc-arc to OTHER_LDFLAGS if any pods require arc and the podfile explicitly requires it' do
@podfile.stubs(:set_arc_compatibility_flag?).returns(true)
@consumer.stubs(:requires_arc?).returns(true)
@xcconfig = @generator.generate
@xcconfig.to_hash['OTHER_LDFLAGS'].split(" ").should.include("-fobjc-arc")
end
it "sets the PODS_ROOT build variable" do
@xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}/Pods'
end
it 'adds the sandbox public headers search paths to the xcconfig, with quotes' do
expected = "\"#{config.sandbox.public_headers.search_paths.join('" "')}\""
@xcconfig.to_hash['HEADER_SEARCH_PATHS'].should == expected
end
it 'adds the COCOAPODS macro definition' do
@xcconfig.to_hash['GCC_PREPROCESSOR_DEFINITIONS'].should.include 'COCOAPODS=1'
end
it 'inherits the parent GCC_PREPROCESSOR_DEFINITIONS value' do
@xcconfig.to_hash['GCC_PREPROCESSOR_DEFINITIONS'].should.include '$(inherited)'
end
#-----------------------------------------------------------------------#
before do
@path = temporary_directory + 'sample.xcconfig'
@generator.save_as(@path)
end
it "saves the xcconfig" do
generated = Xcodeproj::Config.new(@path)
generated.class.should == Xcodeproj::Config
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
before do module XCConfig
@spec = fixture_spec('banana-lib/BananaLib.podspec') describe PublicPodXCConfig do
@target_definition = Podfile::TargetDefinition.new('Pods', nil)
@pod_target = PodTarget.new([@spec], @target_definition, config.sandbox) before do
@pod_target.stubs(:platform).returns(:ios) @spec = fixture_spec('banana-lib/BananaLib.podspec')
@generator = Generator::PublicPodXCConfig.new(@pod_target) @target_definition = Podfile::TargetDefinition.new('Pods', nil)
@pod_target = PodTarget.new([@spec], @target_definition, config.sandbox)
@podfile = Podfile.new @pod_target.stubs(:platform).returns(:ios)
@spec.xcconfig = { 'OTHER_LDFLAGS' => '-no_compact_unwind' } @generator = PublicPodXCConfig.new(@pod_target)
@spec.frameworks = ['QuartzCore']
@spec.weak_frameworks = ['iAd'] @podfile = Podfile.new
@spec.libraries = ['xml2'] @spec.xcconfig = { 'OTHER_LDFLAGS' => '-no_compact_unwind' }
file_accessors = [Sandbox::FileAccessor.new(nil, @spec.consumer(:ios))] @spec.frameworks = ['QuartzCore']
framework_bundle_paths = [config.sandbox.root + 'BananaLib/BananaLib.framework'] @spec.weak_frameworks = ['iAd']
Sandbox::FileAccessor.any_instance.stubs(:framework_bundles).returns(framework_bundle_paths) @spec.libraries = ['xml2']
file_accessors = [Sandbox::FileAccessor.new(nil, @spec.consumer(:ios))]
@pod_target.target_definition.stubs(:podfile).returns(@podfile) framework_bundle_paths = [config.sandbox.root + 'BananaLib/BananaLib.framework']
@pod_target.stubs(:file_accessors).returns(file_accessors) Sandbox::FileAccessor.any_instance.stubs(:framework_bundles).returns(framework_bundle_paths)
@xcconfig = @generator.generate @pod_target.target_definition.stubs(:podfile).returns(@podfile)
@pod_target.stubs(:file_accessors).returns(file_accessors)
@xcconfig = @generator.generate
end
it "generates the xcconfig" do
@xcconfig.class.should == Xcodeproj::Config
end
it "includes the xcconfig of the specifications" do
@xcconfig.to_hash["OTHER_LDFLAGS"].should.include('-no_compact_unwind')
end
it "includes the libraries for the specifications" do
@xcconfig.to_hash["OTHER_LDFLAGS"].should.include('-lxml2')
end
it "includes the frameworks of the specifications" do
@xcconfig.to_hash["OTHER_LDFLAGS"].should.include('-framework QuartzCore')
end
it "includes the weak-frameworks of the specifications" do
@xcconfig.to_hash["OTHER_LDFLAGS"].should.include('-weak_framework iAd')
end
it "includes the developer frameworks search paths when SenTestingKit is detected" do
@spec.xcconfig = { 'OTHER_LDFLAGS' => '-no_compact_unwind' }
@spec.frameworks = ['SenTestingKit']
xcconfig = @generator.generate
xcconfig.to_hash["FRAMEWORK_SEARCH_PATHS"].should == '$(inherited) "$(SDKROOT)/Developer/Library/Frameworks" "$(DEVELOPER_LIBRARY_DIR)/Frameworks" "$(PODS_ROOT)/BananaLib"'
end
it "doesn't include the developer frameworks if already present" do
spec = fixture_spec('banana-lib/BananaLib.podspec')
pod_target = PodTarget.new([@spec, spec], @target_definition, config.sandbox)
pod_target.stubs(:platform).returns(:ios)
generator = PublicPodXCConfig.new(pod_target)
spec.frameworks = ['SenTestingKit']
file_accessors = [Sandbox::FileAccessor.new(nil, spec.consumer(:ios))]
pod_target.stubs(:file_accessors).returns(file_accessors)
xcconfig = generator.generate
xcconfig.to_hash["FRAMEWORK_SEARCH_PATHS"].should == '$(inherited) "$(SDKROOT)/Developer/Library/Frameworks" "$(DEVELOPER_LIBRARY_DIR)/Frameworks" "$(PODS_ROOT)/BananaLib"'
end
it "includes the build settings of the frameworks bundles of the spec" do
@spec.framework_bundles = ['BananaLib.framework']
xcconfig = @generator.generate
xcconfig.to_hash["FRAMEWORK_SEARCH_PATHS"].should.include?('"$(PODS_ROOT)/BananaLib"')
end
#-----------------------------------------------------------------------#
before do
@path = temporary_directory + 'sample.xcconfig'
@generator.save_as(@path)
end
it "saves the xcconfig" do
generated = Xcodeproj::Config.new(@path)
generated.class.should == Xcodeproj::Config
end
it "writes the xcconfig with a prefix computed from the target definition and root spec" do
generated = Xcodeproj::Config.new(@path)
generated.to_hash.each { |k, v| k.should.start_with(@pod_target.xcconfig_prefix) }
end
end
end end
it "generates the xcconfig" do
@xcconfig.class.should == Xcodeproj::Config
end
it "includes the xcconfig of the specifications" do
@xcconfig.to_hash["OTHER_LDFLAGS"].should.include('-no_compact_unwind')
end
it "includes the libraries for the specifications" do
@xcconfig.to_hash["OTHER_LDFLAGS"].should.include('-lxml2')
end
it "includes the frameworks of the specifications" do
@xcconfig.to_hash["OTHER_LDFLAGS"].should.include('-framework QuartzCore')
end
it "includes the weak-frameworks of the specifications" do
@xcconfig.to_hash["OTHER_LDFLAGS"].should.include('-weak_framework iAd')
end
it "includes the developer frameworks search paths when SenTestingKit is detected" do
@spec.xcconfig = { 'OTHER_LDFLAGS' => '-no_compact_unwind' }
@spec.frameworks = ['SenTestingKit']
xcconfig = @generator.generate
xcconfig.to_hash["FRAMEWORK_SEARCH_PATHS"].should == '$(inherited) "$(SDKROOT)/Developer/Library/Frameworks" "$(DEVELOPER_LIBRARY_DIR)/Frameworks" "$(PODS_ROOT)/BananaLib"'
end
it "doesn't include the developer frameworks if already present" do
spec = fixture_spec('banana-lib/BananaLib.podspec')
pod_target = PodTarget.new([@spec, spec], @target_definition, config.sandbox)
pod_target.stubs(:platform).returns(:ios)
generator = Generator::PublicPodXCConfig.new(pod_target)
spec.frameworks = ['SenTestingKit']
file_accessors = [Sandbox::FileAccessor.new(nil, spec.consumer(:ios))]
pod_target.stubs(:file_accessors).returns(file_accessors)
xcconfig = generator.generate
xcconfig.to_hash["FRAMEWORK_SEARCH_PATHS"].should == '$(inherited) "$(SDKROOT)/Developer/Library/Frameworks" "$(DEVELOPER_LIBRARY_DIR)/Frameworks" "$(PODS_ROOT)/BananaLib"'
end
it "includes the build settings of the frameworks bundles of the spec" do
@spec.framework_bundles = ['BananaLib.framework']
xcconfig = @generator.generate
xcconfig.to_hash["FRAMEWORK_SEARCH_PATHS"].should.include?('"$(PODS_ROOT)/BananaLib"')
end
#-----------------------------------------------------------------------#
before do
@path = temporary_directory + 'sample.xcconfig'
@generator.save_as(@path)
end
it "saves the xcconfig" do
generated = Xcodeproj::Config.new(@path)
generated.class.should == Xcodeproj::Config
end
it "writes the xcconfig with a prefix computed from the target definition and root spec" do
generated = Xcodeproj::Config.new(@path)
generated.to_hash.each { |k, v| k.should.start_with(@pod_target.xcconfig_prefix) }
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