Skip to content
Merged
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
90 changes: 47 additions & 43 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,15 @@ val buildResharperPlugin by tasks.registering(Exec::class) {
}

tasks.buildPlugin {
// Capture providers/files at configuration time so the doLast doesn't touch Project APIs
// (project.copy(), project.buildDir, project.rootDir) — required for the configuration cache.
val pluginZip = layout.buildDirectory.file("distributions/${rootProject.name}-${version}.zip")
val outputDir = layout.projectDirectory.dir("output").asFile

doLast {
copy {
from("${buildDir}/distributions/${rootProject.name}-${version}.zip")
into("${rootDir}/output")
}
val zipFile = pluginZip.get().asFile
outputDir.mkdirs()
zipFile.copyTo(outputDir.resolve(zipFile.name), overwrite = true)
}
}

Expand Down Expand Up @@ -155,58 +159,58 @@ tasks.runIde {
}
}

// The Rider SDK archive omits certain DLLs that are present in a full Rider installation.
// Copy the missing Unity plugin DotFiles DLLs from the local Rider installation so the sandbox can load them.
//
// This is a side-effect on the extracted SDK (intellijPlatform.platformPath) — *not* a declared task output — because
// other tasks (patchPluginXml, buildPlugin, etc.) read from that same directory. Declaring it as an OutputDirectory
// would make Gradle complain about implicit dependencies. Hooking it as a `doLast` on prepareSandbox keeps it as a
// transparent mutation of the SDK that runs before any consumer.
//
// All Project-API access (file(), intellijPlatform.platformPath, system properties) is hoisted to configuration time
// and captured into locals so the action stays compatible with the configuration cache.
if (!isWindows) {
tasks.register("copyRiderDlls") {
notCompatibleWithConfigurationCache("Uses local Rider install")

// The Rider SDK archive omits certain DLLs that are present in a full Rider installation.
// Copy the missing Unity plugin DotFiles DLL from the local Rider installation so the sandbox can load it.
if (!isWindows) {
val riderInstallCandidates = if (Os.isFamily(Os.FAMILY_MAC)) {
listOf(file("/Applications/Rider.app/Contents"))
} else {
// Linux: check JetBrains Toolbox and common standalone install paths
val toolboxBase = file("${System.getProperty("user.home")}/.local/share/JetBrains/Toolbox/apps/Rider")
val toolboxInstalls = if (toolboxBase.exists()) {
toolboxBase.walkTopDown()
.filter { it.name == "plugins" && it.parentFile?.name?.startsWith("2") == true }
.map { it.parentFile }
.toList()
} else emptyList()
toolboxInstalls + listOf(file("/opt/rider"), file("/usr/share/rider"))
}
val riderInstallCandidates: List<File> = if (Os.isFamily(Os.FAMILY_MAC)) {
listOf(File("/Applications/Rider.app/Contents"))
} else {
// Linux: check JetBrains Toolbox and common standalone install paths
val userHome = providers.systemProperty("user.home").get()
val toolboxBase = File("$userHome/.local/share/JetBrains/Toolbox/apps/Rider")
val toolboxInstalls = if (toolboxBase.exists()) {
toolboxBase.walkTopDown()
.filter { it.name == "plugins" && it.parentFile?.name?.startsWith("2") == true }
.map { it.parentFile }
.toList()
} else emptyList()
toolboxInstalls + listOf(File("/opt/rider"), File("/usr/share/rider"))
}

val missingDotFileDlls = listOf(
"JetBrains.ReSharper.Plugins.Unity.Rider.Debugger.PausePoint.Helper.dll",
"JetBrains.ReSharper.Plugins.Unity.Rider.Debugger.Presentation.Texture.dll",
)
val missingDotFileDlls = listOf(
"JetBrains.ReSharper.Plugins.Unity.Rider.Debugger.PausePoint.Helper.dll",
"JetBrains.ReSharper.Plugins.Unity.Rider.Debugger.Presentation.Texture.dll",
)

val destDir = intellijPlatform.platformPath.resolve("plugins/rider-unity/DotFiles").toFile()
destDir.mkdirs()
val resolvedRiderDllSources: List<File> = missingDotFileDlls.mapNotNull { dllName ->
val rel = "plugins/rider-unity/DotFiles/$dllName"
riderInstallCandidates.map { File(it, rel) }.firstOrNull { it.exists() }
}

for (dllName in missingDotFileDlls) {
val dllRelPath = "plugins/rider-unity/DotFiles/$dllName"
val srcDll = riderInstallCandidates
.map { file("${it}/${dllRelPath}") }
.firstOrNull { it.exists() }
val riderDllDestDir = intellijPlatform.platformPath.resolve("plugins/rider-unity/DotFiles").toFile()

if (srcDll != null) {
// Copy into the extracted SDK location (platformPath) — that's where Rider loads plugins from at runtime
srcDll.copyTo(file("${destDir}/${srcDll.name}"), overwrite = true)
}
tasks.prepareSandbox {
doLast {
riderDllDestDir.mkdirs()
resolvedRiderDllSources.forEach { src ->
src.copyTo(File(riderDllDestDir, src.name), overwrite = true)
}
}
}

tasks.named("prepareSandbox") {
dependsOn("copyRiderDlls")
}
}

tasks.prepareSandbox {
dependsOn(compileDotNet)

val outputFolder = layout.projectDirectory.dir("/src/dotnet/${DotnetPluginId}/bin/${DotnetPluginId}.Rider/${BuildConfiguration}")
val outputFolder = layout.projectDirectory.dir("src/dotnet/${DotnetPluginId}/bin/${DotnetPluginId}.Rider/${BuildConfiguration}")

val dllFiles = listOf(
"$outputFolder/${DotnetPluginId}.dll",
Expand Down
Loading