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:
committed by
Facebook GitHub Bot
parent
e1b59d63a7
commit
4743040d62
@@ -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,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
@@ -53,12 +53,12 @@ function printTest(e, ext, LTRContainer, RTLContainer, genericContainer) {
|
||||
' *',
|
||||
' * This source code is licensed under the MIT license found in the',
|
||||
' * LICENSE file in the root directory of this source tree.',
|
||||
' */',
|
||||
ext === 'cpp' ? '\n// clang-format off' : '',
|
||||
'// @' +
|
||||
'generated by gentest/gentest-driver.ts from gentest/fixtures/' +
|
||||
ext === 'cpp' ? ' *\n * clang-format off' : ' *',
|
||||
` * MAGIC_PLACEHOLDER`,
|
||||
' * generated by gentest/gentest-driver.ts from gentest/fixtures/' +
|
||||
document.title +
|
||||
'.html',
|
||||
' */',
|
||||
'',
|
||||
]);
|
||||
e.emitPrologue();
|
||||
|
@@ -7,7 +7,8 @@
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"selenium-webdriver": "^4.16.0"
|
||||
"selenium-webdriver": "^4.16.0",
|
||||
"signedsource": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.10.3",
|
||||
|
10
gentest/signedsource.d.ts
vendored
Normal file
10
gentest/signedsource.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
declare module 'signedsource';
|
Reference in New Issue
Block a user