Sign generated tests (#1503)

Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1503

This diff makes it so that our driver will sign all of the generated files to help ensure that they are not edited by hand. Next I will add CI to actually verify the signature

Reviewed By: NickGerleman

Differential Revision: D51966201

fbshipit-source-id: f7e3f4fde1c98832212a448b2dcc8e21be0560c4
This commit is contained in:
Joe Vilches
2023-12-14 11:48:22 -08:00
committed by Facebook GitHub Bot
parent e1b59d63a7
commit 4743040d62
69 changed files with 253 additions and 160 deletions

View File

@@ -17,6 +17,16 @@ import {fileURLToPath} from 'url';
import {stdin, stdout} from 'node:process';
import minimist from 'minimist';
import readline from 'node:readline/promises';
import signedsource from 'signedsource';
function addSignatureToSourceCode(sourceCode: string): string {
const codeWithToken = sourceCode.replace(
'MAGIC_PLACEHOLDER',
signedsource.getSigningToken(),
);
return signedsource.signFile(codeWithToken);
}
const argv = minimist(process.argv.slice(2));
const specificFixture = argv.f || argv.fixture;
@@ -90,22 +100,26 @@ for (const fileName of fixtures) {
await fs.writeFile(
`${yogaDir}/tests/generated/${fileNameNoExtension}.cpp`,
JSON.parse(logs[0].message.replace(/^[^"]*/, '')),
addSignatureToSourceCode(JSON.parse(logs[0].message.replace(/^[^"]*/, ''))),
);
await fs.writeFile(
`${yogaDir}/java/tests/com/facebook/yoga/${fileNameNoExtension}.java`,
JSON.parse(logs[1].message.replace(/^[^"]*/, '')).replace(
'YogaTest',
fileNameNoExtension,
addSignatureToSourceCode(
JSON.parse(logs[1].message.replace(/^[^"]*/, '')).replace(
'YogaTest',
fileNameNoExtension,
),
),
);
await fs.writeFile(
`${yogaDir}/javascript/tests/generated/${fileNameNoExtension}.test.ts`,
JSON.parse(logs[2].message.replace(/^[^"]*/, '')).replace(
'YogaTest',
fileNameNoExtension,
addSignatureToSourceCode(
JSON.parse(logs[2].message.replace(/^[^"]*/, '')).replace(
'YogaTest',
fileNameNoExtension,
),
),
);