mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
1bc9ddbce3
Summary: Fixed Flipper not recognizing app when using custom Xcode configuration names. This fixes the problem that renaming the "Debug" Xcode configuration causes Flipper to not work. Despite using the recommended `:configurations` parameters and instructing Cocoapods that it was a debug build (see https://github.com/facebook/react-native/issues/34332), it still wouldn't recognize the app due to missing C preprocessor flags, specifically it was missing `-DFB_SONARKIT_ENABLED=1`. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [General] [Fixed] - Flipper now supports custom Xcode build configuration names Pull Request resolved: https://github.com/facebook/react-native/pull/34333 Test Plan: I applied the PR change to 0.68.2 (which work similarly but code was refactored since then). I then used `patch-package` to test the change and the fix worked on 2 separate projects. Patch-package change equivalent: ```diff diff --git a/node_modules/react-native/scripts/react_native_pods.rb b/node_modules/react-native/scripts/react_native_pods.rb index f2ceeda..2ea57d6 100644 --- a/node_modules/react-native/scripts/react_native_pods.rb +++ b/node_modules/react-native/scripts/react_native_pods.rb @@ -180,7 +180,7 @@ def flipper_post_install(installer) # Enable flipper for React-Core Debug configuration if target.name == 'React-Core' target.build_configurations.each do |config| - if config.name == 'Debug' + if config.debug? config.build_settings['OTHER_CFLAGS'] = "$(inherited) -DFB_SONARKIT_ENABLED=1" end end ``` **Screen shot of Xcode after the patch has been applied, for RN v0.68.2:**  Reviewed By: dmitryrykun Differential Revision: D38373812 Pulled By: cipolleschi fbshipit-source-id: d2949927084160bf0c6f8af37a7966dd22fea9a6
214 lines
6.3 KiB
Ruby
214 lines
6.3 KiB
Ruby
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||
#
|
||
# This source code is licensed under the MIT license found in the
|
||
# LICENSE file in the root directory of this source tree.
|
||
|
||
|
||
# This file replicate the structure of the Installer used Cocoapods in the post_install step.
|
||
#
|
||
# To use it, add `require_relative path/to/InstallerMock.rb` into your test file
|
||
#
|
||
# ## Initialization
|
||
# You can create a new mock with the `InstallerMock.new` statement. In this case, you will
|
||
# create an empty mock.
|
||
#
|
||
# It's possible to create complex with the initializer. To create an Installer with a pod, for example, we can
|
||
# use the following code:
|
||
#
|
||
# ```ruby
|
||
# installer = Installer.new(
|
||
# PodsProjectMock.new([
|
||
# TargetMock.new(
|
||
# "MyPod",
|
||
# [
|
||
# BuildConfigurationMock.new("Debug"),
|
||
# ]
|
||
# )
|
||
# )
|
||
# )
|
||
# ```
|
||
#
|
||
# ## Assert
|
||
# All the properties of these objects are accessible in read mode.
|
||
# To access the target's list, for example, you can use the following line:
|
||
#
|
||
# ```ruby
|
||
# targets = installer.pods_project.targets
|
||
# ```
|
||
|
||
class InstallerMock
|
||
attr_reader :pods_project
|
||
attr_reader :aggregate_targets
|
||
attr_reader :target_installation_results
|
||
|
||
InstallationResults = Struct.new(:pod_target_installation_results, :aggregate_target_installation_results)
|
||
|
||
def initialize(pods_project = PodsProjectMock.new, aggregate_targets = [AggregatedProjectMock.new],
|
||
pod_target_installation_results: {},
|
||
aggregate_target_installation_results: {})
|
||
@pods_project = pods_project
|
||
@aggregate_targets = aggregate_targets
|
||
|
||
@target_installation_results = InstallationResults.new(pod_target_installation_results, aggregate_target_installation_results)
|
||
aggregate_targets.each do |aggregate_target|
|
||
aggregate_target.user_project.native_targets.each do |target|
|
||
@target_installation_results.pod_target_installation_results[target.name] = TargetInstallationResultMock.new(target, target)
|
||
end
|
||
end
|
||
pods_project.native_targets.each do |target|
|
||
@target_installation_results.pod_target_installation_results[target.name] = TargetInstallationResultMock.new(target, target)
|
||
end
|
||
end
|
||
|
||
def target_with_name(name)
|
||
return @pods_project.targets
|
||
.select { |target| target.name == name }
|
||
.first
|
||
end
|
||
end
|
||
|
||
class PodsProjectMock
|
||
attr_reader :targets
|
||
attr_reader :native_targets
|
||
attr_reader :path
|
||
attr_reader :build_configurations
|
||
@pod_group
|
||
attr_reader :save_invocation_count
|
||
|
||
def initialize(targets = [], pod_group = {}, path = "test/path-pod.xcodeproj", build_configurations = [], native_targets: [])
|
||
@targets = targets
|
||
@pod_group = pod_group
|
||
@path = path
|
||
@build_configurations = build_configurations
|
||
@save_invocation_count = 0
|
||
@native_targets = native_targets
|
||
end
|
||
|
||
def pod_group(name)
|
||
return @pod_group[name]
|
||
end
|
||
|
||
def save()
|
||
@save_invocation_count += 1
|
||
end
|
||
end
|
||
|
||
class AggregatedProjectMock
|
||
attr_reader :user_project
|
||
attr_reader :xcconfigs
|
||
|
||
@base_path
|
||
|
||
def initialize(user_project = UserProjectMock.new, xcconfigs: {}, base_path: "")
|
||
@user_project = user_project
|
||
@xcconfigs = xcconfigs
|
||
@base_path = base_path
|
||
end
|
||
|
||
def xcconfig_path(config_name)
|
||
return File.join(@base_path, "#{config_name}.xcconfig")
|
||
end
|
||
end
|
||
|
||
class UserProjectMock
|
||
attr_reader :path
|
||
attr_reader :build_configurations
|
||
attr_reader :native_targets
|
||
|
||
attr_reader :save_invocation_count
|
||
|
||
|
||
def initialize(path = "/test/path.xcproj", build_configurations = [], native_targets: [])
|
||
@path = path
|
||
@build_configurations = build_configurations
|
||
@native_targets = native_targets
|
||
@save_invocation_count = 0
|
||
end
|
||
|
||
def save()
|
||
@save_invocation_count += 1
|
||
end
|
||
end
|
||
|
||
class XCConfigMock
|
||
attr_reader :name
|
||
attr_accessor :attributes
|
||
attr_reader :save_as_invocation
|
||
|
||
def initialize(name, attributes: {})
|
||
@name = name
|
||
@attributes = attributes
|
||
@save_as_invocation = []
|
||
end
|
||
|
||
def save_as(file_path)
|
||
@save_as_invocation.push(file_path)
|
||
end
|
||
end
|
||
|
||
ReceivedCommonResolvedBuildSettings = Struct.new(:key, :resolve_against_xcconfig)
|
||
|
||
class TargetMock
|
||
attr_reader :name
|
||
attr_reader :build_configurations
|
||
attr_reader :product_type
|
||
|
||
attr_reader :received_resolved_build_setting_parameters
|
||
|
||
def initialize(name, build_configurations = [], product_type = nil)
|
||
@name = name
|
||
@build_configurations = build_configurations
|
||
unless product_type.nil?
|
||
@product_type = product_type
|
||
end
|
||
@received_resolved_build_setting_parameters = []
|
||
end
|
||
|
||
def resolved_build_setting(key, resolve_against_xcconfig: false)
|
||
received_resolved_build_setting_parameters.append(ReceivedCommonResolvedBuildSettings.new(key, resolve_against_xcconfig))
|
||
|
||
return {name: build_configurations[0].build_settings[key]}
|
||
end
|
||
end
|
||
|
||
class BuildConfigurationMock
|
||
attr_reader :name
|
||
attr_reader :build_settings
|
||
@is_debug
|
||
|
||
def initialize(name, build_settings = {}, is_debug: false)
|
||
@name = name
|
||
@build_settings = build_settings
|
||
@is_debug = is_debug
|
||
end
|
||
|
||
def debug?
|
||
return @is_debug
|
||
end
|
||
end
|
||
|
||
class TargetInstallationResultMock
|
||
attr_reader :target
|
||
attr_reader :native_target
|
||
attr_reader :resource_bundle_targets
|
||
attr_reader :test_native_targets
|
||
attr_reader :test_resource_bundle_targets
|
||
attr_reader :test_app_host_targets
|
||
attr_reader :app_native_targets
|
||
attr_reader :app_resource_bundle_targets
|
||
|
||
def initialize(target = TargetMock, native_target = TargetMock,
|
||
resource_bundle_targets = [], test_native_targets = [],
|
||
test_resource_bundle_targets = {}, test_app_host_targets = [],
|
||
app_native_targets = {}, app_resource_bundle_targets = {})
|
||
@target = target
|
||
@native_target = native_target
|
||
@resource_bundle_targets = resource_bundle_targets
|
||
@test_native_targets = test_native_targets
|
||
@test_resource_bundle_targets = test_resource_bundle_targets
|
||
@test_app_host_targets = test_app_host_targets
|
||
@app_native_targets = app_native_targets
|
||
@app_resource_bundle_targets = app_resource_bundle_targets
|
||
end
|
||
end
|