Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RNGP - ENTRY_FILE should resolve relative paths from root #36193

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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