Skip to content

Commit 81a431b

Browse files
sota000facebook-github-bot
authored andcommitted
Add an option to enable USE_CODEGEN_DISCOVERY
Summary: Changelog: [Internal] Adding an option in RN Tester to enable the new codegen discovery option where it uses generate-artifacts.js to codegen native files. It also updates generate-artifacts.js to support the case where react-native is not within node_modules. It also updates the option name for rn-demo-app. Reviewed By: cortinico Differential Revision: D32777912 fbshipit-source-id: f2b76fa61573e3d4507a9f16f8243ac7ca006900
1 parent 1721efb commit 81a431b

File tree

3 files changed

+60
-11
lines changed

3 files changed

+60
-11
lines changed

packages/rn-tester/Podfile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,26 @@ if ENV['USE_HERMES'] == '1'
1818
puts "Using Hermes engine"
1919
end
2020

21-
def pods()
21+
def pods(options = {})
2222
project 'RNTesterPods.xcodeproj'
2323

2424
fabric_enabled = true
2525
puts "Building RNTester with Fabric #{fabric_enabled ? "enabled" : "disabled"}."
2626

2727
prefix_path = "../.."
28+
29+
if options[:use_codegen_discovery]
30+
Pod::UI.puts "[Codegen] Building target with codegen library discovery enabled."
31+
pre_install do |installer|
32+
use_react_native_codegen_discovery!({
33+
react_native_path: prefix_path,
34+
app_path: "#{Dir.pwd}",
35+
fabric_enabled: fabric_enabled,
36+
config_file_dir: "#{Dir.pwd}/node_modules",
37+
})
38+
end
39+
end
40+
2841
use_react_native!(path: prefix_path, fabric_enabled: fabric_enabled, hermes_enabled: ENV['USE_HERMES'] == '1')
2942
pod 'ReactCommon/turbomodule/samples', :path => "#{prefix_path}/ReactCommon"
3043

@@ -38,7 +51,7 @@ def pods()
3851
end
3952

4053
target 'RNTester' do
41-
pods()
54+
pods({ :use_codegen_discovery => ENV['USE_CODEGEN_DISCOVERY'] == '1' })
4255
if !USE_FRAMEWORKS
4356
use_flipper!
4457
end

packages/rn-tester/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ SPEC CHECKSUMS:
881881
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
882882
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
883883
FBLazyVector: b81a2b70c72d8b0aefb652cea22c11e9ffd02949
884-
FBReactNativeSpec: 37e065c0cfc5da966014bf62b50edb066d8206cd
884+
FBReactNativeSpec: 755b7fee1b08aefd74fb2fa9f7312b253719d536
885885
Flipper: 30e8eeeed6abdc98edaf32af0cda2f198be4b733
886886
Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c
887887
Flipper-DoubleConversion: 57ffbe81ef95306cc9e69c4aa3aeeeeb58a6a28c
@@ -923,13 +923,13 @@ SPEC CHECKSUMS:
923923
React-RCTTest: 12bbd7fc2e72bd9920dc7286c5b8ef96639582b6
924924
React-RCTText: e9146b2c0550a83d1335bfe2553760070a2d75c7
925925
React-RCTVibration: 50be9c390f2da76045ef0dfdefa18b9cf9f35cfa
926-
React-rncore: c57d93f56e2d385bdbda34eae2d20d4d3c0c8b4a
926+
React-rncore: d09af3a25cbff0b484776785676c28f3729e07f5
927927
React-runtimeexecutor: 4b0c6eb341c7d3ceb5e2385cb0fdb9bf701024f3
928928
ReactCommon: 7a2714d1128f965392b6f99a8b390e3aa38c9569
929-
ScreenshotManager: 9f69049876d8aafafa13a1a635baa8f7e168eee4
929+
ScreenshotManager: e8a3fc9b2e24b81127b36cb4ebe0eed65090c949
930930
Yoga: c0d06f5380d34e939f55420669a60fe08b79bd75
931931
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
932932

933-
PODFILE CHECKSUM: eb8cf8c55af63e11cb1907f2ae6b457739f4f0af
933+
PODFILE CHECKSUM: 56348fb590e835e25615af889a5cad2d5b227480
934934

935935
COCOAPODS: 1.11.2

scripts/generate-artifacts.js

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const CODEGEN_FABRIC_ENABLED = argv.e;
6565
const CODEGEN_REPO_PATH = `${RN_ROOT}/packages/react-native-codegen`;
6666
const CODEGEN_NPM_PATH = `${RN_ROOT}/../react-native-codegen`;
6767
const CORE_LIBRARIES = new Set(['rncore', 'FBReactNativeSpec']);
68+
const REACT_NATIVE_DEPENDENCY_NAME = 'react-native';
6869

6970
function isReactNativeCoreLibrary(libraryName) {
7071
return CORE_LIBRARIES.has(libraryName);
@@ -78,23 +79,54 @@ function main(appRootDir, outputPath) {
7879
}
7980

8081
try {
81-
// 1. Get app package.json
82+
// Get app package.json
8283
const pkgJson = JSON.parse(
8384
fs.readFileSync(path.join(appRootDir, 'package.json')),
8485
);
8586

86-
// 2. Get dependencies for the app
87+
// Get dependencies for the app
8788
const dependencies = {...pkgJson.dependencies, ...pkgJson.devDependencies};
8889

89-
// 3. Determine which of these are codegen-enabled libraries
90+
const libraries = [];
91+
92+
// Handle react-native core libraries.
93+
// This is required when react-native is outside of node_modules.
94+
console.log('[Codegen] Processing react-native core libraries');
95+
const reactNativePkgJson = path.join(RN_ROOT, CODEGEN_CONFIG_FILENAME);
96+
if (!fs.existsSync(reactNativePkgJson)) {
97+
throw '[Codegen] Error: Could not find config file for react-native.';
98+
}
99+
const reactNativeConfigFile = JSON.parse(
100+
fs.readFileSync(reactNativePkgJson),
101+
);
102+
if (
103+
reactNativeConfigFile[CODEGEN_CONFIG_KEY] == null ||
104+
reactNativeConfigFile[CODEGEN_CONFIG_KEY].libraries == null
105+
) {
106+
throw '[Codegen] Error: Could not find codegen config for react-native.';
107+
}
108+
console.log('[Codegen] Found react-native');
109+
reactNativeConfigFile[CODEGEN_CONFIG_KEY].libraries.forEach(config => {
110+
const libraryConfig = {
111+
library: REACT_NATIVE_DEPENDENCY_NAME,
112+
config,
113+
libraryPath: RN_ROOT,
114+
};
115+
libraries.push(libraryConfig);
116+
});
117+
118+
// Determine which of these are codegen-enabled libraries
90119
const confifDir = CODEGEN_CONFIG_FILE_DIR || path.join(RN_ROOT, '..');
91120
console.log(
92121
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${confifDir}`,
93122
);
94-
const libraries = [];
95123

96-
// Handle react-native and third-party libraries
124+
// Handle third-party libraries
97125
Object.keys(dependencies).forEach(dependency => {
126+
if (dependency === REACT_NATIVE_DEPENDENCY_NAME) {
127+
// react-native should already be added.
128+
return;
129+
}
98130
const codegenConfigFileDir = path.join(confifDir, dependency);
99131
const configFilePath = path.join(
100132
codegenConfigFileDir,
@@ -119,6 +151,10 @@ function main(appRootDir, outputPath) {
119151
}
120152
});
121153

154+
console.log(
155+
'\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in the app',
156+
);
157+
122158
// Handle in-app libraries
123159
if (
124160
pkgJson[CODEGEN_CONFIG_KEY] != null &&

0 commit comments

Comments
 (0)