Skip to content

Commit

Permalink
feat(apple): add :build_setting_overrides to options (#2204)
Browse files Browse the repository at this point in the history
`:build_setting_overrides` allows you to override build settings defined in the
final Xcode project.
  • Loading branch information
okwasniewski authored Sep 4, 2024
1 parent 3ead036 commit b04a565
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ios/pod_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ def try_pod(name, podspec, project_root)
pod name, :podspec => podspec if File.exist?(File.join(project_root, podspec))
end

def override_build_settings!(build_settings, settings_to_append)
settings_to_append&.each do |setting, value|
build_settings[setting] = value
end
end

def use_hermes?(options)
use_hermes = ENV.fetch('USE_HERMES', nil)
return use_hermes == '1' unless use_hermes.nil?
Expand Down
2 changes: 2 additions & 0 deletions ios/test_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ def make_project!(xcodeproj, project_root, target_platform, options)
uitests_build_settings[PRODUCT_BUNDLE_IDENTIFIER] = "#{product_bundle_identifier}UITests"
end

override_build_settings!(build_settings, options[:build_setting_overrides])

build_settings[PRODUCT_DISPLAY_NAME] = display_name
build_settings[PRODUCT_VERSION] = version || '1.0'

Expand Down
26 changes: 26 additions & 0 deletions test/test_pod_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,30 @@ def test_v
assert_equal(1_001_000, v(1, 1, 0))
assert_equal(1_001_001, v(1, 1, 1))
end

def test_override_build_settings
build_settings = { 'OTHER_LDFLAGS' => '-l"Pods-TestApp"', 'ONLY_ACTIVE_ARCH' => 'NO' }

override_build_settings!(build_settings, {})

assert_equal('-l"Pods-TestApp"', build_settings['OTHER_LDFLAGS'])

override_build_settings!(build_settings, { 'OTHER_LDFLAGS' => ' -ObjC' })

assert_equal(' -ObjC', build_settings['OTHER_LDFLAGS'])

# Test passing a table
build_settings_arr = { 'OTHER_LDFLAGS' => ['$(inherited)', '-l"Pods-TestApp"'] }
override_build_settings!(build_settings_arr, { 'OTHER_LDFLAGS' => [' -ObjC'] })

assert_equal([' -ObjC'], build_settings_arr['OTHER_LDFLAGS'])

# Test setting a new key
override_build_settings!(build_settings, { 'OTHER_CFLAGS' => '-DDEBUG' })

assert_equal('-DDEBUG', build_settings['OTHER_CFLAGS'])
override_build_settings!(build_settings, { 'ONLY_ACTIVE_ARCH' => 'YES' })

assert_equal('YES', build_settings['ONLY_ACTIVE_ARCH'])
end
end

0 comments on commit b04a565

Please sign in to comment.