Skip to content

Commit 2016118

Browse files
rubennortefacebook-github-bot
authored andcommitted
Centralize path definitions for Fantom builds and move to .out (#52829)
Summary: Pull Request resolved: #52829 Changelog: [internal] Just a small refactor to move the definitions of output paths to a specific module. We'll add more to this in a latter diff. Reviewed By: sammy-SC Differential Revision: D78905645 fbshipit-source-id: 011e6cec13396301dad8e76400b6f2b9e13568f0
1 parent 6760383 commit 2016118

7 files changed

Lines changed: 44 additions & 45 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ fix_*.patch
170170

171171
# Jest Integration
172172
/private/react-native-fantom/build/
173+
/private/react-native-fantom/.out/
173174
/private/react-native-fantom/tester/build/
174175

175176
# [Experimental] Generated TS type definitions

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

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

1313
import {isCI} from '../EnvironmentOptions';
14+
import {NATIVE_BUILD_OUTPUT_PATH} from '../paths';
1415
import {
1516
getBuckModesForPlatform,
1617
getBuckOptionsForHermes,
@@ -19,7 +20,6 @@ import {
1920
runBuck2Sync,
2021
runCommandSync,
2122
} from '../utils';
22-
import {getNativeBuildOutputPath} from './utils';
2323
import fs from 'fs';
2424
import path from 'path';
2525

@@ -33,7 +33,7 @@ function getHermesCompilerPath({
3333
hermesVariant,
3434
}: TesterOptions): string {
3535
return path.join(
36-
getNativeBuildOutputPath(),
36+
NATIVE_BUILD_OUTPUT_PATH,
3737
`hermesc-${(hermesVariant as string).toLowerCase()}-${isOptimizedMode ? 'opt' : 'dev'}`,
3838
);
3939
}

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

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

1313
import {debugCpp, isCI} from '../EnvironmentOptions';
14+
import {NATIVE_BUILD_OUTPUT_PATH} from '../paths';
1415
import {
1516
getBuckModesForPlatform,
1617
getBuckOptionsForHermes,
@@ -19,7 +20,6 @@ import {
1920
runBuck2Sync,
2021
runCommand,
2122
} from '../utils';
22-
import {getNativeBuildOutputPath} from './utils';
2323
import fs from 'fs';
2424
import path from 'path';
2525

@@ -36,7 +36,7 @@ function getFantomTesterPath({
3636
hermesVariant,
3737
}: TesterOptions): string {
3838
return path.join(
39-
getNativeBuildOutputPath(),
39+
NATIVE_BUILD_OUTPUT_PATH,
4040
`fantom-tester-${(hermesVariant as string).toLowerCase()}-${isOptimizedMode ? 'opt' : 'dev'}`,
4141
);
4242
}

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {createBundle} from '../bundling';
1212
import {isCI} from '../EnvironmentOptions';
1313
import {build as buildHermesCompiler} from '../executables/hermesc';
1414
import {build as buildFantomTester} from '../executables/tester';
15-
import {getNativeBuildOutputPath} from '../executables/utils';
15+
import {NATIVE_BUILD_OUTPUT_PATH} from '../paths';
1616
import {HermesVariant} from '../utils';
1717
// $FlowExpectedError[untyped-import]
1818
import fs from 'fs';
@@ -39,10 +39,10 @@ async function tryOrLog(
3939

4040
export default async function build(): Promise<void> {
4141
try {
42-
fs.rmSync(getNativeBuildOutputPath(), {recursive: true});
42+
fs.rmSync(NATIVE_BUILD_OUTPUT_PATH, {recursive: true});
4343
} catch {}
4444

45-
fs.mkdirSync(getNativeBuildOutputPath(), {recursive: true});
45+
fs.mkdirSync(NATIVE_BUILD_OUTPUT_PATH, {recursive: true});
4646

4747
if (isCI) {
4848
for (const isOptimizedMode of [false, true]) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
import path from 'path';
12+
13+
export const OUTPUT_PATH: string = path.resolve(__dirname, '..', '.out');
14+
export const JS_BUILD_OUTPUT_PATH: string = path.join(OUTPUT_PATH, 'js-builds');
15+
export const NATIVE_BUILD_OUTPUT_PATH: string = path.join(
16+
OUTPUT_PATH,
17+
'native-builds',
18+
);
19+
20+
export function getTestBuildOutputPath(): string {
21+
const fantomRunID = process.env.__FANTOM_RUN_ID__;
22+
if (fantomRunID == null) {
23+
throw new Error(
24+
'Expected Fantom run ID to be set by global setup, but it was not (process.env.__FANTOM_RUN_ID__ is null)',
25+
);
26+
}
27+
28+
return path.join(JS_BUILD_OUTPUT_PATH, fantomRunID);
29+
}

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {run as runHermesCompiler} from './executables/hermesc';
2727
import {run as runFantomTester} from './executables/tester';
2828
import formatFantomConfig from './formatFantomConfig';
2929
import getFantomTestConfigs from './getFantomTestConfigs';
30+
import {getTestBuildOutputPath} from './paths';
3031
import {
3132
getInitialSnapshotData,
3233
updateSnapshotsAndGetJestSnapshotResult,
@@ -46,17 +47,8 @@ import nullthrows from 'nullthrows';
4647
import path from 'path';
4748
import readline from 'readline';
4849

49-
const fantomRunID = process.env.__FANTOM_RUN_ID__;
50-
if (fantomRunID == null) {
51-
throw new Error(
52-
'Expected Fantom run ID to be set by global setup, but it was not (process.env.__FANTOM_RUN_ID__ is null)',
53-
);
54-
}
55-
56-
const BUILD_OUTPUT_ROOT = path.resolve(__dirname, '..', 'build', 'js');
57-
const BUILD_OUTPUT_PATH = path.join(BUILD_OUTPUT_ROOT, fantomRunID);
58-
59-
fs.mkdirSync(BUILD_OUTPUT_PATH, {recursive: true});
50+
const TEST_BUILD_OUTPUT_PATH = getTestBuildOutputPath();
51+
fs.mkdirSync(TEST_BUILD_OUTPUT_PATH, {recursive: true});
6052

6153
function buildError(
6254
failureDetail: FailureDetail,
@@ -276,9 +268,9 @@ module.exports = async function runTest(
276268
}
277269

278270
const entrypointContents = entrypointTemplate({
279-
testPath: `${path.relative(BUILD_OUTPUT_PATH, testPath)}`,
280-
setupModulePath: `${path.relative(BUILD_OUTPUT_PATH, setupModulePath)}`,
281-
featureFlagsModulePath: `${path.relative(BUILD_OUTPUT_PATH, featureFlagsModulePath)}`,
271+
testPath: `${path.relative(TEST_BUILD_OUTPUT_PATH, testPath)}`,
272+
setupModulePath: `${path.relative(TEST_BUILD_OUTPUT_PATH, setupModulePath)}`,
273+
featureFlagsModulePath: `${path.relative(TEST_BUILD_OUTPUT_PATH, featureFlagsModulePath)}`,
282274
testConfig,
283275
snapshotConfig: {
284276
updateSnapshot: snapshotState._updateSnapshot,
@@ -287,7 +279,7 @@ module.exports = async function runTest(
287279
});
288280

289281
const entrypointPath = path.join(
290-
BUILD_OUTPUT_PATH,
282+
TEST_BUILD_OUTPUT_PATH,
291283
`${Date.now()}-${path.basename(testPath)}`,
292284
);
293285
const testJSBundlePath = entrypointPath + '.bundle.js';

0 commit comments

Comments
 (0)