Skip to content

Commit

Permalink
fix: limit diagnostics width output by hermesc (#37531)
Browse files Browse the repository at this point in the history
Summary:
Limit diagnostics width output by `hermesc` as they may cause slowdowns or even crashes in Gradle/Xcode when a minified bundle is used as input. This occurs because Hermes is unable to determine the terminal width when executed by Gradle/Xcode, and falls back to "unlimited". If the input is a minified bundle, Hermes will output the whole bundle for each warning.

See issues filed:
- microsoft/rnx-kit#2416
- microsoft/rnx-kit#2419
- microsoft/rnx-kit#2424

## Changelog:

[GENERAL] [FIXED] - Limit diagnostics width output by `hermesc`

Pull Request resolved: #37531

Test Plan: See listed issues for repros.

Reviewed By: cipolleschi

Differential Revision: D46102686

Pulled By: cortinico

fbshipit-source-id: 1b821cad7ef0d561a5e1c13a7aedf9b10164620a
  • Loading branch information
tido64 authored and facebook-github-bot committed May 23, 2023
1 parent e8b4bb0 commit 260bcf7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ abstract class BundleHermesCTask : DefaultTask() {
return windowsAwareCommandLine(
hermesCommand,
"-emit-binary",
"-max-diagnostic-width=80",
"-out",
bytecodeFile.cliPath(rootFile),
bundleFile.cliPath(rootFile),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,12 @@ class BundleHermesCTaskTest {

assertEquals(customHermesc, hermesCommand[0])
assertEquals("-emit-binary", hermesCommand[1])
assertEquals("-out", hermesCommand[2])
assertEquals(bytecodeFile.absolutePath, hermesCommand[3])
assertEquals(bundleFile.absolutePath, hermesCommand[4])
assertEquals("my-custom-hermes-flag", hermesCommand[5])
assertEquals(6, hermesCommand.size)
assertEquals("-max-diagnostic-width=80", hermesCommand[2])
assertEquals("-out", hermesCommand[3])
assertEquals(bytecodeFile.absolutePath, hermesCommand[4])
assertEquals(bundleFile.absolutePath, hermesCommand[5])
assertEquals("my-custom-hermes-flag", hermesCommand[6])
assertEquals(7, hermesCommand.size)
}

@Test
Expand All @@ -366,11 +367,12 @@ class BundleHermesCTaskTest {
assertEquals("/c", hermesCommand[1])
assertEquals(customHermesc, hermesCommand[2])
assertEquals("-emit-binary", hermesCommand[3])
assertEquals("-out", hermesCommand[4])
assertEquals(bytecodeFile.relativeTo(tempFolder.root).path, hermesCommand[5])
assertEquals(bundleFile.relativeTo(tempFolder.root).path, hermesCommand[6])
assertEquals("my-custom-hermes-flag", hermesCommand[7])
assertEquals(8, hermesCommand.size)
assertEquals("-max-diagnostic-width=80", hermesCommand[4])
assertEquals("-out", hermesCommand[5])
assertEquals(bytecodeFile.relativeTo(tempFolder.root).path, hermesCommand[6])
assertEquals(bundleFile.relativeTo(tempFolder.root).path, hermesCommand[7])
assertEquals("my-custom-hermes-flag", hermesCommand[8])
assertEquals(9, hermesCommand.size)
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/scripts/react-native-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ else
if [[ $EMIT_SOURCEMAP == true ]]; then
EXTRA_COMPILER_ARGS="$EXTRA_COMPILER_ARGS -output-source-map"
fi
"$HERMES_CLI_PATH" -emit-binary $EXTRA_COMPILER_ARGS -out "$DEST/main.jsbundle" "$BUNDLE_FILE"
"$HERMES_CLI_PATH" -emit-binary -max-diagnostic-width=80 "$EXTRA_COMPILER_ARGS" -out "$DEST/main.jsbundle" "$BUNDLE_FILE"
if [[ $EMIT_SOURCEMAP == true ]]; then
HBC_SOURCEMAP_FILE="$DEST/main.jsbundle.map"
"$NODE_BINARY" "$COMPOSE_SOURCEMAP_PATH" "$PACKAGER_SOURCEMAP_FILE" "$HBC_SOURCEMAP_FILE" -o "$SOURCEMAP_FILE"
Expand Down

0 comments on commit 260bcf7

Please sign in to comment.