diff --git a/packages/react-native-fantom/runner/runner.js b/packages/react-native-fantom/runner/runner.js index 74c24e82126f4f..eb46e4653a4cac 100644 --- a/packages/react-native-fantom/runner/runner.js +++ b/packages/react-native-fantom/runner/runner.js @@ -24,7 +24,7 @@ import { getDebugInfoFromCommandResult, getShortHash, printConsoleLogs, - runBuck2, + runBuck2Sync, symbolicateStackTrace, } from './utils'; import fs from 'fs'; @@ -43,7 +43,7 @@ const BUILD_OUTPUT_PATH = fs.mkdtempSync( const PRINT_FANTOM_OUTPUT: false = false; -function parseRNTesterCommandResult(result: ReturnType): { +function parseRNTesterCommandResult(result: ReturnType): { logs: $ReadOnlyArray, testResult: TestSuiteResult, } { @@ -99,7 +99,7 @@ function generateBytecodeBundle({ bytecodePath: string, isOptimizedMode: boolean, }): void { - const hermesCompilerCommandResult = runBuck2( + const hermesCompilerCommandResult = runBuck2Sync( [ 'run', ...getBuckModesForPlatform(isOptimizedMode), @@ -202,7 +202,7 @@ module.exports = async function runTest( }); } - const rnTesterCommandResult = runBuck2([ + const rnTesterCommandResult = runBuck2Sync([ 'run', ...getBuckModesForPlatform( testConfig.mode === FantomTestConfigMode.Optimized, diff --git a/packages/react-native-fantom/runner/utils.js b/packages/react-native-fantom/runner/utils.js index 97a486dcebaf3a..4e426a10cdaee9 100644 --- a/packages/react-native-fantom/runner/utils.js +++ b/packages/react-native-fantom/runner/utils.js @@ -44,24 +44,17 @@ export function getBuckModesForPlatform( return ['@//xplat/mode/react-force-cxx-platform', osPlatform]; } -type SpawnResultWithOriginalCommand = { +type SyncCommandResult = { ...ReturnType, originalCommand: string, ... }; -export function runBuck2(args: Array): SpawnResultWithOriginalCommand { - // If these tests are already running from withing a buck2 process, e.g. when - // they are scheduled by a `buck2 test` wrapper, calling `buck2` again would - // cause a daemon-level deadlock. - // To prevent this - explicitly pass custom `--isolation-dir`. Reuse the same - // dir across tests (even running in different jest processes) to properly - // employ caching. - if (process.env.BUCK2_WRAPPER != null) { - args.unshift('--isolation-dir', BUCK_ISOLATION_DIR); - } - - const result = spawnSync('buck2', args, { +export function runCommandSync( + command: string, + args: Array, +): SyncCommandResult { + const result = spawnSync(command, args, { encoding: 'utf8', env: { ...process.env, @@ -71,12 +64,12 @@ export function runBuck2(args: Array): SpawnResultWithOriginalCommand { return { ...result, - originalCommand: `buck2 ${args.join(' ')}`, + originalCommand: `${command} ${args.join(' ')}`, }; } export function getDebugInfoFromCommandResult( - commandResult: SpawnResultWithOriginalCommand, + commandResult: SyncCommandResult, ): string { const maybeSignal = commandResult.signal != null ? `, signal: ${commandResult.signal}` : ''; @@ -102,6 +95,20 @@ export function getDebugInfoFromCommandResult( return logLines.join('\n'); } +export function runBuck2Sync(args: Array): SyncCommandResult { + // If these tests are already running from withing a buck2 process, e.g. when + // they are scheduled by a `buck2 test` wrapper, calling `buck2` again would + // cause a daemon-level deadlock. + // To prevent this - explicitly pass custom `--isolation-dir`. Reuse the same + // dir across tests (even running in different jest processes) to properly + // employ caching. + if (process.env.BUCK2_WRAPPER != null) { + args.unshift('--isolation-dir', BUCK_ISOLATION_DIR); + } + + return runCommandSync('buck2', args); +} + export function getShortHash(contents: string): string { return crypto.createHash('md5').update(contents).digest('hex').slice(0, 8); } diff --git a/packages/react-native-fantom/runner/warmup/warmup.js b/packages/react-native-fantom/runner/warmup/warmup.js index a5503c154ad0de..93a918e09446e5 100644 --- a/packages/react-native-fantom/runner/warmup/warmup.js +++ b/packages/react-native-fantom/runner/warmup/warmup.js @@ -12,7 +12,7 @@ import { getBuckModesForPlatform, getDebugInfoFromCommandResult, - runBuck2, + runBuck2Sync, } from '../utils'; // $FlowExpectedError[untyped-import] import fs from 'fs'; @@ -94,7 +94,7 @@ async function warmUpMetro(isOptimizedMode: boolean): Promise { } function warmUpHermesCompiler(isOptimizedMode: boolean): void { - const buildHermesCompilerCommandResult = runBuck2([ + const buildHermesCompilerCommandResult = runBuck2Sync([ 'build', ...getBuckModesForPlatform(isOptimizedMode), '//xplat/hermes/tools/hermesc:hermesc', @@ -108,7 +108,7 @@ function warmUpHermesCompiler(isOptimizedMode: boolean): void { } function warmUpRNTesterCLI(isOptimizedMode: boolean): void { - const buildRNTesterCommandResult = runBuck2([ + const buildRNTesterCommandResult = runBuck2Sync([ 'build', ...getBuckModesForPlatform(isOptimizedMode), '//xplat/ReactNative/react-native-cxx/samples/tester:tester',