From 260bcf7f1bf78022872eb2f40f33fb552a414809 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Tue, 23 May 2023 07:51:25 -0700 Subject: [PATCH] fix: limit diagnostics width output by `hermesc` (#37531) 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: - https://github.com/microsoft/rnx-kit/issues/2416 - https://github.com/microsoft/rnx-kit/issues/2419 - https://github.com/microsoft/rnx-kit/issues/2424 ## Changelog: [GENERAL] [FIXED] - Limit diagnostics width output by `hermesc` Pull Request resolved: https://github.com/facebook/react-native/pull/37531 Test Plan: See listed issues for repros. Reviewed By: cipolleschi Differential Revision: D46102686 Pulled By: cortinico fbshipit-source-id: 1b821cad7ef0d561a5e1c13a7aedf9b10164620a --- .../facebook/react/tasks/BundleHermesCTask.kt | 1 + .../react/tasks/BundleHermesCTaskTest.kt | 22 ++++++++++--------- .../scripts/react-native-xcode.sh | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt index 55eab602f4d0f3..78e5a9b2606ce5 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt @@ -174,6 +174,7 @@ abstract class BundleHermesCTask : DefaultTask() { return windowsAwareCommandLine( hermesCommand, "-emit-binary", + "-max-diagnostic-width=80", "-out", bytecodeFile.cliPath(rootFile), bundleFile.cliPath(rootFile), diff --git a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/BundleHermesCTaskTest.kt b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/BundleHermesCTaskTest.kt index 3e07a78b36e1b4..f7feb2b11735f5 100644 --- a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/BundleHermesCTaskTest.kt +++ b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/BundleHermesCTaskTest.kt @@ -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 @@ -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 diff --git a/packages/react-native/scripts/react-native-xcode.sh b/packages/react-native/scripts/react-native-xcode.sh index 9f80ef20246e55..080ed233ec25be 100755 --- a/packages/react-native/scripts/react-native-xcode.sh +++ b/packages/react-native/scripts/react-native-xcode.sh @@ -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"