Skip to content

Commit

Permalink
Add helper function to create header_search_path (facebook#41353)
Browse files Browse the repository at this point in the history
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

Reviewed By: shwanton

Differential Revision: D51026356

fbshipit-source-id: 7cf03601d94d7680f3fdfcaf52b2fd6bcd48c5b4
  • Loading branch information
cipolleschi authored and Othinn committed Jan 9, 2024
1 parent f4922fc commit 8e9db3e
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
65 changes: 65 additions & 0 deletions packages/react-native/scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def teardown
ENV['USE_HERMES'] = '1'
ENV['USE_FRAMEWORKS'] = nil
system_reset_commands
$RN_PLATFORMS = nil
end

# ======================= #
Expand Down Expand Up @@ -902,6 +903,70 @@ def test_applyATSConfig_plistNonNil
end
end

# =============================================== #
# Test - Create Header Search Path For Frameworks #
# =============================================== #
def test_creatHeaderSearchPathForFrameworks_whenNoPlatformsAndNoExtraPath_createsPlainSearchPath
result = ReactNativePodsUtils.create_header_search_path_for_frameworks("PODS_CONFIGURATION_BUILD_DIR", "React-RCTFabric", "RCTFabric", [])

assert_equal(result, [
"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTFabric/RCTFabric.framework/Headers"
])
end

def test_creatHeaderSearchPathForFrameworks_whenNoPlatformsAndExtraPath_createsPlainSearchPath
result = ReactNativePodsUtils.create_header_search_path_for_frameworks("PODS_CONFIGURATION_BUILD_DIR", "React-Fabric", "React_Fabric", ["react/renderer/components/view/platform/cxx"])

assert_equal(result, [
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx",
])
end

def test_creatHeaderSearchPathForFrameworks_whenEmptyPlatformsAndExtraPath_createsPlainSearchPath
$RN_PLATFORMS = []

result = ReactNativePodsUtils.create_header_search_path_for_frameworks("PODS_CONFIGURATION_BUILD_DIR", "React-Fabric", "React_Fabric", ["react/renderer/components/view/platform/cxx"])

assert_equal(result, [
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx",
])
end

def test_creatHeaderSearchPathForFrameworks_whenOnlyOnePlatformsAndExtraPath_createsPlainSearchPath
$RN_PLATFORMS = ['iOS']

result = ReactNativePodsUtils.create_header_search_path_for_frameworks("PODS_CONFIGURATION_BUILD_DIR", "React-Fabric", "React_Fabric", ["react/renderer/components/view/platform/cxx"])

assert_equal(result, [
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx",
])
end

def test_creatHeaderSearchPathForFrameworks_whenMultiplePlatformsAndExtraPath_createsPlainSearchPath
$RN_PLATFORMS = ["iOS", "macOS"]

result = ReactNativePodsUtils.create_header_search_path_for_frameworks(
"PODS_CONFIGURATION_BUILD_DIR",
"React-Fabric",
"React_Fabric",
[
"react/renderer/components/view/platform/cxx",
"react/renderer/components/view/platform/ios"
]
)

assert_equal(result, [
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric-iOS/React_Fabric.framework/Headers",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric-iOS/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric-iOS/React_Fabric.framework/Headers/react/renderer/components/view/platform/ios",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric-macOS/React_Fabric.framework/Headers",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric-macOS/React_Fabric.framework/Headers/react/renderer/components/view/platform/cxx",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric-macOS/React_Fabric.framework/Headers/react/renderer/components/view/platform/ios",
])
end
end

# ===== #
Expand Down
24 changes: 24 additions & 0 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@ def self.detect_use_frameworks(target_definition)
end
end

def self.create_header_search_path_for_frameworks(base_folder, pod_name, framework_name, additional_paths)
platforms = $RN_PLATFORMS != nil ? $RN_PLATFORMS : []
search_paths = []

if platforms.empty?() || platforms.length() == 1
base_path = File.join("${#{base_folder}}", pod_name, "#{framework_name}.framework", "Headers")
self.add_search_path_to_result(search_paths, base_path, additional_paths)
else
platforms.each { |platform|
base_path = File.join("${#{base_folder}}", "#{pod_name}-#{platform}", "#{framework_name}.framework", "Headers")
self.add_search_path_to_result(search_paths, base_path, additional_paths)
}
end
return search_paths
end

def self.update_search_paths(installer)
return if ENV['USE_FRAMEWORKS'] == nil

Expand Down Expand Up @@ -557,4 +573,12 @@ def self.react_native_pods
"React-hermes",
]
end

def self.add_search_path_to_result(result, base_path, additional_paths)
result << base_path
additional_paths.each { |extra_path|
result << File.join(base_path, extra_path)
}
return result
end
end

0 comments on commit 8e9db3e

Please sign in to comment.