-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create script to automatically set CLANG_CXX_LANGUAGE_STANDARD on the…
… client project (#33863) Summary: Currently this [section](https://reactnative.dev/docs/next/new-architecture-app-intro#ios-enable-c17-language-feature-support) of the Playbook tells us to set CLANG_CXX_LANGUAGE_STANDARD = "c++17" in the main app target for the new architecture to work. Would be nice to be able to automate that instead ## 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 --> [iOS] [Added] - Cocoapods function to add the `CLANG_CXX_LANGUAGE_STANDARD` to all the targets if needed Pull Request resolved: #33863 Test Plan: I've created some unit tests for the newly added function. I've executed pod install and the ruby tests locally. Reviewed By: cipolleschi Differential Revision: D36484366 Pulled By: f-meloni fbshipit-source-id: 553b092e747bef11d82195619ae1058985fdc325
- Loading branch information
1 parent
baada4e
commit ca8174e
Showing
7 changed files
with
206 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# 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. | ||
|
||
require "test/unit" | ||
require_relative "../new_architecture.rb" | ||
require_relative "./test_utils/InstallerMock.rb" | ||
require_relative "./test_utils/PodMock.rb" | ||
|
||
class NewArchitectureTests < Test::Unit::TestCase | ||
def setup | ||
File.enable_testing_mode! | ||
end | ||
|
||
def teardown | ||
Pod::UI.reset() | ||
end | ||
|
||
|
||
def test_setClangCxxLanguageStandardIfNeeded_whenReactCoreIsPresent | ||
installer = prepare_mocked_installer_with_react_core | ||
set_clang_cxx_language_standard_if_needed(installer) | ||
|
||
assert_equal(installer.aggregate_targets[0].user_project.build_configurations[0].build_settings["CLANG_CXX_LANGUAGE_STANDARD"], "c++17") | ||
assert_equal(installer.aggregate_targets[1].user_project.build_configurations[0].build_settings["CLANG_CXX_LANGUAGE_STANDARD"], "c++17") | ||
assert_equal(installer.pods_project.targets[1].received_resolved_build_setting_parameters, [ReceivedCommonResolvedBuildSettings.new("CLANG_CXX_LANGUAGE_STANDARD", true)]) | ||
assert_equal(Pod::UI.collected_messages, ["Setting CLANG_CXX_LANGUAGE_STANDARD to c++17 on /test/path.xcproj", "Setting CLANG_CXX_LANGUAGE_STANDARD to c++17 on /test/path2.xcproj"]) | ||
end | ||
|
||
def test_setClangCxxLanguageStandardIfNeeded_whenReactCoreIsNotPresent | ||
installer = prepare_mocked_installer_without_react_core | ||
set_clang_cxx_language_standard_if_needed(installer) | ||
|
||
assert_equal(installer.aggregate_targets[0].user_project.build_configurations[0].build_settings["CLANG_CXX_LANGUAGE_STANDARD"], nil) | ||
assert_equal(installer.aggregate_targets[1].user_project.build_configurations[0].build_settings["CLANG_CXX_LANGUAGE_STANDARD"], nil) | ||
assert_equal(installer.pods_project.targets[0].received_resolved_build_setting_parameters, []) | ||
assert_equal(Pod::UI.collected_messages, []) | ||
end | ||
|
||
def test_setClangCxxLanguageStandardIfNeeded_whenThereAreDifferentValuesForLanguageStandard_takesTheFirstValue | ||
installer = prepare_mocked_installer_with_react_core_and_different_language_standards | ||
set_clang_cxx_language_standard_if_needed(installer) | ||
|
||
assert_equal(installer.aggregate_targets[0].user_project.build_configurations[0].build_settings["CLANG_CXX_LANGUAGE_STANDARD"], "c++17") | ||
assert_equal(installer.aggregate_targets[1].user_project.build_configurations[0].build_settings["CLANG_CXX_LANGUAGE_STANDARD"], "c++17") | ||
assert_equal(installer.pods_project.targets[1].received_resolved_build_setting_parameters, [ReceivedCommonResolvedBuildSettings.new("CLANG_CXX_LANGUAGE_STANDARD", true)]) | ||
assert_equal(Pod::UI.collected_messages, ["Setting CLANG_CXX_LANGUAGE_STANDARD to c++17 on /test/path.xcproj", "Setting CLANG_CXX_LANGUAGE_STANDARD to c++17 on /test/path2.xcproj"]) | ||
end | ||
end | ||
|
||
def prepare_mocked_installer_with_react_core | ||
return InstallerMock.new( | ||
PodsProjectMock.new([ | ||
TargetMock.new( | ||
"YogaKit", | ||
[ | ||
BuildConfigurationMock.new("Debug"), | ||
BuildConfigurationMock.new("Release"), | ||
] | ||
), | ||
TargetMock.new( | ||
"React-Core", | ||
[ | ||
BuildConfigurationMock.new("Debug", { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" }), | ||
BuildConfigurationMock.new("Release", { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" }), | ||
] | ||
) | ||
] | ||
), | ||
[ | ||
AggregatedProjectMock.new( | ||
UserProjectMock.new("/test/path.xcproj", [BuildConfigurationMock.new("Debug")]) | ||
), | ||
AggregatedProjectMock.new( | ||
UserProjectMock.new("/test/path2.xcproj", [BuildConfigurationMock.new("Debug")]) | ||
), | ||
] | ||
) | ||
end | ||
|
||
def prepare_mocked_installer_with_react_core_and_different_language_standards | ||
return InstallerMock.new( | ||
PodsProjectMock.new([ | ||
TargetMock.new( | ||
"YogaKit", | ||
[ | ||
BuildConfigurationMock.new("Debug"), | ||
BuildConfigurationMock.new("Release"), | ||
] | ||
), | ||
TargetMock.new( | ||
"React-Core", | ||
[ | ||
BuildConfigurationMock.new("Debug", { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" }), | ||
BuildConfigurationMock.new("Release", { "CLANG_CXX_LANGUAGE_STANDARD" => "new" }), | ||
] | ||
) | ||
] | ||
), | ||
[ | ||
AggregatedProjectMock.new( | ||
UserProjectMock.new("/test/path.xcproj", [BuildConfigurationMock.new("Debug")]) | ||
), | ||
AggregatedProjectMock.new( | ||
UserProjectMock.new("/test/path2.xcproj", [BuildConfigurationMock.new("Debug")]) | ||
), | ||
] | ||
) | ||
end | ||
|
||
def prepare_mocked_installer_without_react_core | ||
return InstallerMock.new( | ||
PodsProjectMock.new([ | ||
TargetMock.new( | ||
"YogaKit", | ||
[ | ||
BuildConfigurationMock.new("Debug"), | ||
BuildConfigurationMock.new("Release"), | ||
] | ||
) | ||
] | ||
), | ||
[ | ||
AggregatedProjectMock.new( | ||
UserProjectMock.new("/test/path.xcproj", [BuildConfigurationMock.new("Debug")]) | ||
), | ||
AggregatedProjectMock.new( | ||
UserProjectMock.new("/test/path2.xcproj", [BuildConfigurationMock.new("Debug")]) | ||
), | ||
] | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# 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. | ||
|
||
def set_clang_cxx_language_standard_if_needed(installer) | ||
language_standard = nil | ||
|
||
installer.pods_project.targets.each do |target| | ||
if target.name == 'React-Core' | ||
language_standard = target.resolved_build_setting("CLANG_CXX_LANGUAGE_STANDARD", resolve_against_xcconfig: true).values[0] | ||
end | ||
end | ||
|
||
unless language_standard.nil? | ||
projects = installer.aggregate_targets | ||
.map{ |t| t.user_project } | ||
.uniq{ |p| p.path } | ||
|
||
projects.each do |project| | ||
Pod::UI.puts("Setting CLANG_CXX_LANGUAGE_STANDARD to #{ language_standard } on #{ project.path }") | ||
|
||
project.build_configurations.each do |config| | ||
config.build_settings["CLANG_CXX_LANGUAGE_STANDARD"] = language_standard | ||
end | ||
|
||
project.save() | ||
end | ||
end | ||
end |