Skip to content

Commit d2fdd97

Browse files
committed
fixes
1 parent 49c79ab commit d2fdd97

File tree

7 files changed

+73
-97
lines changed

7 files changed

+73
-97
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
org.gradle.jvmargs=-Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError -Xmx2g -XX:MaxMetaspaceSize=512m
1+
org.gradle.jvmargs=-Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError -Xmx4g -XX:MaxMetaspaceSize=1g
22

33
org.gradle.caching=true
44

modules/bcv-gradle-plugin-functional-tests/src/functionalTest/kotlin/kotlinx/validation/test/KlibVerificationTests.kt

Lines changed: 31 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import dev.adamko.kotlin.binary_compatibility_validator.test.utils.*
44
import dev.adamko.kotlin.binary_compatibility_validator.test.utils.api.*
55
import io.kotest.assertions.withClue
66
import io.kotest.inspectors.shouldForAll
7-
import io.kotest.matchers.comparables.shouldBeEqualComparingTo
7+
import io.kotest.matchers.file.shouldBeEmptyDirectory
88
import io.kotest.matchers.file.shouldExist
9-
import io.kotest.matchers.file.shouldNotExist
109
import io.kotest.matchers.shouldBe
1110
import io.kotest.matchers.string.shouldContain
12-
import java.io.File
13-
import java.nio.file.Files
1411
import kotlin.io.path.Path
1512
import kotlin.io.path.name
1613
import org.gradle.testkit.runner.BuildResult
@@ -143,7 +140,7 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
143140
jvmApiDump.shouldExist()
144141

145142
val expected = readResourceFile("/examples/classes/AnotherBuildConfig.dump")
146-
jvmApiDump.readText().invariantNewlines().shouldBeEqualComparingTo(expected)
143+
jvmApiDump.readText().invariantNewlines().shouldBe(expected.invariantNewlines())
147144
}
148145
}
149146

@@ -386,19 +383,13 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
386383
baseProjectSetting()
387384
addToSrcSet("/examples/classes/TopLevelDeclarations.kt")
388385
addToSrcSet("/examples/classes/AnotherBuildConfigLinuxArm64.kt", "linuxArm64Main")
389-
390386
disableKLibTargets("linuxArm64")
391-
392387
runner {
393-
// arguments.add("-P$BANNED_TARGETS_PROPERTY_NAME=linuxArm64")
394388
arguments.add(":apiDump")
395389
}
396390
}
397391
runner.build {
398-
checkKLibDump(
399-
"/examples/classes/TopLevelDeclarations.klib.with.linux.dump",
400-
dumpTask = ":apiDump"
401-
)
392+
checkKLibDump("/examples/classes/TopLevelDeclarations.klib.with.linux.dump")
402393
}
403394
}
404395

@@ -419,14 +410,11 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
419410

420411
runner {
421412
// arguments.add("-P$BANNED_TARGETS_PROPERTY_NAME=linux")
422-
arguments.add(":klibApiDump")
413+
arguments.add(":apiDump")
423414
}
424415
}
425416
runner.build {
426-
checkKLibDump(
427-
"/examples/classes/TopLevelDeclarations.klib.with.guessed.linux.dump",
428-
dumpTask = ":klibApiDump"
429-
)
417+
checkKLibDump("/examples/classes/TopLevelDeclarations.klib.with.guessed.linux.dump")
430418
}
431419
}
432420

@@ -446,7 +434,7 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
446434

447435
runner {
448436
// arguments.add("-P$BANNED_TARGETS_PROPERTY_NAME=linuxArm64")
449-
arguments.add(":klibApiDump")
437+
arguments.add(":apiDump")
450438
}
451439
}
452440

@@ -475,7 +463,7 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
475463
// "-P$BANNED_TARGETS_PROPERTY_NAME=linuxArm64,linuxX64,mingwX64," +
476464
// "androidNativeArm32,androidNativeArm64,androidNativeX64,androidNativeX86"
477465
// )
478-
arguments.add(":klibApiDump")
466+
arguments.add(":apiDump")
479467
}
480468
}
481469

@@ -507,7 +495,7 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
507495
// "-P$BANNED_TARGETS_PROPERTY_NAME=linuxArm64,linuxX64,mingwX64," +
508496
// "androidNativeArm32,androidNativeArm64,androidNativeX64,androidNativeX86"
509497
// )
510-
arguments.add(":klibApiCheck")
498+
arguments.add(":apiCheck")
511499
}
512500
}
513501

@@ -553,15 +541,12 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
553541
}
554542
addToSrcSet("/examples/classes/AnotherBuildConfig.kt")
555543
runner {
556-
arguments.add(":klibApiDump")
544+
arguments.add(":apiDump")
557545
}
558546
}
559547

560548
runner.build {
561-
checkKLibDump(
562-
"/examples/classes/AnotherBuildConfig.klib.custom.dump",
563-
dumpTask = ":klibApiDump"
564-
)
549+
checkKLibDump("/examples/classes/AnotherBuildConfig.klib.custom.dump")
565550
}
566551
}
567552

@@ -579,10 +564,7 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
579564
}
580565
}
581566
runner.build {
582-
checkKLibDump(
583-
"/examples/classes/AnotherBuildConfigLinux.klib.grouping.dump",
584-
dumpTask = ":apiDump"
585-
)
567+
checkKLibDump("/examples/classes/AnotherBuildConfigLinux.klib.grouping.dump")
586568
}
587569
}
588570

@@ -637,16 +619,9 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
637619
}
638620

639621
// Update the source file by adding a declaration
640-
val updatedSourceFile = File(
641-
this::class.java.getResource(
642-
"/examples/classes/AnotherBuildConfigModified.kt"
643-
)!!.toURI()
644-
)
645-
val existingSource = runner.projectDir.resolve(
646-
"src/commonMain/kotlin/AnotherBuildConfig.kt"
647-
)
648-
Files.write(existingSource.toPath(), updatedSourceFile.readBytes())
649-
622+
val updatedSourceFile = readResourceFile("/examples/classes/AnotherBuildConfigModified.kt")
623+
val existingSource = runner.projectDir.resolve("src/commonMain/kotlin/AnotherBuildConfig.kt")
624+
existingSource.writeText(updatedSourceFile)
650625

651626
runner.build {
652627
checkKLibDump("/examples/classes/AnotherBuildConfigModified.klib.dump")
@@ -666,20 +641,13 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
666641
runner.build {
667642
checkKLibDump("/examples/classes/AnotherBuildConfig.klib.dump")
668643
// Update the source file by adding a declaration
669-
val updatedSourceFile = File(
670-
this::class.java.getResource(
671-
"/examples/classes/AnotherBuildConfigLinuxArm64.kt"
672-
)!!.toURI()
673-
)
674-
val existingSource = runner.projectDir.resolve(
675-
"src/linuxArm64Main/kotlin/AnotherBuildConfigLinuxArm64.kt"
676-
)
644+
val updatedSourceFile = readResourceFile("/examples/classes/AnotherBuildConfigLinuxArm64.kt")
645+
val existingSource =
646+
runner.projectDir.resolve("src/linuxArm64Main/kotlin/AnotherBuildConfigLinuxArm64.kt")
677647
existingSource.parentFile.mkdirs()
678-
Files.write(existingSource.toPath(), updatedSourceFile.readBytes())
679-
648+
existingSource.writeText(updatedSourceFile)
680649

681650
runner.build {
682-
683651
checkKLibDump("/examples/classes/AnotherBuildConfigLinuxArm64Extra.klib.dump")
684652
}
685653
}
@@ -702,18 +670,12 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
702670
}
703671

704672
// Update the source file by adding a declaration
705-
val updatedSourceFile = File(
706-
this::class.java.getResource(
707-
"/examples/classes/AnotherBuildConfigModified.kt"
708-
)!!.toURI()
709-
)
710-
val existingSource = runner.projectDir.resolve(
711-
"src/commonMain/kotlin/AnotherBuildConfig.kt"
712-
)
713-
Files.write(existingSource.toPath(), updatedSourceFile.readBytes())
673+
val updatedSourceFile = readResourceFile("/examples/classes/AnotherBuildConfigModified.kt")
674+
val existingSource = runner.projectDir.resolve("src/commonMain/kotlin/AnotherBuildConfig.kt")
675+
existingSource.writeText(updatedSourceFile)
714676

715677
runner.buildAndFail {
716-
shouldHaveTaskWithOutcome(":klibApiCheck", FAILED)
678+
shouldHaveTaskWithOutcome(":apiCheck", FAILED)
717679
}
718680
}
719681

@@ -746,8 +708,8 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
746708
}
747709

748710
runner.build {
749-
shouldHaveTaskWithOutcome(":klibApiCheck", SKIPPED)
750-
rootProjectApiDump.parentFile.shouldNotExist()
711+
shouldHaveTaskWithOutcome(":apiDump", SUCCESS)
712+
rootProjectApiDump.parentFile.shouldBeEmptyDirectory()
751713
}
752714
}
753715

@@ -777,7 +739,7 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
777739
}
778740
}
779741
runner.build {
780-
shouldHaveRunTask(":apiCheck", SUCCESS)
742+
shouldHaveRunTask(":apiCheck", SKIPPED)
781743
}
782744
}
783745

@@ -819,10 +781,9 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
819781
private fun BuildResult.checkKLibDump(
820782
expectedDumpFileName: String,
821783
projectName: String = "testproject",
822-
dumpTask: String = ":apiDump",
823784
) {
824785
withClue(output) {
825-
shouldHaveRunTask(dumpTask, SUCCESS)
786+
shouldHaveRunTask(":apiDump", SUCCESS)
826787

827788
val generatedDump = rootProjectAbiDump(projectName)
828789

@@ -840,12 +801,13 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
840801
private fun BaseKotlinScope.disableKLibTargets(vararg targetNames: String) {
841802
buildGradleKts {
842803
val disabledTargets =
843-
targetNames.joinToString(separator = ", ", prefix = "setOf(", postfix = ")")
804+
targetNames.joinToString(", ") { "\"$it\"" }
844805
addText(
845806
"""
846-
|binaryCompatibilityValidator.targets.withType<BCVKLibTarget>()
847-
| .matching { it.targetName in $disabledTargets }
848-
| .configureEach { this.supportedByCurrentHost.set(false) }
807+
|binaryCompatibilityValidator.targets
808+
| .withType<dev.adamko.kotlin.binary_compatibility_validator.targets.BCVKLibTarget>()
809+
| .matching { it.targetName in setOf($disabledTargets) }
810+
| .configureEach { supportedByCurrentHost.set(false) }
849811
|
850812
""".trimMargin()
851813
)

modules/bcv-gradle-plugin-functional-tests/src/functionalTest/resources/examples/classes/HiddenDeclarations.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*
2-
* Copyright 2016-2023 JetBrains s.r.o.
3-
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4-
*/
5-
61
package examples.classes
72

83
import annotations.*

modules/bcv-gradle-plugin-functional-tests/src/functionalTest/resources/examples/classes/NonPublicMarkers.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/*
2-
* Copyright 2016-2023 JetBrains s.r.o.
3-
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4-
*/
5-
61
package annotations
72

83
@HiddenClass

modules/bcv-gradle-plugin/src/main/kotlin/tasks/BCVApiCheckTask.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import dev.adamko.kotlin.binary_compatibility_validator.internal.fullPath
99
import java.io.File
1010
import java.util.TreeMap
1111
import javax.inject.Inject
12+
import kotlin.io.path.listDirectoryEntries
1213
import org.gradle.api.file.DirectoryProperty
1314
import org.gradle.api.file.FileVisitDetails
1415
import org.gradle.api.file.RelativePath
@@ -52,6 +53,17 @@ constructor(
5253

5354
private val rootDir: File = project.rootProject.rootDir
5455

56+
init {
57+
super.onlyIf { task ->
58+
require(task is BCVApiCheckTask)
59+
task.apiBuildDir.orNull?.asFile
60+
?.takeIf(File::exists)
61+
?.toPath()
62+
?.listDirectoryEntries()
63+
?.isNotEmpty() == true
64+
}
65+
}
66+
5567
@TaskAction
5668
fun verify() {
5769
val projectApiDir = projectApiDir.orNull
@@ -156,8 +168,8 @@ constructor(
156168
/**
157169
* We use case-insensitive comparison to workaround issues with case-insensitive OSes and Gradle
158170
* behaving slightly different on different platforms. We neither know original sensitivity of
159-
* existing .api files, not build ones, because projectName that is part of the path can have any
160-
* sensitivity. To work around that, we replace paths we are looking for the same paths that
171+
* existing `.api` files, not build ones, because `projectName` that is part of the path can have
172+
* any sensitivity. To work around that, we replace paths we are looking for the same paths that
161173
* actually exist on the FS.
162174
*/
163175
private class RelativePaths(

modules/bcv-gradle-plugin/src/main/kotlin/tasks/BCVApiGenerateTask.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,17 @@ constructor(
8484

8585
val enabledTargets = targets.matching { it.enabled.getOrElse(true) }
8686

87-
logger.lifecycle("[$path] ${enabledTargets.size} enabledTargets : ${enabledTargets.joinToString { it.name }}")
88-
8987
generateJvmTargets(
9088
workQueue = workQueue,
9189
jvmTargets = enabledTargets.withType<BCVJvmTarget>(),
92-
enabledTargets = enabledTargets.size,
9390
outputApiBuildDir = outputApiBuildDir,
9491
)
9592

9693
// TODO log when klib file doesn't exist
9794
// TODO log warning when klibFile has >1 file
9895
val klibTargets = enabledTargets.withType<BCVKLibTarget>()
9996
.filter { it.klibFile.singleOrNull()?.exists() == true }
97+
.sortedBy { it.targetName }
10098

10199
generateKLibTargets(
102100
workQueue = workQueue,
@@ -124,13 +122,16 @@ constructor(
124122
workQueue: WorkQueue,
125123
outputApiBuildDir: Directory,
126124
jvmTargets: Collection<BCVJvmTarget>,
127-
enabledTargets: Int,
128125
) {
129-
if (jvmTargets.isEmpty()) return
126+
if (jvmTargets.isEmpty()) {
127+
logger.info("[$path] No enabled JVM targets")
128+
return
129+
}
130+
130131
logger.lifecycle("[$path] generating ${jvmTargets.size} JVM targets : ${jvmTargets.joinToString { it.name }}")
131132

132133
jvmTargets.forEach { target ->
133-
val outputDir = if (enabledTargets == 1) {
134+
val outputDir = if (jvmTargets.size == 1) {
134135
outputApiBuildDir
135136
} else {
136137
outputApiBuildDir.dir(target.platformType)
@@ -249,6 +250,7 @@ constructor(
249250

250251
this@worker.klib.set(target.klibFile.singleFile)
251252
this@worker.signatureVersion.set(target.signatureVersion)
253+
this@worker.strictValidation.set(target.strictValidation)
252254
// this@worker.supportedByCurrentHost.set(target.supportedByCurrentHost)
253255

254256
// this@worker.targets.addAll(klibTargets)

modules/bcv-gradle-plugin/src/main/kotlin/workers/KLibSignaturesWorker.kt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ abstract class KLibSignaturesWorker : WorkAction<KLibSignaturesWorker.Parameters
3232
val ignoredClasses: SetProperty<String>
3333

3434
val signatureVersion: Property<KLibSignatureVersion>
35-
36-
// val targets: ListProperty<BCVKLibTarget>
35+
val strictValidation: Property<Boolean>
3736

3837
/**
3938
* [Task path][org.gradle.api.Task.getPath] of the task that invoked this worker,
@@ -46,16 +45,19 @@ abstract class KLibSignaturesWorker : WorkAction<KLibSignaturesWorker.Parameters
4645
val outputFile = parameters.outputApiDir.asFile.get()
4746
.resolve("${parameters.targetName.get()}.klib.api")
4847

48+
val filters = KLibDumpFilters {
49+
ignoredClasses += parameters.ignoredClasses.get()
50+
ignoredPackages += parameters.ignoredPackages.get()
51+
nonPublicMarkers += parameters.ignoredMarkers.get()
52+
signatureVersion = parameters.signatureVersion.get().convert()
53+
}
54+
55+
logger.lifecycle("[${parameters.taskPath.get()}:KLibSignaturesWorker] ${filters.toPrettyString()}}")
56+
4957
val dump = KlibDump.fromKlib(
5058
klibFile = parameters.klib.get().asFile,
5159
configurableTargetName = parameters.targetName.get(),
52-
filters = KLibDumpFilters {
53-
ignoredClasses += parameters.ignoredClasses.get()
54-
ignoredPackages += parameters.ignoredPackages.get()
55-
nonPublicMarkers += parameters.ignoredMarkers.get()
56-
signatureVersion = parameters.signatureVersion.get().convert()
57-
logger.lifecycle("[${parameters.taskPath.get()}:KLibSignaturesWorker] signatureVersion:$signatureVersion")
58-
}
60+
filters = filters,
5961
)
6062

6163
dump.saveTo(outputFile)
@@ -73,5 +75,13 @@ abstract class KLibSignaturesWorker : WorkAction<KLibSignaturesWorker.Parameters
7375

7476
private fun KlibTarget(configName: String, targetName: String): KlibTarget =
7577
KlibTarget.parse("${configName}.${targetName}")
78+
79+
private fun KlibDumpFilters.toPrettyString(): String =
80+
buildList {
81+
add("ignoredPackages=$ignoredPackages")
82+
add("ignoredClasses=$ignoredClasses")
83+
add("nonPublicMarkers=$nonPublicMarkers")
84+
add("signatureVersion=$signatureVersion")
85+
}.joinToString(", ", prefix = "KLibDumpFilters(", postfix = ")")
7686
}
7787
}

0 commit comments

Comments
 (0)