Skip to content

Commit 05ef52f

Browse files
javachefacebook-github-bot
authored andcommitted
Use per-session output directory for Fantom native builds
Summary: Fixes a race condition where multiple concurrent Jest processes sharing the same checkout could delete each others native binaries. The `globalSetup` in `build.js` previously called `fs.rmSync` on the shared `native-builds/` directory before rebuilding, which could delete binaries that another process workers were actively using (causing `ENOENT` when spawning the fantom-tester binary). Each Jest session now writes native binaries to `native-builds/<run-id>/`, matching the existing pattern used for JS build outputs (`getTestBuildOutputPath`). The buck isolation directory is shared across sessions so builds remain cached. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D101692926
1 parent c533369 commit 05ef52f

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

private/react-native-fantom/runner/executables/hermesc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import type {HermesVariant, SyncCommandResult} from '../utils';
1212

1313
import {isCI} from '../EnvironmentOptions';
14-
import {NATIVE_BUILD_OUTPUT_PATH} from '../paths';
14+
import {getNativeBuildOutputPath} from '../paths';
1515
import {
1616
getBuckModesForPlatform,
1717
getBuckOptionsForHermes,
@@ -35,7 +35,7 @@ function getHermesCompilerPath({
3535
hermesVariant,
3636
}: HermescOptions): string {
3737
return path.join(
38-
NATIVE_BUILD_OUTPUT_PATH,
38+
getNativeBuildOutputPath(),
3939
`hermesc-${(hermesVariant as string).toLowerCase()}-${enableOptimized ? 'opt' : 'dev'}`,
4040
);
4141
}

private/react-native-fantom/runner/executables/tester.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
} from '../utils';
1616

1717
import {debugCpp, isCI, profileCpp} from '../EnvironmentOptions';
18-
import {CPP_TRACES_OUTPUT_PATH, NATIVE_BUILD_OUTPUT_PATH} from '../paths';
18+
import {CPP_TRACES_OUTPUT_PATH, getNativeBuildOutputPath} from '../paths';
1919
import {
2020
getBuckModesForPlatform,
2121
getBuckOptionsForHermes,
@@ -43,7 +43,7 @@ export function getFantomTesterPath({
4343
...options
4444
}: TesterOptions): string {
4545
return path.join(
46-
NATIVE_BUILD_OUTPUT_PATH,
46+
getNativeBuildOutputPath(),
4747
`fantom-tester-${(hermesVariant as string).toLowerCase()}-${options.enableOptimized ? 'opt' : 'dev'}${options.enableCoverage ? '-coverage' : ''}`,
4848
);
4949
}

private/react-native-fantom/runner/global-setup/build.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {createBundle} from '../bundling';
1414
import {isCI} from '../EnvironmentOptions';
1515
import {build as buildHermesCompiler} from '../executables/hermesc';
1616
import {build as buildFantomTester} from '../executables/tester';
17-
import {NATIVE_BUILD_OUTPUT_PATH} from '../paths';
17+
import {getNativeBuildOutputPath} from '../paths';
1818
import {HermesVariant} from '../utils';
1919
// $FlowExpectedError[untyped-import]
2020
import fs from 'fs';
@@ -43,11 +43,7 @@ export default async function build(
4343
enableCoverage: boolean,
4444
env: EnvironmentOverrides,
4545
): Promise<void> {
46-
try {
47-
fs.rmSync(NATIVE_BUILD_OUTPUT_PATH, {recursive: true});
48-
} catch {}
49-
50-
fs.mkdirSync(NATIVE_BUILD_OUTPUT_PATH, {recursive: true});
46+
fs.mkdirSync(getNativeBuildOutputPath(), {recursive: true});
5147

5248
if (isCI) {
5349
for (const enableOptimized of [false, true]) {

private/react-native-fantom/runner/paths.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ export const NATIVE_BUILD_OUTPUT_PATH: string = path.join(
2121
OUTPUT_PATH,
2222
'native-builds',
2323
);
24+
25+
export function getNativeBuildOutputPath(): string {
26+
const fantomRunID = process.env.__FANTOM_RUN_ID__;
27+
if (fantomRunID == null) {
28+
throw new Error(
29+
'Expected Fantom run ID to be set by global setup, but it was not (process.env.__FANTOM_RUN_ID__ is null)',
30+
);
31+
}
32+
return path.join(NATIVE_BUILD_OUTPUT_PATH, fantomRunID);
33+
}
34+
2435
export const JS_TRACES_OUTPUT_PATH: string = path.join(
2536
OUTPUT_PATH,
2637
'js-traces',

0 commit comments

Comments
 (0)