Skip to content

Commit 54c01d6

Browse files
Abduqodiri Qurbonzodaqurbonzoda
authored andcommitted
Prepare kotlinx-benchmark for including to the Kotlin Community Projects
Support passing an url for a kotlin compiler repository: Kotlin compiler artifacts should be downloaded from maven central by default. In case of compiling with not-published into the MC kotlin compiler artifacts, a kotlin_repo_url should be specified as a gradle parameter(E.g. space kotlin/dev repo).
1 parent 59a0ae2 commit 54c01d6

File tree

9 files changed

+94
-1
lines changed

9 files changed

+94
-1
lines changed

build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ buildscript {
22
repositories {
33
maven { url 'https://maven.pkg.jetbrains.space/kotlin/p/kotlinx/maven' }
44
gradlePluginPortal()
5+
6+
KotlinCommunity.addDevRepositoryIfEnabled(delegate, project)
57
}
68

79
dependencies {
@@ -37,4 +39,11 @@ afterEvaluate {
3739
gradle.includedBuilds.forEach { included ->
3840
project(":kotlinx-benchmark-runtime").tasks.named("publishToMavenLocal") { dependsOn(included.task(":publishToMavenLocal")) }
3941
}
40-
}
42+
}
43+
44+
allprojects {
45+
logger.info("Using Kotlin $kotlin_version for project $it")
46+
repositories {
47+
KotlinCommunity.addDevRepositoryIfEnabled(delegate, project)
48+
}
49+
}

buildSrc/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import org.jetbrains.kotlin.gradle.plugin.*
2+
import java.util.*
3+
4+
plugins {
5+
`kotlin-dsl`
6+
}
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
kotlinDslPluginOptions {
13+
experimentalWarning.set(false)
14+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@file:JvmName("KotlinCommunity")
2+
3+
import org.gradle.api.Project
4+
import org.gradle.api.artifacts.dsl.*
5+
import java.net.*
6+
import java.util.logging.Logger
7+
8+
/*
9+
* Functions in this file are responsible for configuring kotlinx-benchmarks build against a custom dev version
10+
* of Kotlin compiler.
11+
* Such configuration is used in aggregate builds of Kotlin in order to check whether not-yet-released changes
12+
* are compatible with our libraries (aka "integration testing that substitues lack of unit testing").
13+
*/
14+
15+
/**
16+
* Kotlin compiler artifacts are expected to be downloaded from maven central by default.
17+
* In case of compiling with kotlin compiler artifacts that are not published into the MC,
18+
* a kotlin_repo_url gradle parameter should be specified.
19+
* To reproduce a build locally, a kotlin/dev repo should be passed.
20+
*
21+
* @return an url for a kotlin compiler repository parametrized from command line or gradle.properties,
22+
* empty string otherwise
23+
*/
24+
fun getKotlinDevRepositoryUrl(project: Project): String? {
25+
val url = project.rootProject.properties["kotlin_repo_url"] as? String
26+
if (url != null) {
27+
project.logger.info("""Configured Kotlin Compiler repository url: '$url' for project ${project.name}""")
28+
}
29+
return url
30+
}
31+
32+
/**
33+
* If the kotlin_repo_url gradle parameter is provided, adds it to the [repositoryHandler].
34+
*/
35+
fun addDevRepositoryIfEnabled(repositoryHandler: RepositoryHandler, project: Project) {
36+
val devRepoUrl = getKotlinDevRepositoryUrl(project) ?: return
37+
repositoryHandler.maven {
38+
url = URI.create(devRepoUrl)
39+
}
40+
}

integration/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,7 @@ dependencies {
8080

8181
testImplementation(kotlin("test-junit"))
8282
}
83+
84+
tasks.test {
85+
systemProperty("kotlin_repo_url", rootProject.properties["kotlin_repo_url"])
86+
}

integration/src/test/kotlin/kotlinx/benchmark/integration/GradleTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ abstract class GradleTest {
2626
templates.resolve(name).copyRecursively(rootProjectDir)
2727
file("build.gradle").modify(builder::build)
2828
file("settings.gradle").writeText("") // empty settings file
29+
val kotlinDevUrl = System.getProperty("kotlin_repo_url")
30+
if (!kotlinDevUrl.isNullOrBlank()) {
31+
file("gradle.properties").appendText("\nkotlin_repo_url=$kotlinDevUrl")
32+
}
2933
return Runner(rootProjectDir, print)
3034
}
3135
}

integration/src/test/resources/templates/kotlin-multiplatform/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ kotlin {
4747
}
4848
}
4949

50+
repositories {
51+
def kotlinDevUrl = rootProject.properties["kotlin_repo_url"]
52+
if (kotlinDevUrl != null) {
53+
maven { url = kotlinDevUrl }
54+
}
55+
}
56+
5057
benchmark {
5158
targets {
5259
register("jvm")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
kotlin.js.compiler=ir
2+
org.gradle.jvmargs=-Xmx2g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

plugin/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
buildscript {
2+
ext.kotlinDevUrl = rootProject.properties["kotlin_repo_url"]
23
repositories {
34
maven { url 'https://maven.pkg.jetbrains.space/kotlin/p/kotlinx/maven' }
45
mavenCentral()
6+
if (kotlinDevUrl != null) {
7+
maven { url = kotlinDevUrl }
8+
}
59
}
610
dependencies {
711
classpath "kotlinx.team:kotlinx.team.infra:$infra_version"
@@ -30,9 +34,15 @@ infra {
3034
}
3135
}
3236

37+
logger.info("Using Kotlin $kotlin_version for project ${project.name}")
38+
3339
repositories {
3440
mavenCentral()
3541
gradlePluginPortal()
42+
43+
if (kotlinDevUrl != null) {
44+
maven { url = kotlinDevUrl }
45+
}
3646
}
3747

3848
pluginBundle {

settings.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
pluginManagement {
22
repositories {
33
gradlePluginPortal()
4+
if (settings.hasProperty("kotlin_repo_url") && settings.kotlin_repo_url != null) {
5+
maven { url = settings.kotlin_repo_url }
6+
}
47
}
58
}
69

0 commit comments

Comments
 (0)