From 6053c94c8ab2066a0290f483a4b549611ed9add5 Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Mon, 13 Nov 2023 14:45:06 +0000 Subject: [PATCH] [K/N][build] Fix KT-56495: improve version manifest merge Add missing input property to stdlib build task. This task should consider kotlin/build version change. Add a version check during the stdlib target task build. This check should be done here instead of the final merge. Fixes ^KT-56495 Merge-request: KT-MR-12906 Merged-by: Pavel Punegov --- kotlin-native/backend.native/tests/build.gradle | 2 ++ .../src/main/kotlin/org/jetbrains/kotlin/Utils.kt | 7 ++++++- .../kotlin/gradle/plugin/konan/tasks/KonanCompileTask.kt | 2 ++ kotlin-native/runtime/build.gradle.kts | 7 +++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 69d397c3765..570c69362e3 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -44,6 +44,8 @@ ext.testOutputRoot = rootProject.file("test.output").absolutePath ext.platformManager = project.project(":kotlin-native").platformManager ext.target = platformManager.targetManager(project.testTarget).target +ext.buildNumber = rootProject.property("kotlinVersion") + // Add executor to run tests depending on a target // NOTE: If this persists in a gradle daemon, environment update (e.g. an Xcode update) may lead to execution failures. project.extensions.executor = ExecutorServiceKt.create(project) diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/Utils.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/Utils.kt index eed47501c41..a935b12c900 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/Utils.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/Utils.kt @@ -28,6 +28,7 @@ import kotlin.collections.HashSet * Copy-pasted from [org.jetbrains.kotlin.library.KLIB_PROPERTY_NATIVE_TARGETS] */ private const val KLIB_PROPERTY_NATIVE_TARGETS = "native_targets" +private const val KLIB_PROPERTY_COMPILER_VERSION = "compiler_version" //region Project properties. @@ -346,7 +347,7 @@ fun Project.mergeManifestsByTargets(source: File, destination: File) { val mismatchedProperties = (sourceProperties.keys + destinationProperties.keys) .asSequence() .map { it.toString() } - .filter { it != KLIB_PROPERTY_NATIVE_TARGETS } + .filterNot { it == KLIB_PROPERTY_NATIVE_TARGETS || it == KLIB_PROPERTY_COMPILER_VERSION } .sorted() .mapNotNull { propertyKey: String -> val sourceProperty: String? = sourceProperties.getProperty(propertyKey) @@ -386,6 +387,10 @@ fun Project.mergeManifestsByTargets(source: File, destination: File) { destinationProperties[KLIB_PROPERTY_NATIVE_TARGETS] = mergedNativeTargets.joinToString(" ") + // Get KLIB_PROPERTY_COMPILER_VERSION source property and override the version + destinationProperties[KLIB_PROPERTY_COMPILER_VERSION] = sourceProperties.getProperty(KLIB_PROPERTY_COMPILER_VERSION) + + // Now save the properties to the destination file destinationFile.saveProperties(destinationProperties) } diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/tasks/KonanCompileTask.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/tasks/KonanCompileTask.kt index b1b632ee4ce..f22bf46afbb 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/tasks/KonanCompileTask.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/tasks/KonanCompileTask.kt @@ -79,6 +79,8 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec { val apiVersion : String? @Optional @Input get() = project.konanExtension.apiVersion + @Input var buildNumber = project.properties.get("kotlinVersion") ?: error("kotlinVersion property is not specified in the project") + /** * Is the two-stage compilation enabled. * diff --git a/kotlin-native/runtime/build.gradle.kts b/kotlin-native/runtime/build.gradle.kts index 572a52da2b8..f75f08a7098 100644 --- a/kotlin-native/runtime/build.gradle.kts +++ b/kotlin-native/runtime/build.gradle.kts @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.gradle.plugin.konan.tasks.KonanCacheTask import org.jetbrains.kotlin.konan.properties.loadProperties import org.jetbrains.kotlin.konan.properties.saveProperties import org.jetbrains.kotlin.konan.target.* +import org.jetbrains.kotlin.library.KLIB_PROPERTY_COMPILER_VERSION import org.jetbrains.kotlin.library.KLIB_PROPERTY_NATIVE_TARGETS import org.jetbrains.kotlin.konan.file.File as KFile import org.jetbrains.kotlin.konan.target.Architecture as TargetArchitecture @@ -18,6 +19,8 @@ val distDir: File by project val konanHome: String by extra(distDir.absolutePath) extra["org.jetbrains.kotlin.native.home"] = konanHome +val kotlinVersion: String by rootProject.extra + plugins { id("compile-to-bitcode") id("runtime-testing") @@ -600,6 +603,10 @@ targetList.forEach { targetName -> with(KFile(destinationDir.resolve("default/manifest").absolutePath)) { val props = loadProperties() props[KLIB_PROPERTY_NATIVE_TARGETS] = targetName + val version = props[KLIB_PROPERTY_COMPILER_VERSION] + check(version == kotlinVersion) { + "Manifest file ($this) processing: $version was found while $kotlinVersion was expected" + } saveProperties(props) } }