Skip to content

Commit

Permalink
Defragment Codegen in OSS between Old and New Architecture (#41500)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #41500

Right now, the old architecture uses Codegen in a slightly different way w.r.t. the New Architecture.
In the Old Architecture, codegen is used to generate some basic TM and components that are part of Core.

Both architectures use the same scripts that actually generates the code, but they are invoked differently.

This is causing some maintenance costs that we would like to reduce.

## Changelog:
[Internal] - Defragment how Codegen is run between old and new architecture

Reviewed By: dmytrorykun

Differential Revision: D51349874

fbshipit-source-id: 188d3ed436a30a77bd42a26306d4a08666d3a00b
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Nov 17, 2023
1 parent a5d8ea4 commit 1204696
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 583 deletions.

This file was deleted.

9 changes: 0 additions & 9 deletions packages/react-native/ReactCommon/React-rncore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,4 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = { "USE_HEADERMAP" => "YES",
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20" }


use_react_native_codegen!(s, {
:react_native_path => react_native_sources_path,
:js_srcs_dir => "#{react_native_sources_path}/Libraries",
:library_name => "rncore",
:library_type => "components",
:output_dir => "#{react_native_dependency_path}/ReactCommon"
})
end
217 changes: 0 additions & 217 deletions packages/react-native/scripts/cocoapods/__tests__/codegen-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,191 +40,6 @@ def teardown
DirMock.reset()
end

# ============================================== #
# Test - setup_fabric #
# ============================================== #
def testCheckAndGenerateEmptyThirdPartyProvider_whenFileAlreadyExists_doNothing()

# Arrange
FileMock.mocked_existing_files([
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header,
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_implementation,
])

# Act
checkAndGenerateEmptyThirdPartyProvider!(@prefix, false, dir_manager: DirMock, file_manager: FileMock)

# Assert
assert_equal(Pathname.pwd_invocation_count, 1)
assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1)
assert_equal(FileMock.exist_invocation_params, [
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header,
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_implementation,
])
assert_equal(DirMock.exist_invocation_params, [])
assert_equal(Pod::UI.collected_messages, [])
assert_equal($collected_commands, [])
assert_equal(FileMock.open_files.length, 0)
assert_equal(Pod::Executable.executed_commands.length, 0)
end

def testCheckAndGenerateEmptyThirdPartyProvider_whenHeaderMissingAndCodegenMissing_dontBuildCodegen()

# Arrange
FileMock.mocked_existing_files([
@base_path + "/build/" + @third_party_provider_implementation,
])

# Act
assert_nothing_raised {
checkAndGenerateEmptyThirdPartyProvider!(@prefix, false, dir_manager: DirMock, file_manager: FileMock)
}

# Assert
assert_equal(Pathname.pwd_invocation_count, 1)
assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1)
assert_equal(FileMock.exist_invocation_params, [
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header,
@base_path + "/" + @prefix + "/React/Fabric/tmpSchemaList.txt",
])
assert_equal(DirMock.exist_invocation_params, [
@base_path + "/"+ @prefix + "/../react-native-codegen",
])
assert_equal(Pod::UI.collected_messages, [
"[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider",
])
assert_equal($collected_commands, [])
assert_equal(FileMock.open_files.length, 1)
assert_equal(Pod::Executable.executed_commands.length, 1)
end

def testCheckAndGenerateEmptyThirdPartyProvider_whenImplementationMissingAndCodegenrepoExists_dontBuildCodegen()

# Arrange
FileMock.mocked_existing_files([
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header,
@base_path + "/" + @prefix + "/React/Fabric/tmpSchemaList.txt"
])

DirMock.mocked_existing_dirs([
@base_path + "/"+ @prefix + "/../react-native-codegen",
@base_path + "/"+ @prefix + "/../react-native-codegen/lib"
])

# Act
checkAndGenerateEmptyThirdPartyProvider!(@prefix, false, dir_manager: DirMock, file_manager: FileMock)

# Assert
assert_equal(Pathname.pwd_invocation_count, 1)
assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1)
assert_equal(FileMock.exist_invocation_params, [
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header,
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_implementation,
@base_path + "/" + @prefix + "/React/Fabric/tmpSchemaList.txt",
])
assert_equal(DirMock.exist_invocation_params, [
@base_path + "/"+ @prefix + "/../react-native-codegen",
@base_path + "/"+ @prefix + "/../react-native-codegen/lib",
])
assert_equal(Pod::UI.collected_messages, ["[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider"])
assert_equal($collected_commands, [])
assert_equal(FileMock.open_invocation_count, 1)
assert_equal(FileMock.open_files_with_mode[@prefix + "/React/Fabric/tmpSchemaList.txt"], nil)
assert_equal(FileMock.open_files[0].collected_write, ["[]"])
assert_equal(FileMock.open_files[0].fsync_invocation_count, 1)
assert_equal(Pod::Executable.executed_commands[0], {
"command" => "node",
"arguments" => [
@base_path + "/" + @prefix + "/scripts/generate-provider-cli.js",
"--platform", 'ios',
"--schemaListPath", @base_path + "/" + @prefix + "/React/Fabric/tmpSchemaList.txt",
"--outputDir", @base_path + "/" + @prefix + "/React/Fabric"
]
})
assert_equal(FileMock.delete_invocation_count, 1)
assert_equal(FileMock.deleted_files, [ @base_path + "/" + @prefix + "/React/Fabric/tmpSchemaList.txt"])
end

def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen()
# Arrange
codegen_cli_path = @base_path + "/" + @prefix + "/../react-native-codegen"
DirMock.mocked_existing_dirs([
codegen_cli_path,
])
# Act
checkAndGenerateEmptyThirdPartyProvider!(@prefix, false, dir_manager: DirMock, file_manager: FileMock)

# Assert
assert_equal(Pathname.pwd_invocation_count, 1)
assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1)
assert_equal(FileMock.exist_invocation_params, [
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header,
@base_path + "/" + @prefix + "/React/Fabric/" + @tmp_schema_list_file
])
assert_equal(DirMock.exist_invocation_params, [
codegen_cli_path,
codegen_cli_path + "/lib",
])
assert_equal(Pod::UI.collected_messages, [
"[Codegen] building #{codegen_cli_path}",
"[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider"
])
assert_equal($collected_commands, ["~/app/ios/../../../react-native-codegen/scripts/oss/build.sh"])
assert_equal(FileMock.open_files[0].collected_write, ["[]"])
assert_equal(FileMock.open_files[0].fsync_invocation_count, 1)
assert_equal(Pod::Executable.executed_commands[0], {
"command" => "node",
"arguments" => [
@base_path + "/" + @prefix + "/scripts/generate-provider-cli.js",
"--platform", 'ios',
"--schemaListPath", @base_path + "/" + @prefix + "/React/Fabric/" + @tmp_schema_list_file,
"--outputDir", @base_path + "/" + @prefix + "/React/Fabric"
]
})
end

def testCheckAndGenerateEmptyThirdPartyProvider_withAbsoluteReactNativePath_buildCodegen()
# Arrange
rn_path = 'packages/react-native'
codegen_cli_path = rn_path + "/../react-native-codegen"
DirMock.mocked_existing_dirs([
@base_path + "/" + codegen_cli_path,
])

# Act
checkAndGenerateEmptyThirdPartyProvider!(rn_path, false, dir_manager: DirMock, file_manager: FileMock)

# Assert
assert_equal(Pathname.pwd_invocation_count, 1)
assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1)
assert_equal(FileMock.exist_invocation_params, [
@base_path + "/" + rn_path + "/React/Fabric/" + @third_party_provider_header,
@base_path + "/" + rn_path + "/React/Fabric/" + @tmp_schema_list_file
])
assert_equal(DirMock.exist_invocation_params, [
@base_path + "/" + codegen_cli_path,
@base_path + "/" + codegen_cli_path + "/lib",
])
assert_equal(Pod::UI.collected_messages, [
"[Codegen] building #{@base_path + "/" + codegen_cli_path}",
"[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider"
])
assert_equal($collected_commands, [
@base_path + "/" + rn_path + "/../react-native-codegen/scripts/oss/build.sh",
])
assert_equal(FileMock.open_files[0].collected_write, ["[]"])
assert_equal(FileMock.open_files[0].fsync_invocation_count, 1)
assert_equal(Pod::Executable.executed_commands[0], {
"command" => "node",
"arguments" => [
@base_path + "/" + rn_path + "/scripts/generate-provider-cli.js",
"--platform", 'ios',
"--schemaListPath", @base_path + "/" + rn_path + "/React/Fabric/" + @tmp_schema_list_file,
"--outputDir", @base_path + "/" + rn_path + "/React/Fabric"
]
})
end

# ================= #
# Test - RunCodegen #
# ================= #
Expand All @@ -250,36 +65,4 @@ def testRunCodegen_whenNewArchEnabled_runsCodegen
assert_equal(codegen_utils_mock.get_react_codegen_spec_params, [])
assert_equal(codegen_utils_mock.generate_react_codegen_spec_params, [])
end

def testRunCodegen_whenNewArchDisabled_runsCodegen
# Arrange
app_path = "~/app"
config_file = ""
package_json_file = "~/app/package.json"
codegen_specs = { "name" => "React-Codegen" }
codegen_utils_mock = CodegenUtilsMock.new(:react_codegen_spec => codegen_specs)

# Act
run_codegen!(
app_path,
config_file,
:new_arch_enabled => false,
:fabric_enabled => true,
:package_json_file => package_json_file,
:codegen_utils => codegen_utils_mock)

# Assert
assert_equal(codegen_utils_mock.use_react_native_codegen_discovery_params, [])
assert_equal(codegen_utils_mock.get_react_codegen_spec_params, [{
:fabric_enabled => true,
:folly_version=>"2023.08.07.00",
:package_json_file => "~/app/package.json",
:script_phases => nil
}])
assert_equal(codegen_utils_mock.generate_react_codegen_spec_params, [{
:codegen_output_dir=>"build/generated/ios",
:react_codegen_spec=>{"name"=>"React-Codegen"}
}])

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,12 @@ def get_podspec_no_fabric_no_script
},
'dependencies': {
"DoubleConversion": [],
"FBReactNativeSpec": [],
"RCT-Folly": [],
"RCTRequired": [],
"RCTTypeSafety": [],
"React-Core": [],
"React-jsi": [],
"React-jsiexecutor": [],
"React-rncore": [],
"ReactCommon/turbomodule/bridging": [],
"ReactCommon/turbomodule/core": [],
"hermes-engine": [],
Expand All @@ -583,7 +581,6 @@ def get_podspec_fabric_and_script_phases(script_phases)

specs[:dependencies].merge!({
'React-graphics': [],
'React-rncore': [],
'React-Fabric': [],
'React-utils': [],
'React-debug': [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,22 @@ def test_installModulesDependencies_whenNewArchDisabledAndSearchPathsAndCompiler
[
{ :dependency_name => "React-Core" },
{ :dependency_name => "RCT-Folly", "version"=>"2023.08.07.00" },
{ :dependency_name => "glog" }
{ :dependency_name => "glog" },
{ :dependency_name => "React-RCTFabric" },
{ :dependency_name => "React-Codegen" },
{ :dependency_name => "RCTRequired" },
{ :dependency_name => "RCTTypeSafety" },
{ :dependency_name => "ReactCommon/turbomodule/bridging" },
{ :dependency_name => "ReactCommon/turbomodule/core" },
{ :dependency_name => "React-NativeModulesApple" },
{ :dependency_name => "Yoga" },
{ :dependency_name => "React-Fabric" },
{ :dependency_name => "React-graphics" },
{ :dependency_name => "React-utils" },
{ :dependency_name => "React-debug" },
{ :dependency_name => "React-ImageManager" },
{ :dependency_name => "React-rendererdebug" },
{ :dependency_name => "hermes-engine" }
]
)
end
Expand Down
Loading

0 comments on commit 1204696

Please sign in to comment.