Skip to content

Commit b04a565

Browse files
authored
feat(apple): add :build_setting_overrides to options (#2204)
`:build_setting_overrides` allows you to override build settings defined in the final Xcode project.
1 parent 3ead036 commit b04a565

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

ios/pod_helpers.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ def try_pod(name, podspec, project_root)
9898
pod name, :podspec => podspec if File.exist?(File.join(project_root, podspec))
9999
end
100100

101+
def override_build_settings!(build_settings, settings_to_append)
102+
settings_to_append&.each do |setting, value|
103+
build_settings[setting] = value
104+
end
105+
end
106+
101107
def use_hermes?(options)
102108
use_hermes = ENV.fetch('USE_HERMES', nil)
103109
return use_hermes == '1' unless use_hermes.nil?

ios/test_app.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ def make_project!(xcodeproj, project_root, target_platform, options)
259259
uitests_build_settings[PRODUCT_BUNDLE_IDENTIFIER] = "#{product_bundle_identifier}UITests"
260260
end
261261

262+
override_build_settings!(build_settings, options[:build_setting_overrides])
263+
262264
build_settings[PRODUCT_DISPLAY_NAME] = display_name
263265
build_settings[PRODUCT_VERSION] = version || '1.0'
264266

test/test_pod_helpers.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,30 @@ def test_v
112112
assert_equal(1_001_000, v(1, 1, 0))
113113
assert_equal(1_001_001, v(1, 1, 1))
114114
end
115+
116+
def test_override_build_settings
117+
build_settings = { 'OTHER_LDFLAGS' => '-l"Pods-TestApp"', 'ONLY_ACTIVE_ARCH' => 'NO' }
118+
119+
override_build_settings!(build_settings, {})
120+
121+
assert_equal('-l"Pods-TestApp"', build_settings['OTHER_LDFLAGS'])
122+
123+
override_build_settings!(build_settings, { 'OTHER_LDFLAGS' => ' -ObjC' })
124+
125+
assert_equal(' -ObjC', build_settings['OTHER_LDFLAGS'])
126+
127+
# Test passing a table
128+
build_settings_arr = { 'OTHER_LDFLAGS' => ['$(inherited)', '-l"Pods-TestApp"'] }
129+
override_build_settings!(build_settings_arr, { 'OTHER_LDFLAGS' => [' -ObjC'] })
130+
131+
assert_equal([' -ObjC'], build_settings_arr['OTHER_LDFLAGS'])
132+
133+
# Test setting a new key
134+
override_build_settings!(build_settings, { 'OTHER_CFLAGS' => '-DDEBUG' })
135+
136+
assert_equal('-DDEBUG', build_settings['OTHER_CFLAGS'])
137+
override_build_settings!(build_settings, { 'ONLY_ACTIVE_ARCH' => 'YES' })
138+
139+
assert_equal('YES', build_settings['ONLY_ACTIVE_ARCH'])
140+
end
115141
end

0 commit comments

Comments
 (0)