Skip to content

Commit

Permalink
Provide option to look into xcconfigs for common build settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Oct 30, 2019
1 parent 7151d54 commit 27d8383
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

##### Enhancements

* None.
* Provide option to look into xcconfigs for common build settings.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#722](https://github.com/CocoaPods/Xcodeproj/pull/722)

##### Bug Fixes

Expand All @@ -27,7 +29,6 @@
* Update PBXProject known_regions attribute to include 'Base'
[Liam Nichols](https://github.com/liamnichols)
[#9187](https://github.com/CocoaPods/CocoaPods/issues/9187)


##### Bug Fixes

Expand Down
10 changes: 7 additions & 3 deletions lib/xcodeproj/project/object/native_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AbstractTarget < AbstractObject
# the key of the build setting.
#
# @param [Bool] resolve_against_xcconfig
# wether the resolved setting should take in consideration any
# whether the resolved setting should take in consideration any
# configuration file present.
#
# @return [Hash{String => String}] The value of the build setting
Expand Down Expand Up @@ -74,6 +74,10 @@ def resolved_build_setting(key, resolve_against_xcconfig = false)
# @param [String] key
# the key of the build setting.
#
# @param [Boolean] resolve_against_xcconfig
# whether the resolved setting should take in consideration any
# configuration file present.
#
# @raise If the build setting has multiple values.
#
# @note As it is common not to have a setting with no value for
Expand All @@ -83,8 +87,8 @@ def resolved_build_setting(key, resolve_against_xcconfig = false)
#
# @return [String] The value of the build setting.
#
def common_resolved_build_setting(key)
values = resolved_build_setting(key).values.compact.uniq
def common_resolved_build_setting(key, resolve_against_xcconfig = false)
values = resolved_build_setting(key, resolve_against_xcconfig).values.compact.uniq
if values.count <= 1
values.first
else
Expand Down
2 changes: 1 addition & 1 deletion lib/xcodeproj/scheme/test_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def code_coverage_enabled?
string_to_bool(@xml_element.attributes['codeCoverageEnabled'])
end

# @rparam [Bool] flag
# @param [Bool] flag
# Set whether Clang Code Coverage is enabled ('Gather coverage data' turned ON)
#
def code_coverage_enabled=(flag)
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/target.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ TARGET_REFERENCE_XCCONFIG_PROJECT = $(USER_DEFINED_XCCONFIG_PROJECT)
A_BUILD_SETTING_WITH_VALUE = Some value
TARGET_REFERENCE_ENVIRONMENT =
TARGET_REFERENCE_ENVIRONMENT_SUBSTITUTION = ${DEFINED_IN_ENVIRONMENT}

APPLICATION_EXTENSION_API_ONLY = YES
9 changes: 9 additions & 0 deletions spec/project/object/native_target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ module ProjectSpecs
@target.common_resolved_build_setting('ARCHS').should == 'VALID_ARCHS'
end

it 'returns the common resolved build setting for the given key including xcconfig' do
project_xcconfig = @project.new_file(fixture_path('project.xcconfig'))
@project.build_configuration_list.build_configurations.each { |build_config| build_config.base_configuration_reference = project_xcconfig }
target_xcconfig = @project.new_file(fixture_path('target.xcconfig'))
@target.build_configuration_list.build_configurations.each { |build_config| build_config.base_configuration_reference = target_xcconfig }
@target.common_resolved_build_setting('APPLICATION_EXTENSION_API_ONLY', false).should.be.nil
@target.common_resolved_build_setting('APPLICATION_EXTENSION_API_ONLY', true).should == 'YES'
end

it 'raises if the build setting has multiple values across the build configurations' do
@target.build_configuration_list.build_configurations.first.build_settings['ARCHS'] = 'arm64'
@target.build_configuration_list.build_configurations.last.build_settings['ARCHS'] = 'VALID_ARCHS'
Expand Down

0 comments on commit 27d8383

Please sign in to comment.