From ac6c810d25da9984c0e7ef36b9890b2d1b541426 Mon Sep 17 00:00:00 2001 From: Nikita Bobko Date: Mon, 17 May 2021 17:09:43 +0200 Subject: [PATCH] Make it possible to attach platforms with different versions to kotlin repo --- buildSrc/prepare-deps/build.gradle.kts | 183 ++++++++++-------- buildSrc/src/main/kotlin/localDependencies.kt | 23 ++- gradle.properties | 1 + gradle/versions.properties | 2 + settings.gradle | 2 +- 5 files changed, 127 insertions(+), 84 deletions(-) diff --git a/buildSrc/prepare-deps/build.gradle.kts b/buildSrc/prepare-deps/build.gradle.kts index cc4eca21c9c..7fb0d1eb7b1 100644 --- a/buildSrc/prepare-deps/build.gradle.kts +++ b/buildSrc/prepare-deps/build.gradle.kts @@ -18,6 +18,7 @@ plugins { val intellijUltimateEnabled: Boolean by rootProject.extra val intellijReleaseType: String by rootProject.extra val intellijVersion = rootProject.extra["versions.intellijSdk"] as String +val intellijVersionForIde = rootProject.intellijSdkVersionForIde() val asmVersion = rootProject.findProperty("versions.jar.asm-all") as String? val androidStudioRelease = rootProject.findProperty("versions.androidStudioRelease") as String? val androidStudioBuild = rootProject.findProperty("versions.androidStudioBuild") as String? @@ -25,13 +26,18 @@ val intellijSeparateSdks: Boolean by rootProject.extra val installIntellijCommunity = !intellijUltimateEnabled || intellijSeparateSdks val installIntellijUltimate = intellijUltimateEnabled && androidStudioRelease == null -val intellijVersionDelimiterIndex = intellijVersion.indexOfAny(charArrayOf('.', '-')) -if (intellijVersionDelimiterIndex == -1) { - error("Invalid IDEA version $intellijVersion") +fun checkIntellijVersion(intellijVersion: String) { + val intellijVersionDelimiterIndex = intellijVersion.indexOfAny(charArrayOf('.', '-')) + if (intellijVersionDelimiterIndex == -1) { + error("Invalid IDEA version $intellijVersion") + } } +checkIntellijVersion(intellijVersion) +intellijVersionForIde?.let { checkIntellijVersion(it) } logger.info("intellijUltimateEnabled: $intellijUltimateEnabled") logger.info("intellijVersion: $intellijVersion") +logger.info("intellijVersionForIde: $intellijVersionForIde") logger.info("androidStudioRelease: $androidStudioRelease") logger.info("androidStudioBuild: $androidStudioBuild") logger.info("intellijSeparateSdks: $intellijSeparateSdks") @@ -71,11 +77,16 @@ repositories { } val intellij by configurations.creating +val intellijForIde by configurations.creating val intellijUltimate by configurations.creating +val intellijUltimateForIde by configurations.creating val androidStudio by configurations.creating val sources by configurations.creating +val sourcesForIde by configurations.creating val jpsStandalone by configurations.creating +val jpsStandaloneForIde by configurations.creating val intellijCore by configurations.creating +val intellijCoreForIde by configurations.creating val nodeJSPlugin by configurations.creating /** @@ -104,9 +115,11 @@ dependencies { } else { if (installIntellijCommunity) { intellij("com.jetbrains.intellij.idea:ideaIC:$intellijVersion") + intellijVersionForIde?.let { intellijForIde("com.jetbrains.intellij.idea:ideaIC:$it") } } if (installIntellijUltimate) { intellijUltimate("com.jetbrains.intellij.idea:ideaIU:$intellijVersion") + intellijVersionForIde.let { intellijUltimateForIde("com.jetbrains.intellij.idea:ideaIU:$it") } } } @@ -115,102 +128,111 @@ dependencies { } sources("com.jetbrains.intellij.idea:ideaIC:$intellijVersion:sources@jar") + intellijVersionForIde?.let { sourcesForIde("com.jetbrains.intellij.idea:ideaIC:$it:sources@jar") } jpsStandalone("com.jetbrains.intellij.idea:jps-standalone:$intellijVersion") + intellijVersionForIde?.let { jpsStandaloneForIde("com.jetbrains.intellij.idea:jps-standalone:$it") } intellijCore("com.jetbrains.intellij.idea:intellij-core:$intellijVersion") + intellijVersionForIde?.let { intellijCoreForIde("com.jetbrains.intellij.idea:intellij-core:$it") } if (intellijUltimateEnabled) { nodeJSPlugin("com.jetbrains.plugins:NodeJS:${rootProject.extra["versions.idea.NodeJS"]}@zip") } } -val makeIntellijCore = buildIvyRepositoryTask(intellijCore, customDepsOrg, customDepsRepoDir) +fun prepareDeps(intellij: Configuration, intellijCore: Configuration, sources: Configuration, intellijUltimate: Configuration, jpsStandalone: Configuration, intellijVersion: String) { + val makeIntellijCore = buildIvyRepositoryTask(intellijCore, customDepsOrg, customDepsRepoDir) -val makeIntellijAnnotations by tasks.registering(Copy::class) { - dependsOn(makeIntellijCore) + val makeIntellijAnnotations = tasks.register("makeIntellijAnnotations${intellij.name.capitalize()}", Copy::class) { + dependsOn(makeIntellijCore) - val intellijCoreRepo = CleanableStore[repoDir.resolve("intellij-core").absolutePath][intellijVersion].use() - from(intellijCoreRepo.resolve("artifacts/annotations.jar")) + val intellijCoreRepo = CleanableStore[repoDir.resolve("intellij-core").absolutePath][intellijVersion].use() + from(intellijCoreRepo.resolve("artifacts/annotations.jar")) - val annotationsStore = CleanableStore[repoDir.resolve(intellijRuntimeAnnotations).absolutePath] - val targetDir = annotationsStore[intellijVersion].use() - into(targetDir) + val annotationsStore = CleanableStore[repoDir.resolve(intellijRuntimeAnnotations).absolutePath] + val targetDir = annotationsStore[intellijVersion].use() + into(targetDir) - val ivyFile = File(targetDir, "$intellijRuntimeAnnotations.ivy.xml") - outputs.files(ivyFile) + val ivyFile = File(targetDir, "$intellijRuntimeAnnotations.ivy.xml") + outputs.files(ivyFile) - doFirst { - annotationsStore.cleanStore() + doFirst { + annotationsStore.cleanStore() + } + + doLast { + writeIvyXml( + customDepsOrg, + intellijRuntimeAnnotations, + intellijVersion, + intellijRuntimeAnnotations, + targetDir, + targetDir, + targetDir, + allowAnnotations = true + ) + } } - doLast { - writeIvyXml( + val mergeSources = tasks.create("mergeSources${intellij.name.capitalize()}", Jar::class.java) { + dependsOn(sources) + isPreserveFileTimestamps = false + isReproducibleFileOrder = true + isZip64 = true + if (!kotlinBuildProperties.isTeamcityBuild) { + from(provider { sources.map(::zipTree) }) + } + destinationDirectory.set(File(repoDir, sources.name)) + archiveBaseName.set("intellij") + archiveClassifier.set("sources") + archiveVersion.set(intellijVersion) + } + + val sourcesFile = mergeSources.outputs.files.singleFile + + val makeIde = if (androidStudioBuild != null) { + buildIvyRepositoryTask( + androidStudio, customDepsOrg, - intellijRuntimeAnnotations, - intellijVersion, - intellijRuntimeAnnotations, - targetDir, - targetDir, - targetDir, - allowAnnotations = true + customDepsRepoDir, + if (androidStudioOs == "mac") + ::skipContentsDirectory + else + ::skipToplevelDirectory + ) + } else { + val task = if (installIntellijUltimate) { + buildIvyRepositoryTask(intellijUltimate, customDepsOrg, customDepsRepoDir, null, sourcesFile) + } else { + buildIvyRepositoryTask(intellij, customDepsOrg, customDepsRepoDir, null, sourcesFile) + } + + task.configure { + dependsOn(mergeSources) + } + + task + } + + val buildJpsStandalone = buildIvyRepositoryTask(jpsStandalone, customDepsOrg, customDepsRepoDir, null, sourcesFile) + + tasks.named("build") { + dependsOn( + makeIntellijCore, + makeIde, + buildJpsStandalone, + makeIntellijAnnotations ) } -} -val mergeSources by tasks.creating(Jar::class.java) { - dependsOn(sources) - isPreserveFileTimestamps = false - isReproducibleFileOrder = true - isZip64 = true - if (!kotlinBuildProperties.isTeamcityBuild) { - from(provider { sources.map(::zipTree) }) + if (installIntellijUltimate) { + val buildNodeJsPlugin = + buildIvyRepositoryTask(nodeJSPlugin, customDepsOrg, customDepsRepoDir, ::skipToplevelDirectory, sourcesFile) + tasks.named("build") { dependsOn(buildNodeJsPlugin) } } - destinationDirectory.set(File(repoDir, sources.name)) - archiveBaseName.set("intellij") - archiveClassifier.set("sources") - archiveVersion.set(intellijVersion) } -val sourcesFile = mergeSources.outputs.files.singleFile - -val makeIde = if (androidStudioBuild != null) { - buildIvyRepositoryTask( - androidStudio, - customDepsOrg, - customDepsRepoDir, - if (androidStudioOs == "mac") - ::skipContentsDirectory - else - ::skipToplevelDirectory - ) -} else { - val task = if (installIntellijUltimate) { - buildIvyRepositoryTask(intellijUltimate, customDepsOrg, customDepsRepoDir, null, sourcesFile) - } else { - buildIvyRepositoryTask(intellij, customDepsOrg, customDepsRepoDir, null, sourcesFile) - } - - task.configure { - dependsOn(mergeSources) - } - - task -} - -val buildJpsStandalone = buildIvyRepositoryTask(jpsStandalone, customDepsOrg, customDepsRepoDir, null, sourcesFile) - -tasks.named("build") { - dependsOn( - makeIntellijCore, - makeIde, - buildJpsStandalone, - makeIntellijAnnotations - ) - -} - -if (installIntellijUltimate) { - val buildNodeJsPlugin = - buildIvyRepositoryTask(nodeJSPlugin, customDepsOrg, customDepsRepoDir, ::skipToplevelDirectory, sourcesFile) - tasks.named("build") { dependsOn(buildNodeJsPlugin) } +prepareDeps(intellij, intellijCore, sources, intellijUltimate, jpsStandalone, intellijVersion) +if (intellijVersionForIde != null) { + prepareDeps(intellijForIde, intellijCoreForIde, sourcesForIde, intellijUltimateForIde, jpsStandaloneForIde, intellijVersionForIde) } tasks.named("clean") { @@ -397,6 +419,11 @@ fun skipToplevelDirectory(path: String) = path.substringAfter('/') fun skipContentsDirectory(path: String) = path.substringAfter("Contents/") +fun Project.intellijSdkVersionForIde(): String? { + val majorVersion = kotlinBuildProperties.getOrNull("attachedIntellijVersion") as? String ?: return null + return rootProject.findProperty("versions.intellijSdk.forIde.$majorVersion") as? String +} + class XMLWriter(private val outputStreamWriter: OutputStreamWriter) : Closeable { private val xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStreamWriter) diff --git a/buildSrc/src/main/kotlin/localDependencies.kt b/buildSrc/src/main/kotlin/localDependencies.kt index 95fd6dacd56..8dda6b7c35a 100644 --- a/buildSrc/src/main/kotlin/localDependencies.kt +++ b/buildSrc/src/main/kotlin/localDependencies.kt @@ -42,9 +42,21 @@ private fun Project.ideModuleName() = when (IdeVersionConfigurator.currentIde.ki } } -private fun Project.ideModuleVersion() = when (IdeVersionConfigurator.currentIde.kind) { +private fun Project.ideModuleVersion(forIde: Boolean) = when (IdeVersionConfigurator.currentIde.kind) { Ide.Kind.AndroidStudio -> rootProject.findProperty("versions.androidStudioBuild") - Ide.Kind.IntelliJ -> rootProject.findProperty("versions.intellijSdk") + Ide.Kind.IntelliJ -> { + if (forIde) { + intellijSdkVersionForIde() + ?: error("Please specify 'attachedIntellijVersion' in your local.properties") + } else { + rootProject.findProperty("versions.intellijSdk") + } + } +} + +fun Project.intellijSdkVersionForIde(): String? { + val majorVersion = kotlinBuildProperties.getOrNull("attachedIntellijVersion") as? String ?: return null + return rootProject.findProperty("versions.intellijSdk.forIde.$majorVersion") as? String } fun RepositoryHandler.kotlinBuildLocalRepo(project: Project): IvyArtifactRepository = ivy { @@ -69,7 +81,8 @@ fun RepositoryHandler.kotlinBuildLocalRepo(project: Project): IvyArtifactReposit } } -fun Project.intellijDep(module: String? = null) = "kotlin.build:${module ?: ideModuleName()}:${ideModuleVersion()}" +fun Project.intellijDep(module: String? = null, forIde: Boolean = false) = + "kotlin.build:${module ?: ideModuleName()}:${ideModuleVersion(forIde)}" fun Project.intellijCoreDep() = "kotlin.build:intellij-core:${rootProject.extra["versions.intellijSdk"]}" @@ -94,7 +107,7 @@ fun Project.kotlinxCollectionsImmutable() = "org.jetbrains.kotlinx:kotlinx-colle */ fun Project.intellijRuntimeAnnotations() = "kotlin.build:intellij-runtime-annotations:${rootProject.extra["versions.intellijSdk"]}" -fun Project.intellijPluginDep(plugin: String) = intellijDep(plugin) +fun Project.intellijPluginDep(plugin: String, forIde: Boolean = false) = intellijDep(plugin, forIde) fun Project.intellijUltimateDep() = intellijDep("ideaIU") @@ -126,7 +139,7 @@ object IntellijRootUtils { fun getIntellijRootDir(project: Project): File = with(project.rootProject) { return File( getRepositoryRootDir(this), - "${ideModuleName()}/${ideModuleVersion()}/artifacts" + "${ideModuleName()}/${ideModuleVersion(forIde = false)}/artifacts" ) } } diff --git a/gradle.properties b/gradle.properties index bf8d2630b05..8db67dd03f7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,6 +27,7 @@ kotlin.build.publishing.attempts=20 #jpsBuild=true #cidrPluginsEnabled=true #idea.fir.plugin=true +#attachedIntellijVersion=203 (or any other platform version) ## Used for compare gradle and jps build diff --git a/gradle/versions.properties b/gradle/versions.properties index ad6c73e856f..9dba06f8a24 100644 --- a/gradle/versions.properties +++ b/gradle/versions.properties @@ -1,4 +1,6 @@ versions.intellijSdk=202.7660.26 +versions.intellijSdk.forIde.202=202.7660.26 +versions.intellijSdk.forIde.203=203.6682.168 versions.idea.NodeJS=193.6494.7 versions.jar.asm-all=8.0.1 versions.jar.guava=29.0-jre diff --git a/settings.gradle b/settings.gradle index 656380ca27f..bf8ea124815 100644 --- a/settings.gradle +++ b/settings.gradle @@ -382,7 +382,7 @@ include ":prepare:ide-plugin-dependencies:android-extensions-compiler-plugin-for ":prepare:ide-plugin-dependencies:compiler-components-for-jps", ":prepare:ide-plugin-dependencies:kotlin-compiler-tests-for-ide" -if (buildProperties.getBoolean("attachedIntellijVersion", false)) { +if (buildProperties.getOrNull("attachedIntellijVersion") != null) { logger.info("Including kotlin-ide modules in settings.gradle") new File(rootDir, "kotlin-ide").eachFileRecurse { String fileName = it.name