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(CI): extend logging in architecture-integrity scripts & add NativeProxy.kt to blacklist #2281

Merged
merged 6 commits into from
Aug 5, 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
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 };

Loading