Skip to content

Commit c422be4

Browse files
committed
Fixed Kotlin Master and switched back Npm -> Yarn (resolved KT-78504)
1 parent 43c9b00 commit c422be4

File tree

12 files changed

+112
-133
lines changed

12 files changed

+112
-133
lines changed

compiler-plugin/compiler-plugin-cli/src/main/kotlin/kotlinx/rpc/codegen/RpcCompilerPlugin.kt renamed to compiler-plugin/compiler-plugin-cli/src/main/kotlin/kotlinx/rpc/codegen/RpcCommandLineProcessor.kt

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44

55
package kotlinx.rpc.codegen
66

7-
import kotlinx.rpc.codegen.extension.RpcIrExtension
8-
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
97
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
108
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
11-
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
129
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
1310
import org.jetbrains.kotlin.config.CompilerConfiguration
14-
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrarAdapter
1511

1612
@OptIn(ExperimentalCompilerApi::class)
1713
class RpcCommandLineProcessor : CommandLineProcessor {
18-
override val pluginId = "kotlinx-rpc"
14+
override val pluginId = PLUGIN_ID
1915

2016
override val pluginOptions = listOf(
2117
RpcFirCliOptions.ANNOTATION_TYPE_SAFETY,
@@ -37,20 +33,3 @@ class RpcCommandLineProcessor : CommandLineProcessor {
3733
}
3834
}
3935
}
40-
41-
@OptIn(ExperimentalCompilerApi::class)
42-
class RpcCompilerPlugin : CompilerPluginRegistrar() {
43-
override val supportsK2: Boolean = true
44-
45-
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
46-
registerRpcExtensions(configuration)
47-
}
48-
}
49-
50-
@OptIn(ExperimentalCompilerApi::class)
51-
fun CompilerPluginRegistrar.ExtensionStorage.registerRpcExtensions(configuration: CompilerConfiguration) {
52-
VersionSpecificApi.INSTANCE = VersionSpecificApiImpl
53-
54-
IrGenerationExtension.registerExtension(RpcIrExtension(configuration))
55-
FirExtensionRegistrarAdapter.registerExtension(FirRpcExtensionRegistrar(configuration))
56-
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.rpc.codegen
6+
7+
const val PLUGIN_ID = "org.jetbrains.kotlinx.rpc"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.rpc.codegen
6+
7+
import kotlinx.rpc.codegen.extension.RpcIrExtension
8+
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
9+
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
10+
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
11+
import org.jetbrains.kotlin.config.CompilerConfiguration
12+
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrarAdapter
13+
14+
@OptIn(ExperimentalCompilerApi::class)
15+
fun CompilerPluginRegistrar.ExtensionStorage.registerRpcExtensions(configuration: CompilerConfiguration) {
16+
VersionSpecificApi.INSTANCE = VersionSpecificApiImpl
17+
18+
IrGenerationExtension.registerExtension(RpcIrExtension(configuration))
19+
FirExtensionRegistrarAdapter.registerExtension(FirRpcExtensionRegistrar(configuration))
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.rpc.codegen
6+
7+
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
8+
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
9+
import org.jetbrains.kotlin.config.CompilerConfiguration
10+
11+
@OptIn(ExperimentalCompilerApi::class)
12+
class RpcCompilerPlugin : CompilerPluginRegistrar() {
13+
override val supportsK2: Boolean = true
14+
15+
//##csm RpcCompilerPlugin.pluginId
16+
//##csm specific=[2.0.0...2.2.99]
17+
//##csm /specific
18+
//##csm default
19+
override val pluginId: String = PLUGIN_ID
20+
//##csm /default
21+
//##csm /RpcCompilerPlugin.pluginId
22+
23+
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
24+
registerRpcExtensions(configuration)
25+
}
26+
}

compiler-plugin/compiler-plugin-k2/src/main/kotlin/kotlinx/rpc/codegen/FirRpcServiceGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class FirRpcServiceGenerator(
9696
* Generates [owner]'s service stub.
9797
* Scrapes the functions from the [owner] to generate method classes.
9898
*/
99-
private fun generateRpcServiceStubClass(owner: FirClassSymbol<*>): FirRegularClassSymbol? {
99+
private fun generateRpcServiceStubClass(owner: FirClassSymbol<*>): FirRegularClassSymbol {
100100
return createNestedClass(owner, RpcNames.SERVICE_STUB_NAME, RpcGeneratedStubKey(owner.name)) {
101101
visibility = Visibilities.Public
102102
modality = Modality.FINAL

compiler-plugin/gradle.properties

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ org.gradle.configuration-cache=true
2020
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
2121
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
2222

23-
# https://youtrack.jetbrains.com/issue/KT-78504
24-
kotlin.js.yarn=false
25-
2623
# development mode for kotlinx.rpc gradle plugin. Uses local project paths to apply the compiler plugin
2724
kotlinx.rpc.plugin.internalDevelopment=true
2825

dokka-plugin/gradle.properties

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ org.gradle.configuration-cache=true
2020
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
2121
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
2222

23-
# https://youtrack.jetbrains.com/issue/KT-78504
24-
kotlin.js.yarn=false
25-
2623
# development mode for kotlinx.rpc gradle plugin. Uses local project paths to apply the compiler plugin
2724
kotlinx.rpc.plugin.internalDevelopment=true
2825

dowload_kotlin_master.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
5+
#
6+
7+
set -e
8+
9+
if [[ -z $BUILD_SERVER_TOKEN ]]; then
10+
BUILD_SERVER_TOKEN=$(cat "$HOME"/.gradle/gradle.properties | sed -En 's/buildserver.token=(.*)/\1/p')
11+
12+
if [[ -z $BUILD_SERVER_TOKEN ]]; then
13+
echo "No BUILD_SERVER_TOKEN token present"
14+
exit 1
15+
fi;
16+
fi;
17+
18+
# Artifacts from https://teamcity.jetbrains.com/buildConfiguration/Kotlin_KotlinPublic_Artifacts
19+
response=$(curl -f "https://teamcity.jetbrains.com/app/rest/builds?locator=count:1,buildType:Kotlin_KotlinPublic_Artifacts,status:SUCCESS,state:finished" --request GET --header "Authorization: Bearer $BUILD_SERVER_TOKEN")
20+
21+
buildId=$(echo "$response" | sed -En 's/.*build id="([0-9]+)".*/\1/p')
22+
echo "Build id: $buildId"
23+
24+
version=$(echo "$response" | sed -En 's/.*number="([0-9a-zA-Z\.-]+)".*/\1/p')
25+
echo "Build Kotlin version: $version"
26+
27+
curl -f "https://teamcity.jetbrains.com/app/rest/builds/id:$buildId/artifacts/content/maven.zip" --request GET --header "Authorization: Bearer $BUILD_SERVER_TOKEN" --output maven.zip
28+
29+
unzip maven.zip -d lib-kotlin
30+
31+
rm maven.zip

gradle-conventions/src/main/kotlin/util/tasks/npm.kt

Lines changed: 24 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,31 @@ package util.tasks
66

77
import org.gradle.api.GradleException
88
import org.gradle.api.Project
9-
import org.gradle.api.Task
10-
import org.gradle.api.tasks.Delete
11-
import org.gradle.api.tasks.Exec
12-
import org.gradle.api.tasks.TaskProvider
13-
import org.gradle.kotlin.dsl.*
14-
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsEnvSpec
15-
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
16-
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
17-
import org.jetbrains.kotlin.gradle.targets.js.npm.BaseNpmExtension
18-
import org.jetbrains.kotlin.gradle.targets.js.npm.LockFileMismatchReport
19-
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmExtension
20-
import org.jetbrains.kotlin.gradle.targets.wasm.nodejs.WasmNodeJsEnvSpec
21-
import org.jetbrains.kotlin.gradle.targets.wasm.nodejs.WasmNodeJsRootExtension
22-
import org.jetbrains.kotlin.gradle.targets.wasm.nodejs.WasmNodeJsRootPlugin
23-
import org.jetbrains.kotlin.gradle.targets.wasm.npm.WasmNpmExtension
24-
import org.jetbrains.kotlin.gradle.targets.web.nodejs.BaseNodeJsEnvSpec
25-
import org.jetbrains.kotlin.gradle.targets.web.nodejs.BaseNodeJsRootExtension
26-
import org.jetbrains.kotlin.gradle.targets.web.nodejs.CommonNodeJsRootPlugin
9+
import org.gradle.kotlin.dsl.assign
10+
import org.gradle.kotlin.dsl.configure
11+
import org.gradle.kotlin.dsl.provideDelegate
12+
import org.gradle.kotlin.dsl.withType
13+
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
14+
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
15+
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootEnvSpec
16+
import org.jetbrains.kotlin.gradle.targets.wasm.yarn.WasmYarnPlugin
17+
import org.jetbrains.kotlin.gradle.targets.wasm.yarn.WasmYarnRootEnvSpec
18+
import org.jetbrains.kotlin.gradle.targets.web.yarn.BaseYarnRootEnvSpec
19+
import org.jetbrains.kotlin.gradle.targets.web.yarn.CommonYarnPlugin
2720
import util.other.optionalProperty
2821
import util.other.spacePassword
2922
import util.other.useProxyRepositories
3023
import java.io.File
3124

32-
const val PUPPETEER_BROWSERS_DIR = ".puppeteer"
33-
3425
private inline fun <
35-
reified Plugin : CommonNodeJsRootPlugin,
36-
reified Spec : BaseNodeJsEnvSpec,
37-
reified RootExtension : BaseNodeJsRootExtension,
26+
reified Plugin : CommonYarnPlugin,
27+
reified Spec : BaseYarnRootEnvSpec,
3828
> Project.registerCustomNpmTasks(
3929
target: String,
4030
useProxy: Boolean,
4131
) {
4232
val capitalizedTarget = target.replaceFirstChar { it.titlecase() }
43-
val login = tasks.register("execute${capitalizedTarget}NpmLogin") {
33+
tasks.register("execute${capitalizedTarget}NpmLogin") {
4434
if (!useProxyRepositories) {
4535
return@register
4636
}
@@ -91,100 +81,38 @@ private inline fun <
9181
if (useProxy) {
9282
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
9383
}
94-
95-
val nodeExecutable = executable
96-
97-
extensions.configure<RootExtension> {
98-
/**
99-
* Long story short:
100-
* We can use Yarn because of this: https://youtrack.jetbrains.com/issue/KT-78504
101-
* So: `kotlin.js.yarn=false`
102-
*
103-
* When we use `npm` instead, it runs `npm install` task.
104-
* That should install `puppeteer` package, which should run its script `install.mjs`.
105-
* That script installs browsers for tests.
106-
*
107-
* If we pass `--ignore-scripts` to npm, the script won't be executed.
108-
* KGP does it by default.
109-
* So we set `ignoreScripts = false`.
110-
* We set it for `NpmExtension` and `WasmNpmExtension` in `NodeJsRootPlugin` and `WasmNodeJsRootPlugin`
111-
* respectively (and not their common supertype because it will not work)
112-
*
113-
* And this approach worked for Yarn.
114-
* Script was executed, browsers were installed.
115-
*
116-
* For some reason, for `npm` it didn't work.
117-
* Even with a proper flag (which I checked with a --debug flag).
118-
*
119-
* So we need to run the script manually AFTER `kotlinNpmInstall` (or `kotlinWasmNpmInstall`).
120-
* But also, BEFORE every other action that comes after `kotlinNpmInstall` (or `kotlinWasmNpmInstall`),
121-
* as otherwise there will be race in parallel tasks execution.
122-
*
123-
* Hence, all shenanigans.
124-
*/
125-
val puppeteerInstall = tasks.register<Exec>("puppeteerInstall$capitalizedTarget") {
126-
commandLine(nodeExecutable.get(), "build/$target/node_modules/puppeteer/install.mjs")
127-
workingDir = rootProject.projectDir
128-
129-
// keep in sync with <ROOT>/.puppeteer.cjs
130-
outputs.dir(rootProject.projectDir.resolve(PUPPETEER_BROWSERS_DIR).resolve("browsers"))
131-
}
132-
133-
npmInstallTaskProvider.configure {
134-
dependsOn(login)
135-
finalizedBy(puppeteerInstall)
136-
}
137-
138-
tasks.matching { task ->
139-
task.dependsOn.any { dependency ->
140-
when (dependency) {
141-
is Task -> dependency == npmInstallTaskProvider.get()
142-
is TaskProvider<*> -> dependency == npmInstallTaskProvider
143-
is String -> dependency == npmInstallTaskProvider.name
144-
else -> false
145-
}
146-
}
147-
}.configureEach {
148-
dependsOn(puppeteerInstall)
149-
}
150-
}
15184
}
15285
}
15386
}
15487

15588
@Suppress("UnusedReceiverParameter")
156-
fun BaseNpmExtension.configureNpmExtension(useProxy: Boolean, kotlinMasterBuild: Boolean) {
157-
// todo it still doesn't work for an unknown reason, see 'puppeteerInstall*' tasks above
89+
fun BaseYarnRootEnvSpec.configureNpmExtension(useProxy: Boolean, kotlinMasterBuild: Boolean) {
15890
ignoreScripts = false // if true - puppeteer won't install browsers
15991

160-
packageLockMismatchReport = if (useProxy && !kotlinMasterBuild) {
161-
LockFileMismatchReport.FAIL
92+
yarnLockMismatchReport = if (useProxy && !kotlinMasterBuild) {
93+
YarnLockMismatchReport.FAIL
16294
} else {
163-
LockFileMismatchReport.WARNING
95+
YarnLockMismatchReport.WARNING
16496
}
16597
}
16698

16799
fun Project.configureNpm() {
168100
val kotlinMasterBuild by optionalProperty()
169101
val useProxy = useProxyRepositories
170102

171-
registerCustomNpmTasks<NodeJsRootPlugin, NodeJsEnvSpec, NodeJsRootExtension>("js", useProxy)
172-
registerCustomNpmTasks<WasmNodeJsRootPlugin, WasmNodeJsEnvSpec, WasmNodeJsRootExtension>("wasm", useProxy)
103+
registerCustomNpmTasks<YarnPlugin, YarnRootEnvSpec>("js", useProxy)
104+
registerCustomNpmTasks<WasmYarnPlugin, WasmYarnRootEnvSpec>("wasm", useProxy)
173105

174106
// necessary for CI js tests
175-
rootProject.plugins.withType<NodeJsRootPlugin> {
176-
rootProject.extensions.configure<NpmExtension> {
107+
rootProject.plugins.withType<YarnPlugin> {
108+
rootProject.extensions.configure<YarnRootEnvSpec> {
177109
configureNpmExtension(useProxy, kotlinMasterBuild)
178110
}
179111
}
180112

181-
rootProject.plugins.withType<WasmNodeJsRootPlugin> {
182-
rootProject.extensions.configure<WasmNpmExtension> {
113+
rootProject.plugins.withType<WasmYarnPlugin> {
114+
rootProject.extensions.configure<WasmYarnRootEnvSpec> {
183115
configureNpmExtension(useProxy, kotlinMasterBuild)
184116
}
185117
}
186-
187-
tasks.named<Delete>("clean") {
188-
delete(project.layout.projectDirectory.dir(PUPPETEER_BROWSERS_DIR))
189-
}
190118
}

gradle-plugin/gradle.properties

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ org.gradle.configuration-cache=true
2020
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
2121
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
2222

23-
# https://youtrack.jetbrains.com/issue/KT-78504
24-
kotlin.js.yarn=false
25-
2623
# development mode for kotlinx.rpc gradle plugin. Uses local project paths to apply the compiler plugin
2724
kotlinx.rpc.plugin.internalDevelopment=true
2825

0 commit comments

Comments
 (0)