Skip to content

Commit 5602085

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Add helper function to create header_search_path (facebook#41353)
Summary: Pull Request resolved: facebook#41353 Last week I helped macOS to work with static framework. When multiple platforms are specified, frameworks are build in two variants, the iOS and macOS one. This break all the HEADER_SEARCH_PATHS as now we have to properly specify the base folder from which the search path is generated. See also [this PR](microsoft#1967) where I manually make MacOS work with `use_framewroks!` In order to make the infra scalable and avoid a maintenance nightmare for macOS and future platform, we are introducing this function that should factor out the platforms from the generation of header search paths. ## Changelog: [Internal] - Add helper function to create header_search_path Differential Revision: D51026356 fbshipit-source-id: 01beddb658d6d5c9896e83c2a548bfdbf5876a4a
1 parent d11d5f3 commit 5602085

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

packages/react-native/scripts/cocoapods/__tests__/utils-test.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def teardown
3535
ENV['USE_HERMES'] = '1'
3636
ENV['USE_FRAMEWORKS'] = nil
3737
system_reset_commands
38+
$RN_PLATFORMS = nil
3839
end
3940

4041
# ======================= #
@@ -902,6 +903,70 @@ def test_applyATSConfig_plistNonNil
902903
end
903904
end
904905

906+
# =============================================== #
907+
# Test - Create Header Search Path For Frameworks #
908+
# =============================================== #
909+
def test_creatHeaderSearchPathForFrameworks_whenNoPlatformsAndNoExtraPath_createsPlainSearchPath
910+
result = ReactNativePodsUtils.create_header_search_path_for_frameworks("PODS_CONFIGURATION_BUILD_DIR", "React-RCTFabric", "RCTFabric", [])
911+
912+
assert_equal(result, [
913+
"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTFabric/RCTFabric.framework/Headers"
914+
])
915+
end
916+
917+
def test_creatHeaderSearchPathForFrameworks_whenNoPlatformsAndExtraPath_createsPlainSearchPath
918+
result = ReactNativePodsUtils.create_header_search_path_for_frameworks("PODS_CONFIGURATION_BUILD_DIR", "React-Fabric", "React_Fabric", ["react/renderer/components/view/platform/cxx"])
919+
920+
assert_equal(result, [
921+
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers",
922+
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx",
923+
])
924+
end
925+
926+
def test_creatHeaderSearchPathForFrameworks_whenEmptyPlatformsAndExtraPath_createsPlainSearchPath
927+
$RN_PLATFORMS = []
928+
929+
result = ReactNativePodsUtils.create_header_search_path_for_frameworks("PODS_CONFIGURATION_BUILD_DIR", "React-Fabric", "React_Fabric", ["react/renderer/components/view/platform/cxx"])
930+
931+
assert_equal(result, [
932+
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers",
933+
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx",
934+
])
935+
end
936+
937+
def test_creatHeaderSearchPathForFrameworks_whenOnlyOnePlatformsAndExtraPath_createsPlainSearchPath
938+
$RN_PLATFORMS = ['iOS']
939+
940+
result = ReactNativePodsUtils.create_header_search_path_for_frameworks("PODS_CONFIGURATION_BUILD_DIR", "React-Fabric", "React_Fabric", ["react/renderer/components/view/platform/cxx"])
941+
942+
assert_equal(result, [
943+
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers",
944+
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx",
945+
])
946+
end
947+
948+
def test_creatHeaderSearchPathForFrameworks_whenMultiplePlatformsAndExtraPath_createsPlainSearchPath
949+
$RN_PLATFORMS = ["iOS", "macOS"]
950+
951+
result = ReactNativePodsUtils.create_header_search_path_for_frameworks(
952+
"PODS_CONFIGURATION_BUILD_DIR",
953+
"React-Fabric",
954+
"React_Fabric",
955+
[
956+
"react/renderer/components/view/platform/cxx",
957+
"react/renderer/components/view/platform/ios"
958+
]
959+
)
960+
961+
assert_equal(result, [
962+
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric-iOS/React_Fabric.framework/Headers",
963+
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric-iOS/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx",
964+
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric-iOS/React_Fabric.framework/Headers/react/renderer/components/view/platform/ios",
965+
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric-macOS/React_Fabric.framework/Headers",
966+
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric-macOS/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx",
967+
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric-macOS/React_Fabric.framework/Headers/react/renderer/components/view/platform/ios",
968+
])
969+
end
905970
end
906971

907972
# ===== #

packages/react-native/scripts/cocoapods/utils.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,22 @@ def self.detect_use_frameworks(target_definition)
228228
end
229229
end
230230

231+
def self.create_header_search_path_for_frameworks(base_folder, pod_name, framework_name, additional_paths)
232+
platforms = $RN_PLATFORMS != nil ? $RN_PLATFORMS : []
233+
search_paths = []
234+
235+
if platforms.empty?() || platforms.length() == 1
236+
base_path = File.join("${#{base_folder}}", pod_name, "#{framework_name}.framework", "Headers")
237+
self.add_search_path_to_result(search_paths, base_path, additional_paths)
238+
else
239+
platforms.each { |platform|
240+
base_path = File.join("${#{base_folder}}", "#{pod_name}-#{platform}", "#{framework_name}.framework", "Headers")
241+
self.add_search_path_to_result(search_paths, base_path, additional_paths)
242+
}
243+
end
244+
return search_paths
245+
end
246+
231247
def self.update_search_paths(installer)
232248
return if ENV['USE_FRAMEWORKS'] == nil
233249

@@ -557,4 +573,12 @@ def self.react_native_pods
557573
"React-hermes",
558574
]
559575
end
576+
577+
def self.add_search_path_to_result(result, base_path, additional_paths)
578+
result << base_path
579+
additional_paths.each { |extra_path|
580+
result << File.join(base_path, extra_path)
581+
}
582+
return result
583+
end
560584
end

0 commit comments

Comments
 (0)