Skip to content
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

fix: Fixes to sync archs scripts #2259

Merged
merged 9 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/check-archs-consistency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ on:
paths:
- src/fabric/**
- android/src/paper/java/com/facebook/react/viewmanagers/**
- .github/workflows/check-archs-consistency.yml
push:
branches:
- main
workflow_dispatch:

jobs:
check:
runs-on: ubuntu-latest
Expand All @@ -14,13 +20,13 @@ jobs:
cancel-in-progress: true
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Use Node.js 18
uses: actions/setup-node@v2
uses: actions/setup-node@v4
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
run: yarn architectures-consistency-check
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

package com.swmansion.rnscreens;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactModuleWithSpec;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import javax.annotation.Nonnull;
Expand All @@ -29,4 +31,6 @@ public NativeScreensModuleSpec(ReactApplicationContext reactContext) {
public @Nonnull String getName() {
return NAME;
}


}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"lint": "yarn lint-js && yarn lint-android",
"release": "yarn prepare && npm login && release-it",
"prepare": "bob build && husky install",
"check-archs-consistency": "node ./scripts/codegen-check-consistency.js",
"sync-archs": "node ./scripts/codegen-sync-archs.js"
"architectures-consistency-check": "node ./scripts/codegen-check-consistency.js",
"sync-architectures": "node ./scripts/codegen-sync-archs.js"
},
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down Expand Up @@ -130,7 +130,7 @@
"android/src/main/cpp/.{cpp, h}": "yarn format-android-cpp",
"android/**/*.kt": "yarn format-android",
"ios/**/*.{h,m,mm,cpp}": "yarn format-ios",
"src/fabric/*.ts": "yarn sync-archs"
"src/fabric/*.ts": "yarn sync-architectures"
},
"react-native-builder-bob": {
"source": "src",
Expand Down
75 changes: 45 additions & 30 deletions scripts/codegen-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,31 @@ const RN_CODEGEN_DIR = path.resolve(
'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}`;
const SOURCE_FOLDER = 'java/com/facebook/react/viewmanagers';
const SCREENS_SOURCE_FOLDER = 'java/com/swmansion/rnscreens'

const SOURCE_FOLDERS = [
{codegenPath: `${GENERATED_DIR}/source/codegen/${SOURCE_FOLDER}`, oldArchPath: `${OLD_ARCH_DIR}/${SOURCE_FOLDER}`},
{codegenPath: `${GENERATED_DIR}/source/codegen/${SCREENS_SOURCE_FOLDER}`, oldArchPath: `${OLD_ARCH_DIR}/${SCREENS_SOURCE_FOLDER}`},
]

const BLACKLISTED_FILES = new Set([
'FabricEnabledViewGroup.kt',
]);


function exec(command) {
console.log(`[${ERROR_PREFIX}]> ` + command);
execSync(command);
}

function readdirSync(dir) {
return fs.readdirSync(dir).filter(file => !BLACKLISTED_FILES.has(file));
}

function fixOldArchJavaForRN72Compat(dir) {
// see https://github.com/rnmapbox/maps/issues/3193
const files = fs.readdirSync(dir);
const files = readdirSync(dir);
files.forEach(file => {
const filePath = path.join(dir, file);
const fileExtension = path.extname(file);
Expand Down Expand Up @@ -70,34 +83,34 @@ async function generateCodegen() {
async function generateCodegenJavaOldArch() {
await generateCodegen();

const generatedFiles = fs.readdirSync(CODEGEN_FILES_DIR);
const oldArchFiles = fs.readdirSync(OLD_ARCH_FILES_DIR);
const existingFilesSet = new Set(oldArchFiles.map(fileName => fileName));
SOURCE_FOLDERS.forEach(({codegenPath, oldArchPath}) => {
const generatedFiles = readdirSync(codegenPath);
const oldArchFiles = readdirSync(oldArchPath);
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.`,
);
}
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.`,
);
}
});

oldArchFiles.forEach(oldArchFile => {
if (!fs.existsSync(`${CODEGEN_FILES_DIR}/${oldArchFile}`)) {
if (oldArchFiles.length === 0) {
console.warn(
`[${ERROR_PREFIX}] ${existingFile.name} file does not exist in codegen artifacts source destination. Please check if you still need this interface/delagete.`,
`[${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(file => {
exec(`cp -rf ${CODEGEN_FILES_DIR}/${file} ${OLD_ARCH_FILES_DIR}/${file}`);
oldArchFiles.forEach(file => {
if (!fs.existsSync(`${codegenPath}/${file}`)) {
console.warn(
`[${ERROR_PREFIX}] ${file} file does not exist in codegen artifacts source destination. Please check if you still need this interface/delagete.`
);
} else {
exec(`cp -rf ${codegenPath}/${file} ${oldArchPath}/${file}`);
}
});
});
}

Expand All @@ -107,17 +120,19 @@ function compareFileAtTwoPaths(filename, firstPath, secondPath) {

if (fileA !== fileB) {
throw new Error(
`[${ERROR_PREFIX}] File ${filename} is different at ${firstPath} and ${secondPath}. Make sure you commited codegen autogenerated files.`,
`[${ERROR_PREFIX}] File ${filename} is different at ${firstPath} and ${secondPath}. Make sure you committed 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);
SOURCE_FOLDERS.forEach(({codegenPath, oldArchPath}) => {
const oldArchFiles = readdirSync(oldArchPath);
oldArchFiles.forEach(file => {
compareFileAtTwoPaths(file, codegenPath, oldArchPath);
});
});
}

Expand Down
Loading