From 9f9b4d1981f733e27521bac9f60284b0b62306c0 Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Wed, 15 Nov 2023 14:54:04 +0000 Subject: [PATCH] [K/N][publish] Publish kotlin-native-compiler-embeddable.jar Add an ability to publish kotlin-native-compiler-embeddable.jar and sources to maven. Adds necessary for that sourcesJar and javadocJar tasks. Note that Native distribution uses this jar without a version postfix. Also cleaned up the obsolete backend.native publication and renamed project to match its name. Merge-request: KT-MR-12974 Merged-by: Pavel Punegov --- kotlin-native/backend.native/build.gradle | 19 +---- kotlin-native/build.gradle | 13 ++- .../build.gradle.kts | 83 ++++++++++++------- .../testData/projects/smoke/Smoke.kt | 0 .../CompilerEmbeddableSmokeTests.kt | 0 .../embeddable/EmbeddableContentsTest.kt | 20 +++++ .../src/main/kotlin/nativeTest.kt | 2 +- settings.gradle | 3 +- 8 files changed, 87 insertions(+), 53 deletions(-) rename kotlin-native/prepare/{kotlin-native-embeddable-compiler => kotlin-native-compiler-embeddable}/build.gradle.kts (58%) rename kotlin-native/prepare/{kotlin-native-embeddable-compiler => kotlin-native-compiler-embeddable}/testData/projects/smoke/Smoke.kt (100%) rename kotlin-native/prepare/{kotlin-native-embeddable-compiler => kotlin-native-compiler-embeddable}/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/CompilerEmbeddableSmokeTests.kt (100%) rename kotlin-native/prepare/{kotlin-native-embeddable-compiler => kotlin-native-compiler-embeddable}/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/EmbeddableContentsTest.kt (83%) diff --git a/kotlin-native/backend.native/build.gradle b/kotlin-native/backend.native/build.gradle index d9134a33041..727629f2c08 100644 --- a/kotlin-native/backend.native/build.gradle +++ b/kotlin-native/backend.native/build.gradle @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.tools.NativePluginKt buildscript { apply from: "../../kotlin-native/gradle/kotlinGradlePlugin.gradle" - apply plugin: 'project-report' } apply plugin: 'java' @@ -238,23 +237,9 @@ tasks.register("debugCompiler", JavaExec) { args = findProperty("konan.debug.args").toString().tokenize() ?: [] } -publishing { - repositories { - maven { url = "$buildDir/repo" } - } - - publications { - maven(MavenPublication) { - groupId = 'org.jetbrains.kotlin' - artifactId = 'backend.native' - version = kotlinVersion - - from components.java - } - } -} - RepoArtifacts.sourcesJar(project) { it.from(sourceSets["cli_bc"].allSource) it.from(sourceSets["compiler"].allSource) } + +RepoArtifacts.javadocJar(project) diff --git a/kotlin-native/build.gradle b/kotlin-native/build.gradle index 948280cc8d3..2b5fafad4fd 100644 --- a/kotlin-native/build.gradle +++ b/kotlin-native/build.gradle @@ -149,6 +149,11 @@ configurations { attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, CppUsage.LLVM_BITCODE)) } } + + embeddableJar { + canBeConsumed = false + canBeResolved = true + } } apply plugin: CompilationDatabasePlugin @@ -170,6 +175,7 @@ dependencies { compilationDatabase project(":kotlin-native:common") compilationDatabase project(":kotlin-native:runtime") runtimeBitcode project(":kotlin-native:runtime") + embeddableJar project(path: ':kotlin-native:prepare:kotlin-native-compiler-embeddable', configuration: 'runtimeElements') } apply plugin: GitClangFormatPlugin @@ -246,7 +252,7 @@ tasks.register("distCompiler", Copy) { enabled = false } else { dependsOn ':kotlin-native:shadowJar' - dependsOn ":kotlin-native-compiler-embeddable:kotlin-native-compiler-embeddable" + dependsOn configurations.embeddableJar } destinationDir distDir @@ -259,7 +265,10 @@ tasks.register("distCompiler", Copy) { into('konan/lib') } - from(project(":kotlin-native-compiler-embeddable").file("build/libs")) { + from(configurations.embeddableJar) { + rename { + "kotlin-native-compiler-embeddable.jar" + } into("konan/lib") } diff --git a/kotlin-native/prepare/kotlin-native-embeddable-compiler/build.gradle.kts b/kotlin-native/prepare/kotlin-native-compiler-embeddable/build.gradle.kts similarity index 58% rename from kotlin-native/prepare/kotlin-native-embeddable-compiler/build.gradle.kts rename to kotlin-native/prepare/kotlin-native-compiler-embeddable/build.gradle.kts index 27a9e5773e9..597940a8b1d 100644 --- a/kotlin-native/prepare/kotlin-native-embeddable-compiler/build.gradle.kts +++ b/kotlin-native/prepare/kotlin-native-compiler-embeddable/build.gradle.kts @@ -1,3 +1,4 @@ +import org.gradle.kotlin.dsl.support.serviceOf import org.jetbrains.kotlin.konan.target.HostManager import org.jetbrains.kotlin.kotlinNativeDist @@ -5,38 +6,37 @@ plugins { kotlin("jvm") } -val testCompilationClasspath by configurations.creating -val testCompilerClasspath by configurations.creating { - isCanBeConsumed = false - extendsFrom(configurations["runtimeElements"]) - attributes { - attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) - attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY)) - } -} +description = "Embeddable JAR of Kotlin/Native compiler" +group = "org.jetbrains.kotlin" repositories { mavenCentral() } -val kotlinNativeEmbedded by configurations.creating -val testPlugin by configurations.creating -val testPluginRuntime by configurations.creating +val kotlinNativeEmbedded by configurations.creating { + isCanBeConsumed = false + isCanBeResolved = true +} -fun DependencyHandlerScope.testPluginRuntime(any: Any) { - val notation = any as? String ?: return add(testPluginRuntime.name, any) {} - val (group, artifact, version) = notation.split(":") - val platformName = HostManager.host.name - val gradlePlatformName = platformName.replace("_", "") - return add(testPluginRuntime.name, "$group:$artifact-$gradlePlatformName:$version") { - isTransitive = false - attributes { - attribute(Attribute.of("artifactType", String::class.java), "org.jetbrains.kotlin.klib") - attribute(Attribute.of("org.gradle.status", String::class.java), "release") - attribute(Attribute.of("org.jetbrains.kotlin.native.target", String::class.java), platformName) - attribute(Attribute.of("org.jetbrains.kotlin.platform.type", String::class.java), "native") - attribute(Usage.USAGE_ATTRIBUTE, objects.named("kotlin-api")) - } +val kotlinNativeSources by configurations.creating { + isVisible = false + isCanBeConsumed = false + isCanBeResolved = true + + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType.SOURCES)) + } +} + +val kotlinNativeJavadoc by configurations.creating { + isVisible = false + isCanBeConsumed = false + isCanBeResolved = true + + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType.JAVADOC)) } } @@ -51,16 +51,16 @@ dependencies { kotlinNativeEmbedded(project(":kotlin-native:klib")) kotlinNativeEmbedded(project(":kotlin-native:endorsedLibraries:kotlinx.cli", "jvmRuntimeElements")) kotlinNativeEmbedded(project(":kotlin-compiler")) { isTransitive = false } + + kotlinNativeSources(project(":kotlin-native:backend.native")) + kotlinNativeJavadoc(project(":kotlin-native:backend.native")) + testImplementation(libs.junit4) testImplementation(project(":kotlin-test:kotlin-test-junit")) } val compiler = embeddableCompiler("kotlin-native-compiler-embeddable") { from(kotlinNativeEmbedded) - /** - * this jar distributed through kotlin-native distribution, but not with maven. - */ - archiveVersion.set("") mergeServiceFiles() } @@ -69,9 +69,30 @@ val runtimeJar = runtimeJar(compiler) { mergeServiceFiles() } +val archiveZipper = serviceOf()::zipTree -kotlin.sourceSets["test"].kotlin.srcDir("tests/kotlin") +val sourcesJar = sourcesJar { + dependsOn(kotlinNativeSources) + from { kotlinNativeSources.map { archiveZipper(it) } } +} +val javadocJar = javadocJar { + dependsOn(kotlinNativeJavadoc) + from { kotlinNativeJavadoc.map { archiveZipper(it) } } +} + +publish { + setArtifacts(listOf(runtimeJar, sourcesJar, javadocJar)) +} + +sourceSets { + "main" {} + "test" { + kotlin { + srcDir("tests/kotlin") + } + } +} projectTest { /** diff --git a/kotlin-native/prepare/kotlin-native-embeddable-compiler/testData/projects/smoke/Smoke.kt b/kotlin-native/prepare/kotlin-native-compiler-embeddable/testData/projects/smoke/Smoke.kt similarity index 100% rename from kotlin-native/prepare/kotlin-native-embeddable-compiler/testData/projects/smoke/Smoke.kt rename to kotlin-native/prepare/kotlin-native-compiler-embeddable/testData/projects/smoke/Smoke.kt diff --git a/kotlin-native/prepare/kotlin-native-embeddable-compiler/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/CompilerEmbeddableSmokeTests.kt b/kotlin-native/prepare/kotlin-native-compiler-embeddable/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/CompilerEmbeddableSmokeTests.kt similarity index 100% rename from kotlin-native/prepare/kotlin-native-embeddable-compiler/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/CompilerEmbeddableSmokeTests.kt rename to kotlin-native/prepare/kotlin-native-compiler-embeddable/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/CompilerEmbeddableSmokeTests.kt diff --git a/kotlin-native/prepare/kotlin-native-embeddable-compiler/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/EmbeddableContentsTest.kt b/kotlin-native/prepare/kotlin-native-compiler-embeddable/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/EmbeddableContentsTest.kt similarity index 83% rename from kotlin-native/prepare/kotlin-native-embeddable-compiler/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/EmbeddableContentsTest.kt rename to kotlin-native/prepare/kotlin-native-compiler-embeddable/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/EmbeddableContentsTest.kt index 567df8ca08b..b6fb26c5322 100644 --- a/kotlin-native/prepare/kotlin-native-embeddable-compiler/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/EmbeddableContentsTest.kt +++ b/kotlin-native/prepare/kotlin-native-compiler-embeddable/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/EmbeddableContentsTest.kt @@ -70,6 +70,15 @@ class EmbeddableContentsTest { } } + @Test + fun `test jars have no jna`() { + konanHomeJars.filterNot { + it.name.startsWith("trove") + }.forEach { + it.checkJarDoesntContain("com/sun/jna") + } + } + private fun File.checkJarContains(string: String) { JarFile(this).use { jar -> assert(jar.entries() @@ -80,4 +89,15 @@ class EmbeddableContentsTest { } } } + + private fun File.checkJarDoesntContain(string: String) { + JarFile(this).use { jar -> + assert(jar.entries() + .asSequence() + .none { it.name.contains(string) } + ) { + "Jar file ${jar.name} contains element: $string" + } + } + } } \ No newline at end of file diff --git a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/nativeTest.kt b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/nativeTest.kt index 379b6e2d508..a74a8406e21 100644 --- a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/nativeTest.kt +++ b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/nativeTest.kt @@ -147,7 +147,7 @@ fun Project.nativeTest( val kotlinNativeCompilerEmbeddable = if (customNativeHome == null) configurations.detachedConfiguration( - dependencies.project(":kotlin-native-compiler-embeddable"), + dependencies.project(":kotlin-native:prepare:kotlin-native-compiler-embeddable"), dependencies.module(commonDependency("org.jetbrains.intellij.deps:trove4j")) ).also { dependsOn(it) } else diff --git a/settings.gradle b/settings.gradle index 9aaf560665a..5a97fab3973 100644 --- a/settings.gradle +++ b/settings.gradle @@ -850,6 +850,5 @@ if (buildProperties.isKotlinNativeEnabled) { include ':kotlin-native:platformLibs' include ':kotlin-native:libclangext' include ':kotlin-native:backend.native:tests' - include ":kotlin-native-compiler-embeddable" - project(":kotlin-native-compiler-embeddable").projectDir = "$rootDir/kotlin-native/prepare/kotlin-native-embeddable-compiler" as File + include ":kotlin-native:prepare:kotlin-native-compiler-embeddable" }