Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ target_include_directories(react_renderer_debug PUBLIC ${REACT_COMMON_DIR})
target_link_libraries(react_renderer_debug folly_runtime react_debug)
target_compile_reactnative_options(react_renderer_debug PRIVATE)
target_compile_options(react_renderer_debug PRIVATE -Wpedantic)

# Enable debug string convertible for Debug builds or when explicitly requested
# This allows getRenderedOutput() to include props in tests
# Set RN_ENABLE_DEBUG_STRING_CONVERTIBLE=ON to enable for Release builds
if(${CMAKE_BUILD_TYPE} MATCHES Debug OR RN_ENABLE_DEBUG_STRING_CONVERTIBLE)
target_compile_definitions(react_renderer_debug PUBLIC RN_ENABLE_DEBUG_STRING_CONVERTIBLE)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
// #define RN_SHADOW_TREE_INTROSPECTION 1

// This enables certain object-to-string debug conversions to be compiled.
// Enable if `REACT_NATIVE_DEBUG` is enabled.
#ifdef REACT_NATIVE_DEBUG
// Enable if either `REACT_NATIVE_DEBUG` or `RN_ENABLE_DEBUG_STRING_CONVERTIBLE`
// is defined
#if defined(REACT_NATIVE_DEBUG) || defined(RN_ENABLE_DEBUG_STRING_CONVERTIBLE)
#define RN_DEBUG_STRING_CONVERTIBLE 1
#else
#define RN_DEBUG_STRING_CONVERTIBLE 0
Expand Down
1 change: 1 addition & 0 deletions private/react-native-fantom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ val configureFantomTester by
"-DREACT_COMMON_DIR=$reactNativeDir/ReactCommon",
"-DREACT_CXX_PLATFORM_DIR=$reactNativeDir/ReactCxxPlatform",
"-DREACT_THIRD_PARTY_NDK_DIR=$reactAndroidBuildDir/third-party-ndk",
"-DRN_ENABLE_DEBUG_STRING_CONVERTIBLE=ON",
)
commandLine(cmdArgs)
standardOutputFile.set(project.file("$buildDir/reports/configure-fantom_tester.log"))
Expand Down
29 changes: 17 additions & 12 deletions private/react-native-fantom/runner/executables/hermesc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {NATIVE_BUILD_OUTPUT_PATH} from '../paths';
import {
getBuckModesForPlatform,
getBuckOptionsForHermes,
getConfigForAnimationBackend,
getDebugInfoFromCommandResult,
getHermesCompilerTarget,
runBuck2Sync,
Expand All @@ -23,23 +24,23 @@ import {
import fs from 'fs';
import path from 'path';

type TesterOptions = $ReadOnly<{
isOptimizedMode: boolean,
type HermescOptions = $ReadOnly<{
enableCoverage: boolean,
enableRelease: boolean,
hermesVariant: HermesVariant,
}>;

function getHermesCompilerPath({
isOptimizedMode,
function getHermescPath({
enableRelease,
hermesVariant,
}: TesterOptions): string {
}: HermescOptions): string {
return path.join(
NATIVE_BUILD_OUTPUT_PATH,
`hermesc-${(hermesVariant as string).toLowerCase()}-${isOptimizedMode ? 'opt' : 'dev'}`,
`hermesc-${(hermesVariant as string).toLowerCase()}-${enableRelease ? 'opt' : 'dev'}`,
);
}

export function build(options: TesterOptions): void {
const destPath = getHermesCompilerPath(options);
export function build(options: HermescOptions): void {
const destPath = getHermescPath(options);
if (fs.existsSync(destPath)) {
return;
}
Expand All @@ -49,8 +50,12 @@ export function build(options: TesterOptions): void {
try {
const result = runBuck2Sync([
'build',
...getBuckModesForPlatform(options.isOptimizedMode),
...getBuckModesForPlatform({
enableRelease: options.enableRelease,
enableCoverage: options.enableCoverage,
}),
...getBuckOptionsForHermes(options.hermesVariant),
...getConfigForAnimationBackend(),
getHermesCompilerTarget(options.hermesVariant),
'--out',
tmpPath,
Expand All @@ -75,11 +80,11 @@ export function build(options: TesterOptions): void {

export function run(
args: $ReadOnlyArray<string>,
options: TesterOptions,
options: HermescOptions,
): SyncCommandResult {
if (!isCI) {
build(options);
}

return runCommandSync(getHermesCompilerPath(options), args);
return runCommandSync(getHermescPath(options), args);
}
38 changes: 25 additions & 13 deletions private/react-native-fantom/runner/executables/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ const FANTOM_TESTER_BUCK_TARGET =
'fbsource//xplat/js/react-native-github/private/react-native-fantom/tester:tester';

type TesterOptions = $ReadOnly<{
isOptimizedMode: boolean,
enableCoverage: boolean,
enableRelease: boolean,
hermesVariant: HermesVariant,
}>;

function getFantomTesterPath({
isOptimizedMode,
hermesVariant,
...options
}: TesterOptions): string {
return path.join(
NATIVE_BUILD_OUTPUT_PATH,
`fantom-tester-${(hermesVariant as string).toLowerCase()}-${isOptimizedMode ? 'opt' : 'dev'}`,
`fantom-tester-${(hermesVariant as string).toLowerCase()}-${options.enableRelease ? 'opt' : 'dev'}`,
);
}

Expand All @@ -51,15 +52,23 @@ export function build(options: TesterOptions): void {
const tmpPath = destPath + '-' + Date.now();

try {
const result = runBuck2Sync([
'build',
...getBuckModesForPlatform(options.isOptimizedMode),
...getBuckOptionsForHermes(options.hermesVariant),
...getConfigForAnimationBackend(),
FANTOM_TESTER_BUCK_TARGET,
'--out',
tmpPath,
]);
const result = runBuck2Sync(
[
'build',
...getBuckModesForPlatform({
enableRelease: options.enableRelease,
enableCoverage: options.enableCoverage,
}),
...getBuckOptionsForHermes(options.hermesVariant),
...getConfigForAnimationBackend(),
FANTOM_TESTER_BUCK_TARGET,
'--out',
tmpPath,
],
{
withFDB: false,
},
);

if (result.status !== 0) {
throw new Error(getDebugInfoFromCommandResult(result));
Expand Down Expand Up @@ -94,7 +103,10 @@ export function run(
return runBuck2(
[
'run',
...getBuckModesForPlatform(options.isOptimizedMode),
...getBuckModesForPlatform({
enableRelease: options.enableRelease,
enableCoverage: options.enableCoverage,
}),
...getBuckOptionsForHermes(options.hermesVariant),
...getConfigForAnimationBackend(),
FANTOM_TESTER_BUCK_TARGET,
Expand Down
8 changes: 4 additions & 4 deletions private/react-native-fantom/runner/global-setup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ async function tryOrLog(
}
}

export default async function build(): Promise<void> {
export default async function build(enableCoverage: boolean): Promise<void> {
try {
fs.rmSync(NATIVE_BUILD_OUTPUT_PATH, {recursive: true});
} catch {}

fs.mkdirSync(NATIVE_BUILD_OUTPUT_PATH, {recursive: true});

if (isCI) {
for (const isOptimizedMode of [false, true]) {
for (const enableRelease of [false, true]) {
for (const hermesVariant of HermesVariant.members()) {
buildFantomTester({isOptimizedMode, hermesVariant});
buildHermesCompiler({isOptimizedMode, hermesVariant});
buildFantomTester({enableRelease, hermesVariant, enableCoverage});
buildHermesCompiler({enableRelease, hermesVariant, enableCoverage});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import {Server} from 'net';
import path from 'path';

export default async function globalSetup(
globalConfig: {...},
globalConfig: {
collectCoverage: boolean,
...
},
projectConfig: {...},
): Promise<void> {
process.env.__FANTOM_RUN_ID__ ??= `run-${Date.now()}`;
Expand All @@ -29,7 +32,7 @@ export default async function globalSetup(
await startMetroServer();

if (!isOSS) {
await build();
await build(globalConfig.collectCoverage);
}
}

Expand Down
12 changes: 12 additions & 0 deletions private/react-native-fantom/runner/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const JS_HEAP_SNAPSHOTS_OUTPUT_PATH: string = path.join(
'js-heap-snapshots',
);

export const COVERAGE_OUTPUT_PATH: string = path.join(OUTPUT_PATH, 'coverage');

export function getTestBuildOutputPath(): string {
const fantomRunID = process.env.__FANTOM_RUN_ID__;
if (fantomRunID == null) {
Expand All @@ -41,6 +43,16 @@ export function getTestBuildOutputPath(): string {
return path.join(JS_BUILD_OUTPUT_PATH, fantomRunID);
}

export function getCoverageFilePath(): string {
const fantomRunID = process.env.__FANTOM_RUN_ID__;
if (fantomRunID == null) {
throw new Error(
'Expected Fantom run ID to be set by global setup, but it was not (process.env.__FANTOM_RUN_ID__ is null)',
);
}
return `${COVERAGE_OUTPUT_PATH}/${fantomRunID}.profraw`;
}

export function buildJSTracesOutputPath({
testPath,
testConfig,
Expand Down
34 changes: 22 additions & 12 deletions private/react-native-fantom/runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {run as runFantomTester} from './executables/tester';
import formatFantomConfig from './formatFantomConfig';
import getFantomTestConfigs from './getFantomTestConfigs';
import {
COVERAGE_OUTPUT_PATH,
JS_HEAP_SNAPSHOTS_OUTPUT_PATH,
JS_TRACES_OUTPUT_PATH,
buildJSHeapSnapshotsOutputPathTemplate,
Expand Down Expand Up @@ -66,6 +67,8 @@ if (EnvironmentOptions.profileJS) {
fs.mkdirSync(JS_TRACES_OUTPUT_PATH, {recursive: true});
}

fs.mkdirSync(COVERAGE_OUTPUT_PATH, {recursive: true});

function buildError(
failureDetail: FailureDetail,
sourceMapPath: string,
Expand Down Expand Up @@ -163,27 +166,30 @@ async function processRNTesterCommandResult(
function generateBytecodeBundle({
sourcePath,
bytecodePath,
isOptimizedMode,
enableRelease,
hermesVariant,
enableCoverage,
}: {
sourcePath: string,
bytecodePath: string,
isOptimizedMode: boolean,
enableCoverage: boolean,
enableRelease: boolean,
hermesVariant: HermesVariant,
sourcePath: string,
}): void {
const hermesCompilerCommandResult = runHermesCompiler(
[
'-emit-binary',
isOptimizedMode ? '-O' : null,
enableRelease ? '-O' : null,
'-max-diagnostic-width',
'80',
'-out',
bytecodePath,
sourcePath,
].filter(Boolean),
{
isOptimizedMode,
enableRelease,
hermesVariant,
enableCoverage,
},
);

Expand Down Expand Up @@ -335,6 +341,12 @@ module.exports = async function runTest(
path.basename(testJSBundlePath, '.js') + '.map',
);

const collectCoverage = shouldCollectCoverage(
testPath,
testContents,
globalConfig,
);

const bundleOptions = {
testPath,
entry: entrypointPath,
Expand All @@ -344,11 +356,7 @@ module.exports = async function runTest(
sourceMap: true,
sourceMapUrl: sourceMapPath,
customTransformOptions: {
collectCoverage: shouldCollectCoverage(
testPath,
testContents,
globalConfig,
),
collectCoverage,
},
};

Expand All @@ -361,7 +369,8 @@ module.exports = async function runTest(
generateBytecodeBundle({
sourcePath: testJSBundlePath,
bytecodePath: testBytecodeBundlePath,
isOptimizedMode: testConfig.isJsOptimized,
enableCoverage: collectCoverage,
enableRelease: testConfig.isJsOptimized,
hermesVariant: testConfig.hermesVariant,
});
}
Expand All @@ -388,8 +397,9 @@ module.exports = async function runTest(
rnTesterCommandArgs,
)
: runFantomTester(rnTesterCommandArgs, {
isOptimizedMode: testConfig.isNativeOptimized,
enableRelease: testConfig.isNativeOptimized,
hermesVariant: testConfig.hermesVariant,
enableCoverage: collectCoverage,
});

const [processedResult, benchmarkResult] =
Expand Down
15 changes: 11 additions & 4 deletions private/react-native-fantom/runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import * as EnvironmentOptions from './EnvironmentOptions';
import {getCoverageFilePath} from './paths';
import {spawn, spawnSync} from 'child_process';
import fs from 'fs';
import os from 'os';
Expand Down Expand Up @@ -51,10 +52,14 @@ export function getHermesCompilerTarget(variant: HermesVariant): string {
}
}

export function getBuckModesForPlatform(
enableRelease: boolean = false,
): $ReadOnlyArray<string> {
let mode = enableRelease ? 'opt' : 'dev';
export function getBuckModesForPlatform({
enableCoverage,
enableRelease,
}: {
enableCoverage: boolean,
enableRelease: boolean,
}): $ReadOnlyArray<string> {
let mode = enableCoverage ? 'code-coverage' : enableRelease ? 'opt' : 'dev';

if (enableRelease) {
if (EnvironmentOptions.enableASAN || EnvironmentOptions.enableTSAN) {
Expand Down Expand Up @@ -151,6 +156,7 @@ export function runCommand(
encoding: 'utf8',
env: {
...process.env,
LLVM_PROFILE_FILE: getCoverageFilePath(),
PATH: `/usr/local/bin:/usr/bin:${process.env.PATH ?? ''}`,
},
},
Expand Down Expand Up @@ -191,6 +197,7 @@ export function runCommandSync(
encoding: 'utf8',
env: {
...process.env,
LLVM_PROFILE_FILE: getCoverageFilePath(),
PATH: `/usr/local/bin:/usr/bin:${process.env.PATH ?? ''}`,
},
});
Expand Down
Loading