Skip to content

Commit

Permalink
fix(CI): extend logging in architecture-integrity scripts & add Nativ…
Browse files Browse the repository at this point in the history
…eProxy.kt to blacklist (#2281)

## Description

I was initially confused why the CI fails, so I debugged it a bit and it
turned out that we forgot to add `NativeProxy.kt` to blacklist in the
integrity scripts. <- Did it.

Because of the initial confusion I've decided to add some more logging &
error handling mechanisms.

## Test code and steps to reproduce

CI now passes. If similar case happens in the future we will get a nice
error message.

## Checklist

- [x] Ensured that CI passes
  • Loading branch information
kkafar authored Aug 5, 2024
1 parent a886ca1 commit 3097f01
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check-archs-consistency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on:
branches:
- main
paths:
- src/fabric/**
- android/src/paper/java/com/facebook/react/viewmanagers/**
- .github/workflows/check-archs-consistency.yml
- 'src/fabric/**'
- 'android/src/paper/java/com/facebook/react/viewmanagers/**'
- '.github/workflows/check-archs-consistency.yml'
push:
branches:
- main
Expand Down
44 changes: 35 additions & 9 deletions scripts/codegen-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const { execSync } = require('child_process');
const packageJSON = require('../package.json');

const ERROR_PREFIX = 'RNScreens';
const TAG = `[RNScreens]>`;
const ROOT_DIR = path.resolve(__dirname, '..');
const ANDROID_DIR = path.resolve(ROOT_DIR, 'android');
const GENERATED_DIR = path.resolve(ANDROID_DIR, 'build/generated');
Expand All @@ -26,19 +26,34 @@ const SOURCE_FOLDERS = [

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


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

function readdirSync(dir) {
return fs.readdirSync(dir).filter(file => !BLACKLISTED_FILES.has(file));
console.log(`${TAG} readdir: ${dir}`);
return fs.readdirSync(dir).filter(file => {
if (BLACKLISTED_FILES.has(file)) {
console.log(`${TAG} Ignoring blacklisted file: ${file}`);
return false;
}
return true;
});
}

function throwIfFileMissing(filepath) {
if (!fs.lstatSync(filepath, { throwIfNoEntry: false })?.isFile()) {
throw new Error(`${TAG} File ${filepath} does not exist or is not a regular file. Maybe it is not codegen-managed and you forgot to put it in blacklist?`);
}
}

function fixOldArchJavaForRN72Compat(dir) {
console.log(`${TAG} fixOldArchJavaForRN72Compat: ${dir}`);
// see https://github.com/rnmapbox/maps/issues/3193
const files = readdirSync(dir);
files.forEach(file => {
Expand Down Expand Up @@ -67,6 +82,7 @@ function fixOldArchJavaForRN72Compat(dir) {
}

async function generateCodegen() {
console.log(`${TAG} generateCodegen`);
exec(`rm -rf ${GENERATED_DIR}`);
exec(`mkdir -p ${GENERATED_DIR}/source/codegen/`);

Expand All @@ -91,21 +107,21 @@ async function generateCodegenJavaOldArch() {
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.`,
`${TAG} ${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.`,
`${TAG} 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 => {
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.`
`${TAG} ${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 @@ -115,17 +131,26 @@ async function generateCodegenJavaOldArch() {
}

function compareFileAtTwoPaths(filename, firstPath, secondPath) {
const fileA = fs.readFileSync(`${firstPath}/${filename}`, 'utf-8');
const fileB = fs.readFileSync(`${secondPath}/${filename}`, 'utf-8');
console.log(`${TAG} compare file: ${filename} at path first: ${firstPath}, second: ${secondPath}`);
const filepathA = `${firstPath}/${filename}`;
const filepathB = `${secondPath}/${filename}`;

throwIfFileMissing(filepathA);
throwIfFileMissing(filepathB);

const fileA = fs.readFileSync(filepathA, 'utf-8');
const fileB = fs.readFileSync(filepathB, 'utf-8');

if (fileA !== fileB) {
throw new Error(
`[${ERROR_PREFIX}] File ${filename} is different at ${firstPath} and ${secondPath}. Make sure you committed codegen autogenerated files.`,
`${TAG} File ${filename} is different at ${firstPath} and ${secondPath}. Make sure you committed codegen autogenerated files.`,
);
}
}

async function checkCodegenIntegrity() {
console.log(`${TAG} checkCodegenIntegrity`);

await generateCodegen();

SOURCE_FOLDERS.forEach(({codegenPath, oldArchPath}) => {
Expand All @@ -137,3 +162,4 @@ async function checkCodegenIntegrity() {
}

module.exports = { generateCodegenJavaOldArch, checkCodegenIntegrity };

0 comments on commit 3097f01

Please sign in to comment.