Skip to content

Commit e1b0c77

Browse files
rubennortemeta-codesync[bot]
authored andcommitted
Fix Fantom dev-mode tests when the tester is built in optimized mode (#57272)
Summary: Pull Request resolved: #57272 Fantom integration tests declared with `fantom_mode dev` rely on debug-only native APIs (e.g. timer mocking via `installHighResTimeStampMock`) that are only compiled when the native tester is built in debug mode. Under some build configurations the active platform pins the core build mode to optimized, so the preprocessor flag that gates those debug-only APIs is not defined and the tester is compiled in optimized mode. As a result, dev-mode tests that depend on those APIs throw at runtime (e.g. "Mocking timers is not supported in optimized builds"). A previous attempt stacked a build-mode constraint on the Hermes build mode setting, which the native preprocessor flags never read, so it had no effect. Stack the constraint on the core build mode setting that actually gates the flag instead, so the tester is compiled in the test's intended dev/opt mode. Changelog: [Internal] Reviewed By: ellemac123 Differential Revision: D109014401 fbshipit-source-id: a04d75d299e3d2a0d1ccabcc2629833ac7a9dbd6
1 parent ffe3f79 commit e1b0c77

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

  • private/react-native-fantom/runner

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,25 @@ export function getBuckModesForPlatform({
123123
);
124124
}
125125

126-
// When coverage instrumentation is enabled, the active build platform
127-
// may not carry a `hermes_build_mode` constraint, causing
128-
// `rn_build_mode()` in `tools/build_defs/oss/rn_defs.bzl` to fall back
129-
// to the non-debug path. That leaves `REACT_NATIVE_DEBUG` undefined,
130-
// which breaks dev-mode tests that use debug-only native APIs (e.g.
131-
// timer mocking via `installHighResTimeStampMock`).
126+
// The coverage platform (e.g. `@//arvr/mode/linux/code-coverage`) pins the
127+
// `core_build_mode` constraint to `opt`. `get_react_native_preprocessor_flags()`
128+
// in `tools/build_defs/oss/rn_defs.bzl` selects on that constraint
129+
// (`ovr_config//build_mode/constraints:{dev,opt}`) to decide between
130+
// `-DREACT_NATIVE_DEBUG` and `-DREACT_NATIVE_PRODUCTION`. Under coverage it
131+
// therefore compiles the native tester with `REACT_NATIVE_PRODUCTION`, which
132+
// breaks dev-mode tests that use debug-only native APIs (e.g. timer mocking
133+
// via `installHighResTimeStampMock`).
132134
//
133-
// Explicitly stack the `hermes_build_mode` constraint so the build
134-
// reflects the test's intended dev/opt mode regardless of how the
135-
// coverage build is configured.
135+
// Explicitly stack the `core_build_mode` constraint so the build reflects the
136+
// test's intended dev/opt mode. This only overrides `core_build_mode`; the
137+
// coverage instrumentation constraint and `-c code_coverage.*` flags above are
138+
// left intact, so coverage is still collected.
136139
if (enableCoverage) {
137140
result.push(
138141
'--modifier',
139142
enableOptimized
140-
? 'fbsource//xplat/hermes/constraints:opt'
141-
: 'fbsource//xplat/hermes/constraints:dev',
143+
? 'ovr_config//build_mode/constraints:opt'
144+
: 'ovr_config//build_mode/constraints:dev',
142145
);
143146
}
144147

0 commit comments

Comments
 (0)