feat(apple): add `:build_setting_overrides` to options (#2204)

`:build_setting_overrides` allows you to override build settings defined in the
final Xcode project.
This commit is contained in:
Oskar Kwaśniewski 2024-09-04 21:42:03 +02:00 коммит произвёл GitHub
Родитель 3ead036281
Коммит b04a5656e3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 34 добавлений и 0 удалений

Просмотреть файл

@ -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?

Просмотреть файл

@ -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'

Просмотреть файл

@ -112,4 +112,30 @@ class TestPodHelpers < Minitest::Test
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