Skip to content

Commit ae89022

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Use artifacts published from Hermes repository when using Hermes V1 (#53725)
Summary: Pull Request resolved: #53725 Changelog: [GENERAL][CHANGED] - Changed the coordinates of hermes artifacts when using Hermes V1 Adds a new `version.properties` file to keep which hermes versions should be consumed from Maven once the versions of Hermes and React Native are decoupled. This diff only implements changes necessary for consuming Hermes V1, as we don't want to migrate everything quite yet (0.82). Reviewed By: cortinico Differential Revision: D82204203 fbshipit-source-id: d712257a73f7ba54612a55c1b312416376f28b56
1 parent 7438fcd commit ae89022

10 files changed

Lines changed: 322 additions & 49 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ if (project.findProperty("react.internal.useHermesNightly")?.toString()?.toBoole
135135
configurations.all {
136136
resolutionStrategy.dependencySubstitution {
137137
substitute(project(":packages:react-native:ReactAndroid:hermes-engine"))
138+
// TODO: T237406039 update coordinates
138139
.using(module("com.facebook.react:hermes-android:0.+"))
139140
.because("Users opted to use hermes from nightly")
140141
}

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class ReactPlugin : Plugin<Project> {
5555
project,
5656
)
5757

58-
if (project.rootProject.isHermesV1Enabled != rootExtension.hermesV1Enabled.get()) {
59-
rootExtension.hermesV1Enabled.set(project.rootProject.isHermesV1Enabled)
58+
if (project.rootProject.isHermesV1Enabled) {
59+
rootExtension.hermesV1Enabled.set(true)
6060
}
6161

6262
// App Only Configuration
@@ -71,11 +71,11 @@ class ReactPlugin : Plugin<Project> {
7171
project.afterEvaluate {
7272
val reactNativeDir = extension.reactNativeDir.get().asFile
7373
val propertiesFile = File(reactNativeDir, "ReactAndroid/gradle.properties")
74-
val versionAndGroupStrings = readVersionAndGroupStrings(propertiesFile)
75-
val hermesV1Enabled =
76-
if (project.rootProject.hasProperty("hermesV1Enabled"))
77-
project.rootProject.findProperty("hermesV1Enabled") == "true"
78-
else false
74+
val hermesVersionPropertiesFile =
75+
File(reactNativeDir, "sdks/hermes-engine/version.properties")
76+
val versionAndGroupStrings =
77+
readVersionAndGroupStrings(propertiesFile, hermesVersionPropertiesFile)
78+
val hermesV1Enabled = rootExtension.hermesV1Enabled.get()
7979
configureDependencies(project, versionAndGroupStrings, hermesV1Enabled)
8080
configureRepositories(project)
8181
}

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import com.facebook.react.utils.PropertyUtils.EXCLUSIVE_ENTEPRISE_REPOSITORY
1313
import com.facebook.react.utils.PropertyUtils.INCLUDE_JITPACK_REPOSITORY
1414
import com.facebook.react.utils.PropertyUtils.INCLUDE_JITPACK_REPOSITORY_DEFAULT
1515
import com.facebook.react.utils.PropertyUtils.INTERNAL_HERMES_PUBLISHING_GROUP
16-
import com.facebook.react.utils.PropertyUtils.INTERNAL_HERMES_VERSION_NAME
16+
import com.facebook.react.utils.PropertyUtils.INTERNAL_HERMES_V1_VERSION_NAME
1717
import com.facebook.react.utils.PropertyUtils.INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO
1818
import com.facebook.react.utils.PropertyUtils.INTERNAL_REACT_PUBLISHING_GROUP
1919
import com.facebook.react.utils.PropertyUtils.INTERNAL_USE_HERMES_NIGHTLY
@@ -31,6 +31,7 @@ internal object DependencyUtils {
3131
internal data class Coordinates(
3232
val versionString: String,
3333
val hermesVersionString: String,
34+
val hermesV1VersionString: String,
3435
val reactGroupString: String = DEFAULT_INTERNAL_REACT_PUBLISHING_GROUP,
3536
val hermesGroupString: String = DEFAULT_INTERNAL_HERMES_PUBLISHING_GROUP,
3637
)
@@ -113,7 +114,12 @@ internal object DependencyUtils {
113114
coordinates: Coordinates,
114115
hermesV1Enabled: Boolean = false,
115116
) {
116-
if (coordinates.versionString.isBlank() || coordinates.hermesVersionString.isBlank()) return
117+
if (
118+
coordinates.versionString.isBlank() ||
119+
(!hermesV1Enabled && coordinates.hermesVersionString.isBlank()) ||
120+
(hermesV1Enabled && coordinates.hermesV1VersionString.isBlank())
121+
)
122+
return
117123
project.rootProject.allprojects { eachProject ->
118124
eachProject.configurations.all { configuration ->
119125
// Here we set a dependencySubstitution for both react-native and hermes-engine as those
@@ -133,7 +139,11 @@ internal object DependencyUtils {
133139
// Contributors only: The hermes-engine version is forced only if the user has
134140
// not opted into using nightlies for local development.
135141
configuration.resolutionStrategy.force(
136-
"${coordinates.reactGroupString}:hermes-android:${coordinates.versionString}"
142+
// TODO: T237406039 update coordinates
143+
if (hermesV1Enabled)
144+
"${coordinates.hermesGroupString}:hermes-android:${coordinates.hermesV1VersionString}"
145+
else
146+
"${coordinates.reactGroupString}:hermes-android:${coordinates.hermesVersionString}"
137147
)
138148
}
139149
}
@@ -146,10 +156,11 @@ internal object DependencyUtils {
146156
): List<Triple<String, String, String>> {
147157
// TODO: T231755027 update coordinates and versioning
148158
val dependencySubstitution = mutableListOf<Triple<String, String, String>>()
159+
// TODO: T237406039 update coordinates
149160
val hermesVersionString =
150161
if (hermesV1Enabled)
151-
"${coordinates.hermesGroupString}:hermes-android:${coordinates.versionString}"
152-
else "${coordinates.reactGroupString}:hermes-android:${coordinates.versionString}"
162+
"${coordinates.hermesGroupString}:hermes-android:${coordinates.hermesV1VersionString}"
163+
else "${coordinates.reactGroupString}:hermes-android:${coordinates.hermesVersionString}"
153164
dependencySubstitution.add(
154165
Triple(
155166
"com.facebook.react:react-native",
@@ -172,6 +183,7 @@ internal object DependencyUtils {
172183
"The react-android dependency was modified to use the correct Maven group.",
173184
)
174185
)
186+
// TODO: T237406039 update coordinates
175187
dependencySubstitution.add(
176188
Triple(
177189
"com.facebook.react:hermes-android",
@@ -183,14 +195,10 @@ internal object DependencyUtils {
183195
return dependencySubstitution
184196
}
185197

186-
fun readVersionAndGroupStrings(propertiesFile: File): Coordinates {
198+
fun readVersionAndGroupStrings(propertiesFile: File, hermesVersionFile: File): Coordinates {
187199
val reactAndroidProperties = Properties()
188200
propertiesFile.inputStream().use { reactAndroidProperties.load(it) }
189201
val versionStringFromFile = (reactAndroidProperties[INTERNAL_VERSION_NAME] as? String).orEmpty()
190-
// TODO: T231755027 update HERMES_VERSION_NAME in gradle.properties to point to the correct
191-
// hermes version
192-
val hermesVersionStringFromFile =
193-
(reactAndroidProperties[INTERNAL_HERMES_VERSION_NAME] as? String).orEmpty()
194202
// If on a nightly, we need to fetch the -SNAPSHOT artifact from Sonatype.
195203
val versionString =
196204
if (versionStringFromFile.startsWith("0.0.0") || "-nightly-" in versionStringFromFile) {
@@ -205,9 +213,18 @@ internal object DependencyUtils {
205213
val hermesGroupString =
206214
reactAndroidProperties[INTERNAL_HERMES_PUBLISHING_GROUP] as? String
207215
?: DEFAULT_INTERNAL_HERMES_PUBLISHING_GROUP
216+
// TODO: T237406039 read both versions from the same file
217+
val hermesVersionProperties = Properties()
218+
hermesVersionFile.inputStream().use { hermesVersionProperties.load(it) }
219+
220+
val hermesVersion = versionString
221+
val hermesV1Version =
222+
(hermesVersionProperties[INTERNAL_HERMES_V1_VERSION_NAME] as? String).orEmpty()
223+
208224
return Coordinates(
209225
versionString,
210-
hermesVersionStringFromFile,
226+
hermesVersion,
227+
hermesV1Version,
211228
reactGroupString,
212229
hermesGroupString,
213230
)

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ internal fun detectOSAwareHermesCommand(
153153

154154
// 3. If Hermes V1 is enabled, use hermes-compiler from npm, otherwise, if the
155155
// react-native contains a pre-built hermesc, use it.
156+
// TODO: T237406039 use hermes-compiler from npm for both
156157
val hermesCPath = if (hermesV1Enabled) HERMES_COMPILER_NPM_DIR else HERMESC_IN_REACT_NATIVE_DIR
157158
val prebuiltHermesPath =
158159
hermesCPath

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PropertyUtils.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ object PropertyUtils {
7979

8080
/** Internal property used to control the version name of React Native */
8181
const val INTERNAL_VERSION_NAME = "VERSION_NAME"
82-
/** Internal property used to control the version name of Hermes Engine */
83-
const val INTERNAL_HERMES_VERSION_NAME = "HERMES_VERSION_NAME"
82+
83+
/**
84+
* Internal property, shared with iOS, used to control the version name of Hermes Engine. This is
85+
* stored in sdks/hermes-engine/version.properties
86+
*/
87+
const val INTERNAL_HERMES_V1_VERSION_NAME = "HERMES_V1_VERSION_NAME"
8488
}

0 commit comments

Comments
 (0)