Skip to content

Commit

Permalink
Fix delimiter used to pass changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
ting-yuan committed Feb 26, 2021
1 parent 1d51ace commit 791fc87
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class KotlinSymbolProcessingCommandLineProcessor : CommandLineProcessor {
val (k, v) = value.split('=', ignoreCase = false, limit = 2)
processingOptions.put(k, v)
}
KspCliOption.KNOWN_MODIFIED_OPTION -> knownModified.addAll(value.split('=').map { File(it) } )
KspCliOption.KNOWN_REMOVED_OPTION -> knownRemoved.addAll(value.split('=').map { File(it) } )
KspCliOption.KNOWN_MODIFIED_OPTION -> knownModified.addAll(value.split(File.pathSeparator).map { File(it) } )
KspCliOption.KNOWN_REMOVED_OPTION -> knownRemoved.addAll(value.split(File.pathSeparator).map { File(it) } )
KspCliOption.INCREMENTAL_OPTION -> incremental = value.toBoolean()
KspCliOption.INCREMENTAL_LOG_OPTION -> incrementalLog = value.toBoolean()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ abstract class AbstractKotlinKSPTest : KotlinBaseTest<AbstractKotlinKSPTest.KspT
// need to compile java sources as well
val javaOutDir = module.rootDir.resolve("javaOut").apply { mkdirs() }
val classpath = (dependencies + KotlinTestUtils.getAnnotationsJar() + module.outDir)
.joinToString(":") { it.absolutePath }
.joinToString(File.pathSeparator) { it.absolutePath }
val options = listOf(
"-classpath", classpath,
"-d", javaOutDir.absolutePath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ fun K2JVMCompilerArguments.addPluginOptions(options: List<SubpluginOption>) {
fun K2JVMCompilerArguments.addChangedFiles(changedFiles: ChangedFiles) {
if (changedFiles is ChangedFiles.Known) {
val options = mutableListOf<SubpluginOption>()
changedFiles.modified.ifNotEmpty { options += SubpluginOption("knownModified", map { it.path }.joinToString(":")) }
changedFiles.removed.ifNotEmpty { options += SubpluginOption("knownRemoved", map { it.path }.joinToString(":")) }
changedFiles.modified.ifNotEmpty { options += SubpluginOption("knownModified", map { it.path }.joinToString(File.pathSeparator)) }
changedFiles.removed.ifNotEmpty { options += SubpluginOption("knownRemoved", map { it.path }.joinToString(File.pathSeparator)) }
options.ifNotEmpty { addPluginOptions(this) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ class IncrementalIT {
"w: [ksp] p3/J3.java",
),
"workload/src/main/kotlin/p1/K1.kt" to setOf(
"w: [ksp] <root>/K1.kt",
"w: [ksp] p1/TestK2K.kt",
"w: [ksp] p1/K1.kt",
"w: [ksp] p1/TestJ2K.java",
),
"workload/src/main/kotlin/p1/K2.kt" to setOf(
"w: [ksp] <root>/K2.kt",
"w: [ksp] p1/K2.kt",
),
"workload/src/main/kotlin/p1/TestK2J.kt" to setOf(
"w: [ksp] p1/TestK2J.kt",
Expand All @@ -62,9 +64,7 @@ class IncrementalIT {
"w: [ksp] p1/TestJ2K.java",
),
"workload/src/main/kotlin/p3/K1.kt" to setOf(
"w: [ksp] p1/TestK2K.kt",
"w: [ksp] p3/K1.kt",
"w: [ksp] p1/TestJ2K.java",
),
"workload/src/main/kotlin/p3/K2.kt" to setOf(
"w: [ksp] p3/K2.kt",
Expand Down Expand Up @@ -103,13 +103,106 @@ class IncrementalIT {
gradleRunner.withArguments("assemble").build().let { result ->
Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":workload:kspKotlin")?.outcome)
val dirties = result.output.split("\n").filter { it.startsWith("w: [ksp]") }.toSet()
Assert.assertEquals(dirties, expectedDirties)
Assert.assertEquals(expectedDirties, dirties)
}
}
val incrementalArtifact = Artifact(File(project.root, "workload/build/libs/workload-1.0-SNAPSHOT.jar"))
Assert.assertEquals(cleanArtifact, incrementalArtifact)
}

val changeSets = listOf(
listOf(7, 5),
listOf(0, 12),
listOf(13, 14),
listOf(8, 10),
listOf(11, 4),
listOf(3, 15),
listOf(6, 9),
listOf(2, 1),
listOf(3, 1, 12),
listOf(13, 0, 11),
listOf(6, 8, 4),
listOf(10, 9, 15),
listOf(2, 14, 5, 7),
listOf(5, 0, 13, 15),
listOf(3, 2, 6, 7),
listOf(4, 14, 10, 1),
listOf(12, 9, 8, 11),
listOf(12, 13, 5, 14, 7),
listOf(11, 2, 8, 8, 9),
listOf(11, 2, 8, 8, 9),
listOf(4, 0, 15, 1, 10),
)

@Test
fun testMultipleChanges() {
val gradleRunner = GradleRunner.create().withProjectDir(project.root)

gradleRunner.withArguments("clean", "assemble").build().let { result ->
Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":workload:assemble")?.outcome)
}

changeSets.forEach { changeSet ->
changeSet.forEach {
File(project.root, src2Dirty[it].first).appendText("\n\n")
}
val expectedDirties = changeSet.flatMapTo(mutableSetOf()) {
src2Dirty[it].second
}
gradleRunner.withArguments("assemble").build().let { result ->
Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":workload:kspKotlin")?.outcome)
val dirties = result.output.split("\n").filter { it.startsWith("w: [ksp]") }.toSet()
Assert.assertEquals(expectedDirties, dirties)
}

}
}

@Test
fun testMultipleDeletes() {
val gradleRunner = GradleRunner.create().withProjectDir(project.root)

gradleRunner.withArguments("clean", "assemble").build().let { result ->
Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":workload:assemble")?.outcome)
}

val srcs = src2Dirty.map { it.first }

changeSets.forEach { changeSet ->
val notChanged = IntRange(0, srcs.size - 1).filter { it !in changeSet }

// Touch a file so that Gradle won't UP_TO_DATE for us.
notChanged.first().let {
File(project.root, srcs[it]).appendText("\n\n")
}

// Delete files
changeSet.forEach {
File(project.root, srcs[it]).delete()
}

// in: "workload/src/main/kotlin/p1/K2.kt"
// out: "p1/K2.kt"
val expectedOutputs = notChanged.map() {
srcs[it].split("/").subList(4, 6).joinToString("/") + ".log"
}.sorted()

gradleRunner.withArguments(":workload:kspKotlin").build().let { result ->
Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":workload:kspKotlin")?.outcome)
val outputRoot = File(project.root, "workload/build/generated/ksp/main/resources")
val outputs = outputRoot.walk().filter { it.isFile() }.map {
it.toRelativeString(outputRoot)
}.sorted().toList()

Assert.assertEquals(expectedOutputs, outputs)
}

changeSet.forEach {
project.restore(srcs[it])
}
}
}

@Test
fun testArgChange() {
val gradleRunner = GradleRunner.create().withProjectDir(project.root)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package p1

open class K1
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package p1

open class K2

0 comments on commit 791fc87

Please sign in to comment.