From 84aea1a6bf4e16625d8b78e6f34347cd828244d6 Mon Sep 17 00:00:00 2001 From: JoseLion Date: Wed, 6 Jul 2022 22:21:26 -0500 Subject: [PATCH 1/3] fix(android): Append `.exe` to hermesc binary path for Windows users --- .gitignore | 1 + react.gradle | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c954afb75a0f3b..40935ee4b89afb 100644 --- a/.gitignore +++ b/.gitignore @@ -122,6 +122,7 @@ package-lock.json # Visual studio .vscode .vs +bin/ # Android memory profiler files *.hprof diff --git a/react.gradle b/react.gradle index 2e9d8e51fb61b3..912a4078477bc8 100644 --- a/react.gradle +++ b/react.gradle @@ -102,20 +102,22 @@ def getHermesCommand = { } } + def hermescBin = Os.isFamily(Os.FAMILY_WINDOWS) ? 'hermesc.exe' : 'hermesc' + // 2. If the project is building hermes-engine from source, use hermesc from there // Also note that user can override the hermes source location with // the `REACT_NATIVE_OVERRIDE_HERMES_DIR` env variable. def hermesOverrideDir = System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR") def builtHermesc = hermesOverrideDir ? - new File(hermesOverrideDir, "build/bin/hermesc") : - new File(reactRoot, "node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/hermesc") + new File(hermesOverrideDir, "build/bin/$hermescBin") : + new File(reactRoot, "node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/$hermescBin") if (builtHermesc.exists()) { return builtHermesc.getAbsolutePath() } // 3. If the react-native contains a pre-built hermesc, use it. - def prebuiltHermesPath = "node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc" + def prebuiltHermesPath = "node_modules/react-native/sdks/hermesc/%OS-BIN%/$hermescBin" .replaceAll("%OS-BIN%", getHermesOSBin()) .replace('/' as char, File.separatorChar); def prebuiltHermes = new File(reactRoot, prebuiltHermesPath) From de9623ba9d3c5208247c29c90cec2488acbf1791 Mon Sep 17 00:00:00 2001 From: JoseLion Date: Thu, 7 Jul 2022 01:44:55 -0500 Subject: [PATCH 2/3] Address @cortinico feedback --- .gitignore | 1 - .../src/main/kotlin/com/facebook/react/utils/PathUtils.kt | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 40935ee4b89afb..c954afb75a0f3b 100644 --- a/.gitignore +++ b/.gitignore @@ -122,7 +122,6 @@ package-lock.json # Visual studio .vscode .vs -bin/ # Android memory profiler files *.hprof diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt index 562ac7857c11da..9567ea77c03ee7 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt @@ -170,7 +170,7 @@ internal fun detectOSAwareHermesCommand(projectRoot: File, hermesCommand: String */ internal fun getBuiltHermescFile(projectRoot: File, pathOverride: String?) = if (!pathOverride.isNullOrBlank()) { - File(pathOverride, "build/bin/hermesc") + File(pathOverride, "build/bin/${HERMESC_BIN}") } else { File(projectRoot, HERMESC_BUILT_FROM_SOURCE_PATH) } @@ -190,7 +190,9 @@ internal fun projectPathToLibraryName(projectPath: String): String = .joinToString("") { token -> token.replaceFirstChar { it.uppercase() } } .plus("Spec") +private const val HERMESC_BIN = Os.isWindows() ? "hermesc.exe" : "hermesc" + private const val HERMESC_IN_REACT_NATIVE_PATH = - "node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc" + "node_modules/react-native/sdks/hermesc/%OS-BIN%/${HERMESC_BIN}" private const val HERMESC_BUILT_FROM_SOURCE_PATH = - "node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/hermesc" + "node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/${HERMESC_BIN}" From cd912ac40aec6f9b9120315ba92826d2db1ac0e9 Mon Sep 17 00:00:00 2001 From: JoseLion Date: Thu, 7 Jul 2022 02:02:31 -0500 Subject: [PATCH 3/3] Fix Kotlin changes --- .../com/facebook/react/utils/PathUtils.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt index 9567ea77c03ee7..445aa66c292829 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt @@ -145,7 +145,8 @@ internal fun detectOSAwareHermesCommand(projectRoot: File, hermesCommand: String // 3. If the react-native contains a pre-built hermesc, use it. val prebuiltHermesPath = - HERMESC_IN_REACT_NATIVE_PATH.replace("%OS-BIN%", getHermesOSBin()) + HERMESC_IN_REACT_NATIVE_DIR.plus(getHermesCBin()) + .replace("%OS-BIN%", getHermesOSBin()) // Execution on Windows fails with / as separator .replace('/', File.separatorChar) @@ -162,7 +163,7 @@ internal fun detectOSAwareHermesCommand(projectRoot: File, hermesCommand: String /** * Gets the location where Hermesc should be. If nothing is specified, built hermesc is assumed to - * be inside [HERMESC_BUILT_FROM_SOURCE_PATH]. Otherwise user can specify an override with + * be inside [HERMESC_BUILT_FROM_SOURCE_DIR]. Otherwise user can specify an override with * [pathOverride], which is assumed to be an absolute path where Hermes source code is * provided/built. * @@ -170,11 +171,13 @@ internal fun detectOSAwareHermesCommand(projectRoot: File, hermesCommand: String */ internal fun getBuiltHermescFile(projectRoot: File, pathOverride: String?) = if (!pathOverride.isNullOrBlank()) { - File(pathOverride, "build/bin/${HERMESC_BIN}") + File(pathOverride, "build/bin/${getHermesCBin()}") } else { - File(projectRoot, HERMESC_BUILT_FROM_SOURCE_PATH) + File(projectRoot, HERMESC_BUILT_FROM_SOURCE_DIR.plus(getHermesCBin())) } +internal fun getHermesCBin() = if (Os.isWindows()) "hermesc.exe" else "hermesc" + internal fun getHermesOSBin(): String { if (Os.isWindows()) return "win64-bin" if (Os.isMac()) return "osx-bin" @@ -190,9 +193,7 @@ internal fun projectPathToLibraryName(projectPath: String): String = .joinToString("") { token -> token.replaceFirstChar { it.uppercase() } } .plus("Spec") -private const val HERMESC_BIN = Os.isWindows() ? "hermesc.exe" : "hermesc" - -private const val HERMESC_IN_REACT_NATIVE_PATH = - "node_modules/react-native/sdks/hermesc/%OS-BIN%/${HERMESC_BIN}" -private const val HERMESC_BUILT_FROM_SOURCE_PATH = - "node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/${HERMESC_BIN}" +private const val HERMESC_IN_REACT_NATIVE_DIR = + "node_modules/react-native/sdks/hermesc/%OS-BIN%/" +private const val HERMESC_BUILT_FROM_SOURCE_DIR = + "node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/"