Commit e92cd653 authored by Marius Rackwitz's avatar Marius Rackwitz Committed by Samuel Giddins

[XCConfig] Support customized build dirs in user project

parent ea67c41e
...@@ -4,12 +4,21 @@ module Pod ...@@ -4,12 +4,21 @@ module Pod
# Stores the shared logic of the classes of the XCConfig module. # Stores the shared logic of the classes of the XCConfig module.
# #
module XCConfigHelper module XCConfigHelper
# @return [String] Defined to hold the default Xcode build path, so # @return [String] Used as alias for BUILD_DIR, so that when this
# that when this is overridden per {PodTarget}, it is still # is overridden in the user target, the user can override
# possible to reference other build products relative to the # this variable to point to the standard directory, which
# original path. # will be used by CocoaPods.
# #
SHARED_BUILD_DIR_VARIABLE = 'PODS_SHARED_BUILD_DIR'.freeze BUILD_DIR_VARIABLE = '$PODS_BUILD_DIR'.freeze
# @return [String] Used as alias for CONFIGURATION_BUILD_DIR, so that
# when this is overridden per {PodTarget}, it is still possible
# to reference other build products relative to the original
# path. Furthermore if it was overridden in the user target,
# the user can override this variable to point to the standard
# directory, which will be used by CocoaPods.
#
CONFIGURATION_BUILD_DIR_VARIABLE = '$PODS_CONFIGURATION_BUILD_DIR'.freeze
# Converts an array of strings to a single string where the each string # 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 # is surrounded by double quotes and separated by a space. Used to
...@@ -232,25 +241,27 @@ module Pod ...@@ -232,25 +241,27 @@ module Pod
# #
def self.settings_for_dependent_targets(target, dependent_targets) def self.settings_for_dependent_targets(target, dependent_targets)
dependent_targets = dependent_targets.select(&:should_build?) dependent_targets = dependent_targets.select(&:should_build?)
has_configuration_build_dir = target.respond_to?(:configuration_build_dir)
if has_configuration_build_dir # Alias build dirs to avoid recursive definitions for pod targets and depending
build_dir_var = "$#{SHARED_BUILD_DIR_VARIABLE}" # on build settings which could be overwritten in the user target.
build_settings = { build_settings = {
'CONFIGURATION_BUILD_DIR' => target.configuration_build_dir(build_dir_var), BUILD_DIR_VARIABLE[1..-1] => '$BUILD_DIR',
SHARED_BUILD_DIR_VARIABLE => '$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)', CONFIGURATION_BUILD_DIR_VARIABLE[1..-1] => "#{BUILD_DIR_VARIABLE}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)",
} }
else
build_dir_var = '$CONFIGURATION_BUILD_DIR' # Scope pod targets
build_settings = {} if target.respond_to?(:configuration_build_dir)
build_settings['CONFIGURATION_BUILD_DIR'] = target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)
end end
unless dependent_targets.empty? unless dependent_targets.empty?
framework_search_paths = [] framework_search_paths = []
library_search_paths = [] library_search_paths = []
dependent_targets.each do |dependent_target| dependent_targets.each do |dependent_target|
if dependent_target.requires_frameworks? if dependent_target.requires_frameworks?
framework_search_paths << dependent_target.configuration_build_dir(build_dir_var) framework_search_paths << dependent_target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)
else else
library_search_paths << dependent_target.configuration_build_dir(build_dir_var) library_search_paths << dependent_target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)
end end
end end
build_settings['FRAMEWORK_SEARCH_PATHS'] = XCConfigHelper.quote(framework_search_paths.uniq) build_settings['FRAMEWORK_SEARCH_PATHS'] = XCConfigHelper.quote(framework_search_paths.uniq)
......
...@@ -240,7 +240,7 @@ module Pod ...@@ -240,7 +240,7 @@ module Pod
# #
# @return [String] The absolute path to the configuration build dir # @return [String] The absolute path to the configuration build dir
# #
def configuration_build_dir(dir = '$CONFIGURATION_BUILD_DIR') def configuration_build_dir(dir = Generator::XCConfig::XCConfigHelper::CONFIGURATION_BUILD_DIR_VARIABLE)
"#{dir}/#{label}" "#{dir}/#{label}"
end end
...@@ -249,7 +249,7 @@ module Pod ...@@ -249,7 +249,7 @@ module Pod
# #
# @return [String] The absolute path to the build product # @return [String] The absolute path to the build product
# #
def build_product_path(dir = '$CONFIGURATION_BUILD_DIR') def build_product_path(dir = Generator::XCConfig::XCConfigHelper::CONFIGURATION_BUILD_DIR_VARIABLE)
"#{configuration_build_dir(dir)}/#{product_name}" "#{configuration_build_dir(dir)}/#{product_name}"
end end
......
...@@ -61,6 +61,14 @@ module Pod ...@@ -61,6 +61,14 @@ module Pod
@xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}/Pods' @xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}/Pods'
end end
it 'sets the PODS_BUILD_DIR build variable' do
@xcconfig.to_hash['PODS_BUILD_DIR'].should == '$BUILD_DIR'
end
it 'sets the PODS_CONFIGURATION_BUILD_DIR build variable' do
@xcconfig.to_hash['PODS_CONFIGURATION_BUILD_DIR'].should == '$PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)'
end
it 'adds the COCOAPODS macro definition' do it 'adds the COCOAPODS macro definition' do
@xcconfig.to_hash['GCC_PREPROCESSOR_DEFINITIONS'].should.include 'COCOAPODS=1' @xcconfig.to_hash['GCC_PREPROCESSOR_DEFINITIONS'].should.include 'COCOAPODS=1'
end end
...@@ -166,12 +174,12 @@ module Pod ...@@ -166,12 +174,12 @@ module Pod
end end
it 'does not include framework header paths as local headers for pods that are linked statically' do it 'does not include framework header paths as local headers for pods that are linked statically' do
monkey_headers = '-iquote "$CONFIGURATION_BUILD_DIR/monkey.framework/Headers"' monkey_headers = '-iquote "$PODS_CONFIGURATION_BUILD_DIR/monkey.framework/Headers"'
@xcconfig.to_hash['OTHER_CFLAGS'].should.not.include monkey_headers @xcconfig.to_hash['OTHER_CFLAGS'].should.not.include monkey_headers
end end
it 'includes the public header paths as system headers' do it 'includes the public header paths as system headers' do
expected = '$(inherited) -iquote "$CONFIGURATION_BUILD_DIR/OrangeFramework/OrangeFramework.framework/Headers" -isystem "${PODS_ROOT}/Headers/Public"' expected = '$(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/OrangeFramework/OrangeFramework.framework/Headers" -isystem "${PODS_ROOT}/Headers/Public"'
@generator.stubs(:pod_targets).returns([@pod_targets.first, pod_target(fixture_spec('orange-framework/OrangeFramework.podspec'), @target_definition)]) @generator.stubs(:pod_targets).returns([@pod_targets.first, pod_target(fixture_spec('orange-framework/OrangeFramework.podspec'), @target_definition)])
@xcconfig = @generator.generate @xcconfig = @generator.generate
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected @xcconfig.to_hash['OTHER_CFLAGS'].should == expected
...@@ -205,22 +213,22 @@ module Pod ...@@ -205,22 +213,22 @@ module Pod
end end
it 'adds the framework build path to the xcconfig, with quotes, as framework search paths' do it 'adds the framework build path to the xcconfig, with quotes, as framework search paths' do
@xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should == '$(inherited) "$CONFIGURATION_BUILD_DIR/BananaLib-iOS" "$CONFIGURATION_BUILD_DIR/OrangeFramework-iOS"' @xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should == '$(inherited) "$PODS_CONFIGURATION_BUILD_DIR/BananaLib-iOS" "$PODS_CONFIGURATION_BUILD_DIR/OrangeFramework-iOS"'
end end
it 'adds the framework header paths to the xcconfig, with quotes, as local headers' do it 'adds the framework header paths to the xcconfig, with quotes, as local headers' do
expected = '$(inherited) -iquote "$CONFIGURATION_BUILD_DIR/BananaLib-iOS/BananaLib.framework/Headers" -iquote "$CONFIGURATION_BUILD_DIR/OrangeFramework-iOS/OrangeFramework.framework/Headers"' expected = '$(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/BananaLib-iOS/BananaLib.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/OrangeFramework-iOS/OrangeFramework.framework/Headers"'
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected @xcconfig.to_hash['OTHER_CFLAGS'].should == expected
end end
end end
describe 'with an unscoped pod target' do describe 'with an unscoped pod target' do
it 'adds the framework build path to the xcconfig, with quotes, as framework search paths' do it 'adds the framework build path to the xcconfig, with quotes, as framework search paths' do
@xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should == '$(inherited) "$CONFIGURATION_BUILD_DIR/OrangeFramework"' @xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should == '$(inherited) "$PODS_CONFIGURATION_BUILD_DIR/OrangeFramework"'
end end
it 'adds the framework header paths to the xcconfig, with quotes, as local headers' do it 'adds the framework header paths to the xcconfig, with quotes, as local headers' do
expected = '$(inherited) -iquote "$CONFIGURATION_BUILD_DIR/OrangeFramework/OrangeFramework.framework/Headers"' expected = '$(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/OrangeFramework/OrangeFramework.framework/Headers"'
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected @xcconfig.to_hash['OTHER_CFLAGS'].should == expected
end end
end end
......
...@@ -95,6 +95,14 @@ module Pod ...@@ -95,6 +95,14 @@ module Pod
@xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}' @xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}'
end end
it 'sets the PODS_BUILD_DIR build variable' do
@xcconfig.to_hash['PODS_BUILD_DIR'].should == '$BUILD_DIR'
end
it 'sets the PODS_CONFIGURATION_BUILD_DIR build variable' do
@xcconfig.to_hash['PODS_CONFIGURATION_BUILD_DIR'].should == '$PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)'
end
it 'will be skipped when installing' do it 'will be skipped when installing' do
@xcconfig.to_hash['SKIP_INSTALL'].should == 'YES' @xcconfig.to_hash['SKIP_INSTALL'].should == 'YES'
end end
......
...@@ -157,8 +157,8 @@ module Pod ...@@ -157,8 +157,8 @@ module Pod
) )
resources_by_config = @installer.send(:resources_by_config) resources_by_config = @installer.send(:resources_by_config)
resources_by_config.each_value do |resources| resources_by_config.each_value do |resources|
resources.should.include '$CONFIGURATION_BUILD_DIR/BananaLib/Trees.bundle' resources.should.include '$PODS_CONFIGURATION_BUILD_DIR/BananaLib/Trees.bundle'
resources.should.include '$CONFIGURATION_BUILD_DIR/BananaLib/Leafs.bundle' resources.should.include '$PODS_CONFIGURATION_BUILD_DIR/BananaLib/Leafs.bundle'
end end
end end
......
...@@ -169,15 +169,15 @@ module Pod ...@@ -169,15 +169,15 @@ module Pod
end end
it 'returns the path for the CONFIGURATION_BUILD_DIR build setting' do it 'returns the path for the CONFIGURATION_BUILD_DIR build setting' do
@pod_target.configuration_build_dir.should == '$CONFIGURATION_BUILD_DIR/BananaLib' @pod_target.configuration_build_dir.should == '$PODS_CONFIGURATION_BUILD_DIR/BananaLib'
@pod_target.scoped.first.configuration_build_dir.should == '$CONFIGURATION_BUILD_DIR/BananaLib-Pods' @pod_target.scoped.first.configuration_build_dir.should == '$PODS_CONFIGURATION_BUILD_DIR/BananaLib-Pods'
@pod_target.configuration_build_dir('$PODS_SHARED_BUILD_DIR').should == '$PODS_SHARED_BUILD_DIR/BananaLib' @pod_target.configuration_build_dir('$PODS_BUILD_DIR').should == '$PODS_BUILD_DIR/BananaLib'
@pod_target.scoped.first.configuration_build_dir('$PODS_SHARED_BUILD_DIR').should == '$PODS_SHARED_BUILD_DIR/BananaLib-Pods' @pod_target.scoped.first.configuration_build_dir('$PODS_BUILD_DIR').should == '$PODS_BUILD_DIR/BananaLib-Pods'
end end
it 'returns the path for the CONFIGURATION_BUILD_DIR build setting' do it 'returns the path for the CONFIGURATION_BUILD_DIR build setting' do
@pod_target.build_product_path.should == '$CONFIGURATION_BUILD_DIR/BananaLib/libBananaLib.a' @pod_target.build_product_path.should == '$PODS_CONFIGURATION_BUILD_DIR/BananaLib/libBananaLib.a'
@pod_target.scoped.first.build_product_path.should == '$CONFIGURATION_BUILD_DIR/BananaLib-Pods/libBananaLib-Pods.a' @pod_target.scoped.first.build_product_path.should == '$PODS_CONFIGURATION_BUILD_DIR/BananaLib-Pods/libBananaLib-Pods.a'
@pod_target.build_product_path('$BUILT_PRODUCTS_DIR').should == '$BUILT_PRODUCTS_DIR/BananaLib/libBananaLib.a' @pod_target.build_product_path('$BUILT_PRODUCTS_DIR').should == '$BUILT_PRODUCTS_DIR/BananaLib/libBananaLib.a'
@pod_target.scoped.first.build_product_path('$BUILT_PRODUCTS_DIR').should == '$BUILT_PRODUCTS_DIR/BananaLib-Pods/libBananaLib-Pods.a' @pod_target.scoped.first.build_product_path('$BUILT_PRODUCTS_DIR').should == '$BUILT_PRODUCTS_DIR/BananaLib-Pods/libBananaLib-Pods.a'
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