Skip to content

Commit

Permalink
[0.75] Fix core autolinking not working on Windows (#45796)
Browse files Browse the repository at this point in the history
  • Loading branch information
cortinico committed Jul 29, 2024
1 parent 011118f commit c8cb3d4
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .circleci/configurations/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ jobs:
- packages/react-native/ReactAndroid/hermes-engine/build/
- packages/react-native/ReactAndroid/src/main/jni/prebuilt/
- packages/react-native-gradle-plugin/.gradle/
- packages/react-native-gradle-plugin/build/
- packages/react-native-gradle-plugin/react-native-gradle-plugin/build/
- packages/react-native-gradle-plugin/settings-plugin/build/
- packages/react-native-gradle-plugin/shared/build/
- packages/react-native-gradle-plugin/shared-testutil/build/
- packages/react-native-codegen/lib/

# -------------------------
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-gradle-plugin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build/
app-plugin/build/
settings-plugin/build/
shared/build/
shared-testutil/build/
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {
implementation(libs.javapoet)

testImplementation(libs.junit)
testImplementation(project(":shared-testutil"))

testRuntimeOnly(
files(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package com.facebook.react.utils
import com.facebook.react.utils.KotlinStdlibCompatUtils.lowercaseCompat
import java.io.File

internal object Os {
object Os {

fun isWindows(): Boolean =
System.getProperty("os.name")?.lowercaseCompat()?.contains("windows") ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

package com.facebook.react.utils

internal fun windowsAwareCommandLine(vararg args: Any): List<Any> =
fun windowsAwareCommandLine(vararg args: Any): List<Any> =
windowsAwareCommandLine(args.toList())

internal fun windowsAwareCommandLine(args: List<Any>): List<Any> =
fun windowsAwareCommandLine(args: List<Any>): List<Any> =
if (Os.isWindows()) {
listOf("cmd", "/c") + args
} else {
args
}

internal fun windowsAwareBashCommandLine(
fun windowsAwareBashCommandLine(
vararg args: String,
bashWindowsHome: String? = null
): List<String> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {
implementation(libs.javapoet)

testImplementation(libs.junit)
testImplementation(project(":shared-testutil"))

testRuntimeOnly(
files(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.facebook.react

import com.facebook.react.utils.JsonUtils
import com.facebook.react.utils.windowsAwareCommandLine
import java.io.File
import java.math.BigInteger
import java.security.MessageDigest
Expand All @@ -25,6 +26,11 @@ abstract class ReactSettingsExtension @Inject constructor(val settings: Settings
private val outputFolder =
settings.layout.rootDirectory.file("build/generated/autolinking/").asFile

private val defaultConfigCommand: List<String> =
windowsAwareCommandLine(listOf("npx", "@react-native-community/cli", "config")).map {
it.toString()
}

/**
* Utility function to autolink libraries using an external command as source of truth.
*
Expand All @@ -39,7 +45,7 @@ abstract class ReactSettingsExtension @Inject constructor(val settings: Settings
*/
@JvmOverloads
public fun autolinkLibrariesFromCommand(
command: List<String> = listOf("npx", "@react-native-community/cli", "config"),
command: List<String> = defaultConfigCommand,
workingDirectory: File? = settings.layout.rootDirectory.dir("../").asFile,
lockFiles: FileCollection =
settings.layout.rootDirectory
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-gradle-plugin/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include(
":react-native-gradle-plugin",
":settings-plugin",
":shared",
":shared-testutil",
)

rootProject.name = "gradle-plugins-root"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins { alias(libs.plugins.kotlin.jvm) }

repositories { mavenCentral() }

group = "com.facebook.react"

dependencies { implementation(libs.junit) }

java { targetCompatibility = JavaVersion.VERSION_11 }

kotlin { jvmToolchain(17) }

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
apiVersion = "1.6"
jvmTarget = "11"
allWarningsAsErrors = true
}
}

tasks.withType<Test>().configureEach {
testLogging {
exceptionFormat = TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
implementation(libs.gson)
implementation(libs.guava)
testImplementation(libs.junit)
testImplementation(project(":shared-testutil"))
}

java { targetCompatibility = JavaVersion.VERSION_11 }
Expand Down

0 comments on commit c8cb3d4

Please sign in to comment.