Skip to content

Commit 5c55a61

Browse files
rubennortemeta-codesync[bot]
authored andcommitted
Set hermes_build_mode constraint when building tester with coverage (#56541)
Summary: Pull Request resolved: #56541 The Fantom test runner spawns native `fantom-tester` binaries built in either dev or opt mode based on each test's `fantom_mode` pragma. When collecting C++ code coverage of the tester binary, however, the build may switch to a coverage-instrumented build configuration that does not define `REACT_NATIVE_DEBUG`. That breaks dev-mode tests that rely on debug-only native APIs. For example, `installHighResTimeStampMock` in `private/react-native-fantom/tester/src/NativeFantom.cpp` is gated on `#ifdef REACT_NATIVE_DEBUG` and throws "Mocking timers is not supported in optimized builds" otherwise. Tests like `LongTasksAPI-itest.js` (no `fantom_mode` pragma → defaults to dev) fail in CI coverage runs with that error. When invoking buck with coverage enabled, layer the `hermes_build_mode` constraint on top of the build platform so `rn_build_mode()` (in `tools/build_defs/oss/rn_defs.bzl`) picks up the right value and adds `-DREACT_NATIVE_DEBUG` for dev tests. Reviewed By: fkgozali Differential Revision: D101832028 fbshipit-source-id: cfb5269dea846f41d9d1f9af1c5ff8bd5828085c
1 parent 90017b5 commit 5c55a61

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

  • private/react-native-fantom/runner

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +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`).
132+
//
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.
136+
if (enableCoverage) {
137+
result.push(
138+
'--modifier',
139+
enableOptimized
140+
? 'fbsource//xplat/hermes/constraints:opt'
141+
: 'fbsource//xplat/hermes/constraints:dev',
142+
);
143+
}
144+
126145
return result;
127146
}
128147

0 commit comments

Comments
 (0)