[kotlin] project-model-updater: add new COMPILER_PUBLICATION application mode

This migration from Gradle configurations to our own app allows passing an arbitrary
Kotlin repo path, so the coop setup can be simplified

^KTIJ-35777

GitOrigin-RevId: fd8bd03fd097e245fc043ba12c167473079ddac2
This commit is contained in:
Dmitrii Gridin
2025-09-30 09:07:30 +00:00
committed by intellij-monorepo-bot
parent d03bffd284
commit effbe80afb
7 changed files with 92 additions and 54 deletions
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Kotlin Coop: Publish Compiler JARs" type="JetRunConfigurationType">
<option name="MAIN_CLASS_NAME" value="org.jetbrains.tools.model.updater.MainKt" />
<module name="kotlin.util.project-model-updater" />
<option name="PROGRAM_PARAMETERS" value="applicationMode=COMPILER_PUBLICATION" />
<shortenClasspath name="NONE" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
@@ -1,28 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Kotlin Coop: Publish compiler-for-ide JARs" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$/.." />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="-Ppublish.ide.plugin.dependencies=true -PdeployVersion=2.3.255-dev-255 -Pbuild.number=2.3.255-dev-255 -Pkotlin.build.deploy-path=intellij/lib/kotlin-snapshot" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="publishIdeArtifacts" />
<option value=":prepare:ide-plugin-dependencies:kotlin-dist-for-ide:publish" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<ExternalSystemDebugDisabled>false</ExternalSystemDebugDisabled>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<GradleProfilingDisabled>false</GradleProfilingDisabled>
<GradleCoverageDisabled>false</GradleCoverageDisabled>
<method v="2" />
</configuration>
</component>
@@ -11,5 +11,8 @@ jpsPluginArtifactsMode=MAVEN
# within this Kotlin Gradle Plugin
kotlinGradlePluginVersion=2.2.0-dev-15683
# The path to the Kotlin compiler repository. The value might be both relative (to the IntelliJ repo root) and absolute
kotlinCompilerRepoPath=..
# Use a local.properties file to override the values above locally without committing them to the repository
# The file should be located in the same directory as this file
@@ -66,6 +66,12 @@ object KotlinTestsDependenciesUtil {
error("cannot detect community root path for class $aClassLocation")
}
val monorepoRoot: Path?
get() = communityRoot.parent?.takeIf { it.resolve(ULTIMATE_MARKER).exists() }
val projectRoot: Path
get() = monorepoRoot ?: communityRoot
private val httpClient = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NEVER).build()
data class DownloadFile(
@@ -15,6 +15,8 @@ class GeneratorPreferences(properties: Properties) : Preferences(properties) {
val applicationMode: ApplicationMode? by OptionalPreference(ApplicationMode::valueOf)
val kotlinCompilerRepoPath: String by MandatoryPreference()
/**
* Represents modes of the application. [PROJECT_MODEL_UPDATER] is the default one.
*/
@@ -27,6 +29,14 @@ class GeneratorPreferences(properties: Properties) : Preferences(properties) {
* @see updateProjectModel
*/
PROJECT_MODEL_UPDATER,
/**
* Runs the compiler artifacts publication, so they might be consumed by [PROJECT_MODEL_UPDATER]
* mode later
*
* @see publishCompiler
*/
COMPILER_PUBLICATION,
;
}
@@ -73,5 +83,6 @@ fun main(args: Array<String>) {
val preferences = GeneratorPreferences.parse(args)
when (preferences.applicationMode) {
null, ApplicationMode.PROJECT_MODEL_UPDATER -> updateProjectModel(preferences)
ApplicationMode.COMPILER_PUBLICATION -> publishCompiler(preferences)
}
}
@@ -0,0 +1,54 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.tools.model.updater
import kotlin.io.path.absolute
import kotlin.io.path.isDirectory
import kotlin.system.exitProcess
internal fun publishCompiler(preferences: GeneratorPreferences) {
val kotlinCompilerRepoPath = preferences.kotlinCompilerRepoPath
val root = KotlinTestsDependenciesUtil.projectRoot
val kotlinRepoRoot = root.resolve(kotlinCompilerRepoPath)
.also {
if (!it.isDirectory()) {
error("Kotlin compiler repo path does not exist or is not a directory: $it")
}
}
.absolute()
.normalize()
println("Kotlin compiler repo: $kotlinRepoRoot")
val kotlinSnapshotPath = KotlinTestsDependenciesUtil.communityRoot
.resolve("lib")
.resolve("kotlin-snapshot")
.absolute()
.normalize()
println("Artifacts path: $kotlinSnapshotPath")
val exitCode = ProcessBuilder(
gradleWrapperExecutable,
"publishIdeArtifacts",
":prepare:ide-plugin-dependencies:kotlin-dist-for-ide:publish",
"-Ppublish.ide.plugin.dependencies=true",
"-PdeployVersion=$BOOTSTRAP_VERSION",
"-Pbuild.number=$BOOTSTRAP_VERSION",
"-Pkotlin.build.deploy-path=$kotlinSnapshotPath",
)
.directory(kotlinRepoRoot.toFile())
.inheritIO()
.start()
.waitFor()
if (exitCode != 0) {
exitProcess(exitCode)
}
println("Successfully published to $kotlinSnapshotPath")
}
private val gradleWrapperExecutable: String
get() {
val isWindows = System.getProperty("os.name").startsWith("Windows", ignoreCase = true)
return if (isWindows) "gradlew.bat" else "./gradlew"
}
@@ -5,7 +5,12 @@ import org.jetbrains.tools.model.updater.impl.JpsLibrary
import org.jetbrains.tools.model.updater.impl.JpsResolverSettings
import org.jetbrains.tools.model.updater.impl.readJpsResolverSettings
import java.nio.file.Path
import kotlin.io.path.*
import kotlin.io.path.Path
import kotlin.io.path.deleteExisting
import kotlin.io.path.isDirectory
import kotlin.io.path.listDirectoryEntries
import kotlin.io.path.readText
import kotlin.io.path.writeText
internal fun updateProjectModel(preferences: GeneratorPreferences) {
copyBootstrapArtifactsToMavenRepositoryIfExists()
@@ -46,10 +51,8 @@ internal fun updateProjectModel(preferences: GeneratorPreferences) {
processRoot(communityRoot, isCommunity = true)
updateLatestGradlePluginVersion(communityRoot, preferences.kotlinGradlePluginVersion)
updateKGPVersionForKotlinNativeTests(communityRoot, preferences.kotlinGradlePluginVersion)
updateCoopRunConfiguration(monorepoRoot, communityRoot)
}
private fun regenerateProjectLibraries(dotIdea: Path, newLibraries: List<JpsLibrary>, resolverSettings: JpsResolverSettings) {
val librariesDir = dotIdea.resolve("libraries")
val oldLibraries = librariesDir.listDirectoryEntries("kotlinc_*").toMutableSet()
@@ -74,29 +77,6 @@ private fun regenerateProjectLibraries(dotIdea: Path, newLibraries: List<JpsLibr
}
}
private fun updateCoopRunConfiguration(monorepoRoot: Path?, communityRoot: Path) {
val runConfigurationFilePath = ".idea/runConfigurations/Kotlin_Coop__Publish_compiler_for_ide_JARs.xml"
val communityRunConfigurationFile = communityRoot.resolve(runConfigurationFilePath)
val originalText = communityRunConfigurationFile.readText()
val communityResultText = originalText.replace(bootstrapVersionRegex) { matchResult ->
"${matchResult.groupValues[1]}$BOOTSTRAP_VERSION${matchResult.groupValues[4]}"
}
communityRunConfigurationFile.writeText(communityResultText)
val monorepoResultText = communityResultText.replace(Regex.fromLiteral("-Pkotlin.build.deploy-path=intellij/")) { matchResult ->
matchResult.groupValues[0] + "community/"
}
require(monorepoResultText != communityResultText)
val monorepoRunConfigurationFile = monorepoRoot?.resolve(runConfigurationFilePath)
monorepoRunConfigurationFile?.writeText(monorepoResultText)
}
private val bootstrapVersionRegex = Regex("(-P(deployVersion|build\\.number)=)(.+?)([ \"])")
internal val kotlinCompilerCliVersionRegex: Regex = Regex("""kotlinCompilerCliVersion\s*=\s*"(\S+)"""")
internal val kotlincKotlinJpsPluginTestsVersionRegex: Regex = Regex("""kotlincKotlinJpsPluginTestsVersion\s*=\s*"(\S+)"""")