Files
Rubén Norte 2016118aeb Centralize path definitions for Fantom builds and move to .out (#52829)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/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
2025-08-04 05:56:51 -07:00

86 lines
1.9 KiB
JavaScript

/**
* 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.
*
* @flow strict-local
* @format
*/
import type {HermesVariant, SyncCommandResult} from '../utils';
import {isCI} from '../EnvironmentOptions';
import {NATIVE_BUILD_OUTPUT_PATH} from '../paths';
import {
getBuckModesForPlatform,
getBuckOptionsForHermes,
getDebugInfoFromCommandResult,
getHermesCompilerTarget,
runBuck2Sync,
runCommandSync,
} from '../utils';
import fs from 'fs';
import path from 'path';
type TesterOptions = $ReadOnly<{
isOptimizedMode: boolean,
hermesVariant: HermesVariant,
}>;
function getHermesCompilerPath({
isOptimizedMode,
hermesVariant,
}: TesterOptions): string {
return path.join(
NATIVE_BUILD_OUTPUT_PATH,
`hermesc-${(hermesVariant as string).toLowerCase()}-${isOptimizedMode ? 'opt' : 'dev'}`,
);
}
export function build(options: TesterOptions): void {
const destPath = getHermesCompilerPath(options);
if (fs.existsSync(destPath)) {
return;
}
const tmpPath = destPath + '-' + Date.now();
try {
const result = runBuck2Sync([
'build',
...getBuckModesForPlatform(options.isOptimizedMode),
...getBuckOptionsForHermes(options.hermesVariant),
getHermesCompilerTarget(options.hermesVariant),
'--out',
tmpPath,
]);
if (result.status !== 0) {
throw new Error(getDebugInfoFromCommandResult(result));
}
if (fs.existsSync(destPath)) {
// Another test might have compiled the binary after our initial check.
return;
}
fs.renameSync(tmpPath, destPath);
} finally {
try {
fs.unlinkSync(tmpPath);
} catch {}
}
}
export function run(
args: $ReadOnlyArray<string>,
options: TesterOptions,
): SyncCommandResult {
if (!isCI) {
build(options);
}
return runCommandSync(getHermesCompilerPath(options), args);
}