[Gradle][MPP] Don't save library dependency versions in KLIB manifest
^KT-62515
This commit is contained in:
committed by
Space Team
parent
e64068cf82
commit
bc8841c6fe
+98
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.mpp
|
||||||
|
|
||||||
|
import org.gradle.util.GradleVersion
|
||||||
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
|
import org.jetbrains.kotlin.konan.file.file
|
||||||
|
import org.jetbrains.kotlin.konan.file.withZipFileSystem
|
||||||
|
import org.jetbrains.kotlin.konan.properties.loadProperties
|
||||||
|
import org.jetbrains.kotlin.library.KLIB_PROPERTY_DEPENDENCY_VERSION
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import org.junit.jupiter.api.io.TempDir
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
import org.jetbrains.kotlin.konan.file.File as KFile
|
||||||
|
|
||||||
|
@NativeGradlePluginTests
|
||||||
|
@DisplayName("Tests for KLIB resolver inside the Kotlin compiler")
|
||||||
|
@GradleTestVersions(maxVersion = TestVersions.Gradle.G_8_2)
|
||||||
|
class KlibResolverInsideCompilerIT : KGPBaseTest() {
|
||||||
|
@DisplayName("Test resolver with C-interop KLIBs (KT-62515)")
|
||||||
|
@GradleTest
|
||||||
|
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_0, maxVersion = TestVersions.Gradle.G_8_2)
|
||||||
|
fun testResolverWithCInteropKlibs(gradleVersion: GradleVersion, @TempDir tempDir: Path) {
|
||||||
|
buildProjects(
|
||||||
|
baseDir = "mpp-klib-resolver-inside-compiler/with-cinterop",
|
||||||
|
tempDir, gradleVersion
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("Test resolver without C-interop KLIBs (KT-62515)")
|
||||||
|
@GradleTest
|
||||||
|
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_0, maxVersion = TestVersions.Gradle.G_8_2)
|
||||||
|
fun testResolverWithoutCInteropKlibs(gradleVersion: GradleVersion, @TempDir tempDir: Path) {
|
||||||
|
buildProjects(
|
||||||
|
baseDir = "mpp-klib-resolver-inside-compiler/without-cinterop",
|
||||||
|
tempDir, gradleVersion
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createLocalRepo(tempDir: Path): Path {
|
||||||
|
val localRepo = tempDir.resolve("local-repo").toAbsolutePath()
|
||||||
|
Files.createDirectories(localRepo)
|
||||||
|
return localRepo
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildProject(
|
||||||
|
baseDir: String,
|
||||||
|
projectName: String,
|
||||||
|
gradleVersion: GradleVersion,
|
||||||
|
localRepoDir: Path,
|
||||||
|
buildTask: String = "publish",
|
||||||
|
) {
|
||||||
|
project("$baseDir/$projectName", gradleVersion, localRepoDir = localRepoDir) {
|
||||||
|
build(buildTask)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildProjects(baseDir: String, tempDir: Path, gradleVersion: GradleVersion) {
|
||||||
|
val localRepoDir = createLocalRepo(tempDir)
|
||||||
|
|
||||||
|
buildProject(baseDir, "liba-v1", gradleVersion, localRepoDir)
|
||||||
|
buildProject(baseDir, "liba-v2", gradleVersion, localRepoDir)
|
||||||
|
buildProject(baseDir, "libb", gradleVersion, localRepoDir)
|
||||||
|
buildProject(baseDir, "libc", gradleVersion, localRepoDir)
|
||||||
|
|
||||||
|
// Make sure there are no `dependency_version_<name>=` properties with non-`unspecified` values in the manifest file:
|
||||||
|
localRepoDir.toFile().walkTopDown().forEach { file ->
|
||||||
|
if (file.isFile && file.extension == "klib") {
|
||||||
|
val specifiedDependencyVersions: Map<String, String> = KFile(file.absolutePath).withZipFileSystem {
|
||||||
|
it.file("default/manifest")
|
||||||
|
.loadProperties()
|
||||||
|
.entries
|
||||||
|
.mapNotNull { (key, value) ->
|
||||||
|
val keyStr = key.toString()
|
||||||
|
if (!keyStr.startsWith(KLIB_PROPERTY_DEPENDENCY_VERSION)) return@mapNotNull null
|
||||||
|
|
||||||
|
val valueStr = value.toString()
|
||||||
|
if (valueStr == "unspecified") return@mapNotNull null
|
||||||
|
|
||||||
|
keyStr to valueStr
|
||||||
|
}.toMap()
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
specifiedDependencyVersions.isEmpty(),
|
||||||
|
"There are specific library versions in the manifest of the library $file:\n${specifiedDependencyVersions.entries.sortedBy { it.key }}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buildProject(baseDir, "app", gradleVersion, localRepoDir, buildTask = "assemble")
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64 {
|
||||||
|
binaries.executable()
|
||||||
|
}
|
||||||
|
|
||||||
|
linuxArm64 {
|
||||||
|
binaries.executable()
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets.commonMain.dependencies {
|
||||||
|
implementation("org.sample.kt-62515:libb:1.0")
|
||||||
|
implementation("org.sample.kt-62515:libc:1.0")
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = "app"
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
fun main() {
|
||||||
|
a()
|
||||||
|
b()
|
||||||
|
c()
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "org.sample.kt-62515"
|
||||||
|
version = 1.0
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64 {
|
||||||
|
compilations.getByName("main") {
|
||||||
|
cinterops {
|
||||||
|
val liba by creating
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
linuxArm64 {
|
||||||
|
compilations.getByName("main") {
|
||||||
|
cinterops {
|
||||||
|
val liba by creating
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = "liba"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
fun a() {
|
||||||
|
println("a:1.0")
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package = liba
|
||||||
|
---
|
||||||
|
static int _a() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "org.sample.kt-62515"
|
||||||
|
version = 2.0
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64 {
|
||||||
|
compilations.getByName("main") {
|
||||||
|
cinterops {
|
||||||
|
val liba by creating
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
linuxArm64 {
|
||||||
|
compilations.getByName("main") {
|
||||||
|
cinterops {
|
||||||
|
val liba by creating
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = "liba"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
fun a() {
|
||||||
|
println("a:2.0")
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package = liba
|
||||||
|
---
|
||||||
|
static int _a() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "org.sample.kt-62515"
|
||||||
|
version = 1.0
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64()
|
||||||
|
linuxArm64()
|
||||||
|
|
||||||
|
sourceSets.commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation("org.sample.kt-62515:liba:1.0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = "libb"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
fun b() {
|
||||||
|
println("b")
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "org.sample.kt-62515"
|
||||||
|
version = 1.0
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64()
|
||||||
|
linuxArm64()
|
||||||
|
|
||||||
|
sourceSets.commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation("org.sample.kt-62515:liba:2.0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = "libc"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
fun c() {
|
||||||
|
println("c")
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64 {
|
||||||
|
binaries.executable()
|
||||||
|
}
|
||||||
|
|
||||||
|
linuxArm64 {
|
||||||
|
binaries.executable()
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets.commonMain.dependencies {
|
||||||
|
implementation("org.sample.kt-62515:libb:1.0")
|
||||||
|
implementation("org.sample.kt-62515:libc:1.0")
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = "app"
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
fun main() {
|
||||||
|
a()
|
||||||
|
b()
|
||||||
|
c()
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "org.sample.kt-62515"
|
||||||
|
version = 1.0
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64()
|
||||||
|
linuxArm64()
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = "liba"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
fun a() {
|
||||||
|
println("a:1.0")
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "org.sample.kt-62515"
|
||||||
|
version = 2.0
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64()
|
||||||
|
linuxArm64()
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = "liba"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
fun a() {
|
||||||
|
println("a:2.0")
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "org.sample.kt-62515"
|
||||||
|
version = 1.0
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64()
|
||||||
|
linuxArm64()
|
||||||
|
|
||||||
|
sourceSets.commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation("org.sample.kt-62515:liba:1.0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = "libb"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
fun b() {
|
||||||
|
println("b")
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "org.sample.kt-62515"
|
||||||
|
version = 1.0
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("<localRepo>") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64()
|
||||||
|
linuxArm64()
|
||||||
|
|
||||||
|
sourceSets.commonMain {
|
||||||
|
dependencies {
|
||||||
|
implementation("org.sample.kt-62515:liba:2.0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = "libc"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
fun c() {
|
||||||
|
println("c")
|
||||||
|
}
|
||||||
+3
-1
@@ -1168,7 +1168,9 @@ abstract class CInteropProcess @Inject internal constructor(params: Params) :
|
|||||||
addArgs("-headerFilterAdditionalSearchPrefix", headerFilterDirs.map { it.absolutePath })
|
addArgs("-headerFilterAdditionalSearchPrefix", headerFilterDirs.map { it.absolutePath })
|
||||||
addArg("-Xmodule-name", moduleName)
|
addArg("-Xmodule-name", moduleName)
|
||||||
|
|
||||||
addArg("-libraryVersion", libraryVersion)
|
// TODO: Uncomment when KT-61096 is implemented.
|
||||||
|
// Don't pass library version to C-interop tool. This leads to issues like this: KT-62515
|
||||||
|
//addArg("-libraryVersion", libraryVersion)
|
||||||
|
|
||||||
addAll(extraOpts)
|
addAll(extraOpts)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user