Skip to content

Commit

Permalink
Merge pull request #148 from Kotlin/version-0.14.4
Browse files Browse the repository at this point in the history
Version 0.14.4
  • Loading branch information
qwwdfsad authored Aug 17, 2020
2 parents cffe6ee + 6f2a521 commit d40cac6
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 183 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log for kotlinx.atomicfu

# Version 0.14.4

* Fixed bug when Maven plugin wasn't published
* Migrate to new Kotlin HMPP metadata for multiplatform projects
* Update Kotlin to 1.4.0

# Version 0.14.3

* Update to Kotlin 1.3.71.
Expand Down
7 changes: 6 additions & 1 deletion atomicfu-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ dependencies {
evaluationDependsOn(':atomicfu')
def atomicfu = project(':atomicfu')
def atomicfuJvmJarTask = atomicfu.tasks.getByName(atomicfu.kotlin.targets.jvm.artifactsTaskName)
def atomicfuJsJarTask = atomicfu.tasks.getByName(atomicfu.kotlin.targets.js.artifactsTaskName)

def jsLegacy = atomicfu.kotlin.targets.hasProperty("jsLegacy")
? atomicfu.kotlin.targets.jsLegacy
: atomicfu.kotlin.targets.js
def atomicfuJsJarTask = atomicfu.tasks.getByName(jsLegacy.artifactsTaskName)

def atomicfuMetadataJarTask = atomicfu.tasks.getByName(atomicfu.kotlin.targets.metadata.artifactsTaskName)

// Write the plugin's classpath to a file to share with the tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ private fun Project.configureDependencies() {
)
dependencies.add(TEST_IMPLEMENTATION_CONFIGURATION, getAtomicfuDependencyNotation(Platform.JS, version))
}
withPluginWhenEvaluatedDependencies("kotlin-native") { version ->
dependencies.add(IMPLEMENTATION_CONFIGURATION, getAtomicfuDependencyNotation(Platform.NATIVE, version))
dependencies.add(TEST_IMPLEMENTATION_CONFIGURATION, getAtomicfuDependencyNotation(Platform.NATIVE, version))
}
withPluginWhenEvaluatedDependencies("kotlin-platform-common") { version ->
dependencies.add(COMPILE_ONLY_CONFIGURATION, getAtomicfuDependencyNotation(Platform.COMMON, version))
dependencies.add(TEST_IMPLEMENTATION_CONFIGURATION, getAtomicfuDependencyNotation(Platform.COMMON, version))
}
withPluginWhenEvaluatedDependencies("kotlin-multiplatform") { version ->
configureMultiplatformPluginDependencies(version)
}
Expand Down Expand Up @@ -96,10 +88,10 @@ private fun Project.configureTasks() {
}

private enum class Platform(val suffix: String) {
JVM(""),
JVM("-jvm"),
JS("-js"),
NATIVE("-native"),
COMMON("-common")
NATIVE(""),
MULTIPLATFORM("")
}

private enum class CompilationType { MAIN, TEST }
Expand All @@ -119,15 +111,8 @@ private fun String.sourceSetNameToType(): CompilationType? = when (this) {
private val Project.config: AtomicFUPluginExtension
get() = extensions.findByName(EXTENSION_NAME) as? AtomicFUPluginExtension ?: AtomicFUPluginExtension(null)

private fun getAtomicfuDependencyNotation(platform: Platform, version: String): String {
val suffix = when (platform) {
// in common source sets, use a dependency on the MPP root module:
Platform.COMMON -> atomicfuRootMppModulePlatform.suffix
else -> platform.suffix
}
return "org.jetbrains.kotlinx:atomicfu$suffix:$version"
}

private fun getAtomicfuDependencyNotation(platform: Platform, version: String): String =
"org.jetbrains.kotlinx:atomicfu${platform.suffix}:$version"

// Note "afterEvaluate" does nothing when the project is already in executed state, so we need
// a special check for this case
Expand Down Expand Up @@ -248,14 +233,29 @@ fun Project.sourceSetsByCompilation(): Map<KotlinSourceSet, List<KotlinCompilati
return sourceSetsByCompilation
}

private val atomicfuRootMppModulePlatform = Platform.NATIVE

fun Project.configureMultiplatformPluginDependencies(version: String) {
if (rootProject.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata").toString().toBoolean()) {
val configurationName = project.extensions.getByType(KotlinMultiplatformExtension::class.java).sourceSets
val mainConfigurationName = project.extensions.getByType(KotlinMultiplatformExtension::class.java).sourceSets
.getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME)
.compileOnlyConfigurationName
dependencies.add(configurationName, getAtomicfuDependencyNotation(atomicfuRootMppModulePlatform, version))
dependencies.add(mainConfigurationName, getAtomicfuDependencyNotation(Platform.MULTIPLATFORM, version))

val testConfigurationName = project.extensions.getByType(KotlinMultiplatformExtension::class.java).sourceSets
.getByName(KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME)
.implementationConfigurationName
dependencies.add(testConfigurationName, getAtomicfuDependencyNotation(Platform.MULTIPLATFORM, version))

// For each source set that is only used in Native compilations, add an implementation dependency so that it
// gets published and is properly consumed as a transitive dependency:
sourceSetsByCompilation().forEach { (sourceSet, compilations) ->
val isSharedNativeSourceSet = compilations.all {
it.platformType == KotlinPlatformType.common || it.platformType == KotlinPlatformType.native
}
if (isSharedNativeSourceSet) {
val configuration = sourceSet.implementationConfigurationName
dependencies.add(configuration, getAtomicfuDependencyNotation(Platform.MULTIPLATFORM, version))
}
}
} else {
sourceSetsByCompilation().forEach { (sourceSet, compilations) ->
val platformTypes = compilations.map { it.platformType }.toSet()
Expand All @@ -265,9 +265,9 @@ fun Project.configureMultiplatformPluginDependencies(version: String) {
val compilationType = compilationNames.single().compilationNameToType()
?: return@forEach // skip unknown compilations
val platform =
if (platformTypes.size > 1) Platform.COMMON else // mix of platform types -> "common"
if (platformTypes.size > 1) Platform.MULTIPLATFORM else // mix of platform types -> "common"
when (platformTypes.single()) {
KotlinPlatformType.common -> Platform.COMMON
KotlinPlatformType.common -> Platform.MULTIPLATFORM
KotlinPlatformType.jvm, KotlinPlatformType.androidJvm -> Platform.JVM
KotlinPlatformType.js -> Platform.JS
KotlinPlatformType.native -> Platform.NATIVE
Expand Down Expand Up @@ -401,12 +401,17 @@ class AtomicFUPluginExtension(pluginVersion: String?) {

@CacheableTask
open class AtomicFUTransformTask : ConventionTask() {
@PathSensitive(PathSensitivity.RELATIVE)
@InputFiles
lateinit var inputFiles: FileCollection

@OutputDirectory
lateinit var outputDir: File

@Classpath
@InputFiles
lateinit var classPath: FileCollection

@Input
var variant = "FU"
@Input
Expand All @@ -427,8 +432,10 @@ open class AtomicFUTransformTask : ConventionTask() {

@CacheableTask
open class AtomicFUTransformJsTask : ConventionTask() {
@PathSensitive(PathSensitivity.RELATIVE)
@InputFiles
lateinit var inputFiles: FileCollection

@OutputDirectory
lateinit var outputDir: File
@Input
Expand Down
74 changes: 38 additions & 36 deletions atomicfu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ kotlin {
addNative(delegate.fromPreset(preset, preset.name))
}

// JS -- always
js {
// TODO: Commented out because browser tests do not work on TeamCity
// browser()
nodejs()
}

targets {
// JVM & JS -- always
// JVM -- always
fromPreset(presets.jvm, 'jvm')
fromPreset(presets.js, 'js') {
// TODO: Commented out because browser tests do not work on TeamCity
// browser()
nodejs()
}

if (project.ext.ideaActive) {
addNative(fromPreset(project.ext.ideaPreset, 'native'))
Expand Down Expand Up @@ -113,25 +115,12 @@ if (!project.ext.ideaActive) {
nativeMain.dependsOn(nativeInterop)
}

afterEvaluate {
def nativeTarget = kotlin.targets.findByName("linuxX64")
def cinteropTask = tasks.named(kotlin.linuxX64().compilations["main"].cinterops[0].interopProcessingTaskName)
def cinteropKlib = cinteropTask.map { it.outputFile }
def fakeCinteropCompilation = kotlin.targets["metadata"].compilations[kotlin.sourceSets.nativeInterop.name]
def destination = fakeCinteropCompilation.compileKotlinTask.destinationDir

task copyCinteropKlib(type: Zip) {
from(zipTree(cinteropKlib).matching {
exclude("targets/**") // with Kotlin pre-1.4
exclude("default/targets/**") // with Kotlin 1.4
})
destinationDirectory.set(destination)
archiveFileName.set("${project.name}_${fakeCinteropCompilation.name}.klib")
dependsOn cinteropTask
}
apply from: "$rootDir/gradle/interop-as-source-set-klib.gradle"

fakeCinteropCompilation.output.classesDirs.from(files().builtBy(copyCinteropKlib))
}
registerInteropAsSourceSetOutput(
kotlin.linuxX64().compilations["main"].cinterops["interop"],
kotlin.sourceSets["nativeInterop"]
)
}

configurations {
Expand All @@ -148,15 +137,19 @@ dependencies {

// ==== CONFIGURE JS =====

tasks.withType(compileKotlinJs.getClass()) {
def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy")
? compileKotlinJsLegacy
: compileKotlinJs

tasks.withType(compileJsLegacy.getClass()) {
kotlinOptions {
moduleKind = "umd"
sourceMap = true
metaInfo = true
}
}

compileKotlinJs {
compileJsLegacy.configure {
kotlinOptions {
// NOTE: Module base-name must be equal to the package name declared in package.json
def baseName = "kotlinx-atomicfu"
Expand All @@ -165,7 +158,6 @@ compileKotlinJs {
}

apply from: file("$rootProject.projectDir/gradle/node-js.gradle")
apply from: file("$rootProject.projectDir/gradle/test-mocha-js.gradle")
apply from: file("$rootProject.projectDir/gradle/publish-npm-js.gradle")

// Workaround the problem with Node downloading
Expand All @@ -177,26 +169,30 @@ repositories.whenObjectAdded {
}
}

def transformedJsFile = compileTestKotlinJs.kotlinOptions.outputFile
compileTestKotlinJs {
def compileTestJsLegacy = tasks.hasProperty("compileTestKotlinJsLegacy")
? compileTestKotlinJsLegacy
: compileTestKotlinJs

def transformedJsFile = compileTestJsLegacy.kotlinOptions.outputFile
compileTestJsLegacy.configure {
kotlinOptions {
// NOTE: Module base-name must be equal to the package name declared in package.json
def baseName = "kotlinx-atomicfu"
outputFile = new File(outputFile.parent, baseName + ".js")
}
}
def originalJsFile = compileTestKotlinJs.kotlinOptions.outputFile
def originalJsFile = compileTestJsLegacy.kotlinOptions.outputFile

task transformJS(type: JavaExec, dependsOn: [compileTestKotlinJs]) {
task transformJS(type: JavaExec, dependsOn: [compileTestJsLegacy]) {
main = "kotlinx.atomicfu.transformer.AtomicFUTransformerJSKt"
args = [originalJsFile, transformedJsFile]
classpath = configurations.transformer
inputs.file(originalJsFile)
outputs.file(transformedJsFile)
}

if (project.tasks.findByName('legacyjsNodeTest')) {
legacyjsNodeTest.dependsOn transformJS
if (project.tasks.findByName('jsLegacyNodeTest')) {
jsLegacyNodeTest.dependsOn transformJS
} else {
jsNodeTest.dependsOn transformJS
}
Expand Down Expand Up @@ -301,9 +297,15 @@ jvmTest.dependsOn jvmTestAll

afterEvaluate {
publishing.publications {
jvm.artifactId = 'atomicfu'
js.artifactId = 'atomicfu-js'
metadata.artifactId = 'atomicfu-common'
kotlinMultiplatform.artifactId = 'atomicfu-native'

kotlinMultiplatform {
apply from: "$rootDir/gradle/publish-mpp-root-module-in-platform.gradle"
publishPlatformArtifactsInRootModule(jvm)
}
}
}

tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach {
dependsOn(tasks["generatePomFileForJvmPublication"])
}
10 changes: 7 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
#

version=0.14.3-SNAPSHOT
version=0.14.4-SNAPSHOT
group=org.jetbrains.kotlinx

kotlin_version=1.3.71
kotlin_version=1.4.0
asm_version=7.2
slf4j_version=1.8.0-alpha2
junit_version=4.12
Expand All @@ -26,4 +26,8 @@ kotlin.native.ignoreDisabledTargets=true
kotlin.js.compiler=both

kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.mpp.enableCompatibilityMetadataVariant=true
kotlin.mpp.enableCompatibilityMetadataVariant=true

# Workaround for Bintray treating .sha512 files as artifacts
# https://github.com/gradle/gradle/issues/11412
systemProp.org.gradle.internal.publish.checksums.insecure=true
55 changes: 55 additions & 0 deletions gradle/interop-as-source-set-klib.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

project.ext.registerInteropAsSourceSetOutput = { interop, sourceSet ->
afterEvaluate {
def cinteropTask = tasks.named(interop.interopProcessingTaskName)
def cinteropKlib = cinteropTask.map { it.outputFile }
def fakeCinteropCompilation = kotlin.targets["metadata"].compilations[sourceSet.name]
def destination = fakeCinteropCompilation.compileKotlinTask.destinationDir

def tempDir = "$buildDir/tmp/${sourceSet.name}UnpackedInteropKlib"

def prepareKlibTaskProvider = tasks.register("prepare${sourceSet.name.capitalize()}InteropKlib", Sync) {
from(files(zipTree(cinteropKlib).matching {
exclude("targets/**", "default/targets/**")
}).builtBy(cinteropTask))

into(tempDir)

doLast {
def manifest140 = file("$tempDir/default/manifest")
def manifest1371 = file("$tempDir/manifest")
def manifest = manifest140.exists() ? manifest140 : manifest1371

def lines = manifest.readLines()
def modifiedLines = lines.collect { line ->
line.startsWith("depends=") ? "depends=stdlib ${manifest == manifest140 ? 'org.jetbrains.kotlin.native.platform.posix' : 'posix'}" :
line.startsWith("native_targets=") ? "native_targets=" :
line
}
manifest.text = modifiedLines.join("\n")
}
}

def copyCinteropTaskProvider = tasks.register("copy${sourceSet.name.capitalize()}CinteropKlib", Zip) {
from(fileTree(tempDir).builtBy(prepareKlibTaskProvider))
destinationDirectory.set(destination)
archiveFileName.set("${project.name}_${fakeCinteropCompilation.name}.klib")
dependsOn cinteropTask
}

fakeCinteropCompilation.output.classesDirs.from(files().builtBy(copyCinteropTaskProvider))

kotlin.sourceSets.matching {
def visited = new HashSet()
def visit
visit = { s -> if (visited.add(s)) s.dependsOn.each { visit(it) } }
visit(it)
sourceSet in visited
}.all {
project.dependencies.add(implementationMetadataConfigurationName, files(cinteropKlib))
}
}
}
Loading

0 comments on commit d40cac6

Please sign in to comment.