Skip to content

Commit

Permalink
RNGP - ENTRY_FILE should resolve relative paths from root (#36193)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #36193

Fixes #36186

Changelog:
[Android] [Fixed] - ENTRY_FILE should resolve relative paths from root

Reviewed By: cipolleschi

Differential Revision: D43392121

fbshipit-source-id: ddf302d333c5fc5f822e0635a73e5b52470140ee
  • Loading branch information
cortinico authored and facebook-github-bot committed Feb 17, 2023
1 parent e42dd15 commit 6dde1dc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ internal fun Project.configureReactTasks(variant: Variant, config: ReactExtensio
configureJsEnginePackagingOptions(config, variant, isHermesEnabledInThisVariant)

if (!isDebuggableVariant) {
val entryFileEnvVariable = System.getenv("ENTRY_FILE")
val bundleTask =
tasks.register("createBundle${targetName}JsAndAssets", BundleHermesCTask::class.java) {
it.root.set(config.root)
it.nodeExecutableAndArgs.set(config.nodeExecutableAndArgs)
it.cliFile.set(cliFile)
it.bundleCommand.set(config.bundleCommand)
it.entryFile.set(detectedEntryFile(config))
it.entryFile.set(detectedEntryFile(config, entryFileEnvVariable))
it.extraPackagerArgs.set(config.extraPackagerArgs)
it.bundleConfig.set(config.bundleConfig)
it.bundleAssetName.set(config.bundleAssetName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import org.gradle.api.file.DirectoryProperty
*
* @param config The [ReactExtension] configured for this project
*/
internal fun detectedEntryFile(config: ReactExtension): File =
internal fun detectedEntryFile(config: ReactExtension, envVariableOverride: String? = null): File =
detectEntryFile(
entryFile = config.entryFile.orNull?.asFile, reactRoot = config.root.get().asFile)
entryFile = config.entryFile.orNull?.asFile,
reactRoot = config.root.get().asFile,
envVariableOverride = envVariableOverride)

/**
* Computes the CLI file for React Native. The Algo follows this order:
Expand All @@ -54,9 +56,13 @@ internal fun detectedCliFile(config: ReactExtension): File =
internal fun detectedHermesCommand(config: ReactExtension): String =
detectOSAwareHermesCommand(config.root.get().asFile, config.hermesCommand.get())

private fun detectEntryFile(entryFile: File?, reactRoot: File): File =
private fun detectEntryFile(
entryFile: File?,
reactRoot: File,
envVariableOverride: String? = null
): File =
when {
System.getenv("ENTRY_FILE") != null -> File(System.getenv("ENTRY_FILE"))
envVariableOverride != null -> File(reactRoot, envVariableOverride)
entryFile != null -> entryFile
File(reactRoot, "index.android.js").exists() -> File(reactRoot, "index.android.js")
else -> File(reactRoot, "index.js")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ class PathUtilsTest {
assertEquals(File(tempFolder.root, "index.js"), actual)
}

@Test
fun detectedEntryFile_withEnvironmentVariable() {
val extension = TestReactExtension(ProjectBuilder.builder().build())
val expected = tempFolder.newFile("./fromenv.index.js")
// As we can't override env variable for tests, we're going to emulate them here.
val envVariable = "./fromenv.index.js"

extension.root.set(tempFolder.root)

val actual = detectedEntryFile(extension, envVariable)

assertEquals(expected, actual)
}

@Test
fun detectedCliPath_withCliPathFromExtensionAndFileExists_returnsIt() {
val project = ProjectBuilder.builder().build()
Expand Down

0 comments on commit 6dde1dc

Please sign in to comment.