-
-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: change gradle task for copying to new archs into JS scripts #2224
Changes from 18 commits
4eaf9fe
a4a707a
b214415
5d250e2
bbace06
51f3397
bfbc266
cd5e7d0
54bcd79
8e4f7a0
2b31454
adb798d
4106011
6a24cee
bdf4f93
1b2a000
3e8dc1e
cfaa6da
18d3e80
7f96746
f1ff4b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Test consistency between Paper & Fabric | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- src/fabric/** | ||
- android/src/paper/java/com/facebook/react/viewmanagers/** | ||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
concurrency: | ||
group: check-archs-consistency-${{ github.ref }} | ||
cancel-in-progress: true | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
- name: Use Node.js 18 | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 18 | ||
cache: 'yarn' | ||
- name: Install node dependencies | ||
run: yarn | ||
- name: Check Android Paper & Fabric generated interfaces consistency | ||
run: yarn check-archs-consistency |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,3 +135,13 @@ dependencies { | |
} | ||
|
||
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) | ||
apply plugin: 'com.github.node-gradle.node' | ||
|
||
task syncArchs(type: NodeTask) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get it why it's still here. Don't we do everything on the JS side now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's in the app so it shouldn't interfere with the lib. I understood that @kkafar wanted to have it run automatically while developing. It needs to be added per example/test app, so I can just not add it in other packages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah & I want this in screens. |
||
group = 'Build' | ||
description = 'Run sync beetwen Paper and Fabric arch' | ||
yarn_install | ||
script = file('../../../scripts/codegen-sync-archs.js') | ||
} | ||
|
||
tasks['preBuild'].dependsOn(syncArchs) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { checkCodegenIntegrity } = require('./codegen-utils'); | ||
|
||
checkCodegenIntegrity(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { generateCodegenJavaOldArch } = require('./codegen-utils'); | ||
|
||
generateCodegenJavaOldArch(); |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great job with this one! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { execSync } = require('child_process'); | ||
const packageJSON = require('../package.json'); | ||
|
||
const ERROR_PREFIX = 'RNScreens' | ||
const ROOT_DIR = path.resolve(__dirname, '..'); | ||
const ANDROID_DIR = path.resolve(ROOT_DIR, 'android'); | ||
const GENERATED_DIR = path.resolve(ANDROID_DIR, 'build/generated'); | ||
const OLD_ARCH_DIR = path.resolve(ANDROID_DIR, 'src/paper'); | ||
const SPECS_DIR = path.resolve(ROOT_DIR, packageJSON.codegenConfig.jsSrcsDir); | ||
const PACKAGE_NAME = packageJSON.codegenConfig.android.javaPackageName; | ||
const RN_DIR = path.resolve(ROOT_DIR, 'node_modules/react-native'); | ||
const RN_CODEGEN_DIR = path.resolve( | ||
ROOT_DIR, | ||
'node_modules/@react-native/codegen' | ||
); | ||
|
||
const SOURCE_FOLDERS = 'java/com/facebook/react/viewmanagers'; | ||
const CODEGEN_FILES_DIR = `${GENERATED_DIR}/source/codegen/${SOURCE_FOLDERS}`; | ||
const OLD_ARCH_FILES_DIR = `${OLD_ARCH_DIR}/${SOURCE_FOLDERS}`; | ||
|
||
function exec(command) { | ||
console.log(`[${PACKAGE_NAME}]> ` + command); | ||
execSync(command); | ||
} | ||
|
||
function fixOldArchJavaForRN72Compat(dir) { | ||
// see https://github.com/rnmapbox/maps/issues/3193 | ||
const files = fs.readdirSync(dir); | ||
files.forEach(file => { | ||
const filePath = path.join(dir, file); | ||
const fileExtension = path.extname(file); | ||
if (fileExtension === '.java') { | ||
let fileContent = fs.readFileSync(filePath, 'utf-8'); | ||
let newFileContent = fileContent.replace( | ||
/extends ReactContextBaseJavaModule implements TurboModule/g, | ||
'extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule' | ||
); | ||
if (fileContent !== newFileContent) { | ||
// also insert an import line with `import com.facebook.react.bridge.ReactModuleWithSpec;` | ||
newFileContent = newFileContent.replace( | ||
/import com.facebook.react.bridge.ReactMethod;/, | ||
'import com.facebook.react.bridge.ReactMethod;\nimport com.facebook.react.bridge.ReactModuleWithSpec;' | ||
); | ||
|
||
console.log(' => fixOldArchJava applied to:', filePath); | ||
fs.writeFileSync(filePath, newFileContent, 'utf-8'); | ||
} | ||
} else if (fs.lstatSync(filePath).isDirectory()) { | ||
fixOldArchJavaForRN72Compat(filePath); | ||
} | ||
}); | ||
} | ||
|
||
async function generateCodegen() { | ||
exec(`rm -rf ${GENERATED_DIR}`); | ||
exec(`mkdir -p ${GENERATED_DIR}/source/codegen/`); | ||
|
||
exec( | ||
`node ${RN_CODEGEN_DIR}/lib/cli/combine/combine-js-to-schema-cli.js --platform android ${GENERATED_DIR}/source/codegen/schema.json ${SPECS_DIR}` | ||
); | ||
exec( | ||
`node ${RN_DIR}/scripts/generate-specs-cli.js --platform android --schemaPath ${GENERATED_DIR}/source/codegen/schema.json --outputDir ${GENERATED_DIR}/source/codegen --javaPackageName ${PACKAGE_NAME}` | ||
); | ||
|
||
fixOldArchJavaForRN72Compat(`${GENERATED_DIR}/source/codegen/java/`); | ||
} | ||
|
||
async function generateCodegenJavaOldArch() { | ||
await generateCodegen(); | ||
|
||
const generatedFiles = fs.readdirSync(CODEGEN_FILES_DIR); | ||
const oldArchFiles = fs.readdirSync(OLD_ARCH_FILES_DIR); | ||
maciekstosio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const existingFilesSet = new Set(oldArchFiles.map(fileName => fileName)); | ||
|
||
generatedFiles.forEach(generatedFile => { | ||
if (!existingFilesSet.has(generatedFile)) { | ||
console.warn( | ||
`[${ERROR_PREFIX}] ${generatedFile} not found in paper dir, if it's used on Android you need to copy it manually and implement yourself before using auto-copy feature.` | ||
); | ||
} | ||
}); | ||
|
||
if (oldArchFiles.length === 0) { | ||
console.warn( | ||
`[${ERROR_PREFIX}] Paper destination with codegen interfaces is empty. This might be okay if you don't have any interfaces/delegates used on Android, otherwise please check if OLD_ARCH_DIR and SOURCE_FOLDERS are set properly.` | ||
); | ||
} | ||
|
||
oldArchFiles.forEach(oldArchFile => { | ||
if (!fs.existsSync(`${CODEGEN_FILES_DIR}/${oldArchFile}`)) { | ||
console.warn( | ||
`[${ERROR_PREFIX}] ${existingFile.name} file does not exist in codegen artifacts source destination. Please check if you still need this interface/delagete.` | ||
); | ||
} | ||
}); | ||
|
||
oldArchFiles.forEach(file => { | ||
exec(`cp -rf ${CODEGEN_FILES_DIR}/${file} ${OLD_ARCH_FILES_DIR}/${file}`); | ||
}); | ||
} | ||
|
||
function compareFileAtTwoPaths(filename, firstPath, secondPath) { | ||
const fileA = fs.readFileSync(`${firstPath}/${filename}`, 'utf-8'); | ||
const fileB = fs.readFileSync(`${secondPath}/${filename}`, 'utf-8'); | ||
|
||
maciekstosio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (fileA !== fileB) { | ||
throw new Error( | ||
`[${ERROR_PREFIX}] File ${filename} is different at ${firstPath} and ${secondPath}. Make sure you commited codegen autogenerated files.` | ||
); | ||
} | ||
} | ||
|
||
async function checkCodegenIntegrity() { | ||
await generateCodegen(); | ||
|
||
const oldArchFiles = fs.readdirSync(OLD_ARCH_FILES_DIR); | ||
oldArchFiles.forEach(file => { | ||
compareFileAtTwoPaths(file, CODEGEN_FILES_DIR, OLD_ARCH_FILES_DIR); | ||
}); | ||
} | ||
|
||
module.exports = { generateCodegenJavaOldArch, checkCodegenIntegrity }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use
v4
script versions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:(