Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare atomicfu build scripts for inclusion into the main aggregate as a user project #265

Merged
merged 1 commit into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions atomicfu-gradle-plugin/build.gradle
Expand Up @@ -14,8 +14,8 @@ if (rootProject.ext.jvm_ir_enabled) {
// Gradle plugin must be compiled targeting the same Kotlin version as used by Gradle
kotlin.sourceSets.all {
languageSettings {
apiVersion = "1.4"
languageVersion = "1.4"
apiVersion = KotlinAggregateBuild.getOverriddenKotlinApiVersion(project) ?: "1.4"
languageVersion = KotlinAggregateBuild.getOverriddenKotlinLanguageVersion(project) ?: "1.4"
}
}

Expand Down
21 changes: 12 additions & 9 deletions atomicfu-maven-plugin/build.gradle
Expand Up @@ -23,6 +23,8 @@ def buildSnapshots = rootProject.properties['build_snapshot_train'] != null

evaluationDependsOn(':atomicfu-transformer')

def kotlinDevRepoUrl = KotlinAggregateBuild.getKotlinDevRepositoryUrl(project)

task generatePomFile(dependsOn: [compileKotlin, ':atomicfu-transformer:publishToMavenLocal']) {
def buildDir = project.buildDir // because Maven model also has "project"
outputs.file(pomFile)
Expand All @@ -43,11 +45,12 @@ task generatePomFile(dependsOn: [compileKotlin, ':atomicfu-transformer:publishTo
appendNode('project.build.sourceEncoding', 'UTF-8')
}
appendNode('repositories').with {
appendNode('repository').with {
appendNode('id', 'dev')
appendNode('url', 'https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev')
if (kotlinDevRepoUrl != null && !kotlinDevRepoUrl.isEmpty()) {
appendNode('repository').with {
appendNode('id', 'dev')
appendNode('url', kotlinDevRepoUrl)
}
}

if (buildSnapshots) {
appendNode('repository').with {
appendNode('id', 'kotlin-snapshots')
Expand Down Expand Up @@ -77,11 +80,11 @@ task generatePluginDescriptor(type: Exec, dependsOn: generatePomFile) {
if (mavenUserHome != null) args.add("-Dmaven.user.home=${new File(mavenUserHome).getAbsolutePath()}")
if (mavenRepoLocal != null) args.add("-Dmaven.repo.local=${new File(mavenRepoLocal).getAbsolutePath()}")
args.addAll([
'--settings', './settings.xml',
'--errors',
'--batch-mode',
'--file', pomFile.toString(),
'org.apache.maven.plugins:maven-plugin-plugin:3.5.1:descriptor'
'--settings', './settings.xml',
'--errors',
'--batch-mode',
'--file', pomFile.toString(),
'org.apache.maven.plugins:maven-plugin-plugin:3.5.1:descriptor'
])
commandLine args
doLast {
Expand Down
18 changes: 9 additions & 9 deletions build.gradle
Expand Up @@ -5,6 +5,8 @@
import org.jetbrains.kotlin.konan.target.HostManager

buildscript {


/*
* These property group is used to build kotlinx.atomicfu against Kotlin compiler snapshot.
* How does it work:
Expand All @@ -29,14 +31,13 @@ buildscript {
ext.jvm_ir_enabled = rootProject.properties['enable_jvm_ir'] != null
ext.native_targets_enabled = rootProject.properties['disable_native_targets'] == null


repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
// Future replacement for kotlin-dev, with cache redirector
maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
KotlinAggregateBuild.addDevRepositoryIfEnabled(delegate, project)
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Expand All @@ -54,12 +55,11 @@ allprojects {
}
}

println "Using Kotlin $kotlin_version for project $it"
logger.info("Using Kotlin compiler $kotlin_version for $it")

repositories {
mavenCentral()
// Future replacement for kotlin-dev, with cache redirector
maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
KotlinAggregateBuild.addDevRepositoryIfEnabled(delegate, project)
}

def deployVersion = properties['DeployVersion']
Expand All @@ -79,7 +79,7 @@ allprojects {
}
}

println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
logger.info("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
if (build_snapshot_train) {
afterEvaluate {
println "Manifest of kotlin-compiler-embeddable.jar for atomicfu"
Expand Down
67 changes: 67 additions & 0 deletions buildSrc/src/main/kotlin/KotlinAggregateBuild.kt
@@ -0,0 +1,67 @@
@file:JvmName("KotlinAggregateBuild")

import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.*
import java.net.*
import java.util.logging.Logger

/*
* Functions in this file are responsible for configuring atomicfu build against a custom dev version
* of Kotlin compiler.
* Such configuration is used in aggregate builds of Kotlin in order to check whether not-yet-released changes
* are compatible with our libraries (aka "integration testing that substitues lack of unit testing").
*/

private val LOGGER: Logger = Logger.getLogger("Kotlin settings logger")

/**
* Should be used for running against of non-released Kotlin compiler on a system test level.
*
* @return a Kotlin API version parametrized from command line nor gradle.properties, null otherwise
*/
fun getOverriddenKotlinApiVersion(project: Project): String? {
val apiVersion = project.rootProject.properties["kotlin_api_version"] as? String
if (apiVersion != null) {
LOGGER.info("""Configured Kotlin API version: '$apiVersion' for project $${project.name}""")
}
return apiVersion
}

/**
* Should be used for running against of non-released Kotlin compiler on a system test level
*
* @return a Kotlin Language version parametrized from command line nor gradle.properties, null otherwise
*/
fun getOverriddenKotlinLanguageVersion(project: Project): String? {
val languageVersion = project.rootProject.properties["kotlin_language_version"] as? String
if (languageVersion != null) {
LOGGER.info("""Configured Kotlin Language version: '$languageVersion' for project ${project.name}""")
}
return languageVersion
}

/**
* Should be used for running against of non-released Kotlin compiler on a system test level
* Kotlin compiler artifacts are expected to be downloaded from maven central by default.
* In case of compiling with not-published into the MC kotlin compiler artifacts, a kotlin_repo_url gradle parameter should be specified.
* To reproduce a build locally, a kotlin/dev repo should be passed
*
* @return an url for a kotlin compiler repository parametrized from command line nor gradle.properties, empty string otherwise
*/
fun getKotlinDevRepositoryUrl(project: Project): String? {
val url = project.rootProject.properties["kotlin_repo_url"] as? String
if (url != null) {
LOGGER.info("""Configured Kotlin Compiler repository url: '$url' for project ${project.name}""")
}
return url
}

/**
* Adds a kotlin-dev space repository with dev versions of Kotlin if Kotlin aggregate build is enabled
*/
fun addDevRepositoryIfEnabled(rh: RepositoryHandler, project: Project) {
val devRepoUrl = getKotlinDevRepositoryUrl(project) ?: return
rh.maven {
url = URI.create(devRepoUrl)
}
}
2 changes: 0 additions & 2 deletions buildSrc/src/main/kotlin/Publishing.kt
Expand Up @@ -45,12 +45,10 @@ fun MavenPom.configureMavenCentralMetadata(project: Project) {
}

fun mavenRepositoryUri(): URI {
// TODO -SNAPSHOT detection can be made here as well
val repositoryId: String? = System.getenv("libs.repository.id")
return if (repositoryId == null) {
// Using implicitly created staging, for MPP it's likely to be a mistake because
// publication on TeamCity will create 3 independent staging repositories
System.err.println("Warning: using an implicitly created staging for atomicfu")
URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
} else {
URI("https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repositoryId")
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Expand Up @@ -6,6 +6,7 @@ version=0.18.5-SNAPSHOT
group=org.jetbrains.kotlinx

kotlin_version=1.7.20

asm_version=9.3
slf4j_version=1.8.0-alpha2
junit_version=4.12
Expand Down
5 changes: 2 additions & 3 deletions gradle/compile-options.gradle
@@ -1,4 +1,3 @@

/*
* Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
Expand All @@ -19,8 +18,8 @@ ext.configureKotlin = { isMultiplatform ->

kotlin.sourceSets.all {
languageSettings {
apiVersion = "1.4"
languageVersion = "1.4"
apiVersion = KotlinAggregateBuild.getOverriddenKotlinApiVersion(project) ?: "1.4"
languageVersion = KotlinAggregateBuild.getOverriddenKotlinLanguageVersion(project) ?: "1.4"
}
}
}