Fix build reports when no kotlin task is executed
#KT-58313: Fixed
This commit is contained in:
committed by
Space Team
parent
750ff32241
commit
71e81aa30e
+1
-1
@@ -78,7 +78,7 @@ class FileReportService(
|
|||||||
// a bit unfamiliar.
|
// a bit unfamiliar.
|
||||||
// TODO: If it is confusing, consider renaming "tasks" to "build operations" in this class.
|
// TODO: If it is confusing, consider renaming "tasks" to "build operations" in this class.
|
||||||
printBuildInfo(startParameters, failureMessages)
|
printBuildInfo(startParameters, failureMessages)
|
||||||
if (printMetrics) {
|
if (printMetrics && statisticsData.isNotEmpty()) {
|
||||||
printMetrics(
|
printMetrics(
|
||||||
statisticsData.map { it.buildTimesMetrics }.reduce { agg, value ->
|
statisticsData.map { it.buildTimesMetrics }.reduce { agg, value ->
|
||||||
(agg.keys + value.keys).associateWith { (agg[it] ?: 0) + (value[it] ?: 0) }
|
(agg.keys + value.keys).associateWith { (agg[it] ?: 0) + (value[it] ?: 0) }
|
||||||
|
|||||||
+50
-37
@@ -12,9 +12,8 @@ import org.jetbrains.kotlin.gradle.report.BuildReportType
|
|||||||
import org.jetbrains.kotlin.gradle.testbase.*
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
import java.io.ObjectInputStream
|
import java.io.ObjectInputStream
|
||||||
|
import java.nio.file.Path
|
||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
import kotlin.test.assertEquals
|
|
||||||
import kotlin.test.assertNotNull
|
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@DisplayName("Build reports")
|
@DisplayName("Build reports")
|
||||||
@@ -25,6 +24,9 @@ class BuildReportsIT : KGPBaseTest() {
|
|||||||
buildReport = listOf(BuildReportType.FILE)
|
buildReport = listOf(BuildReportType.FILE)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val GradleProject.reportFile: Path
|
||||||
|
get() = projectPath.getSingleFileInDir("build/reports/kotlin-build")
|
||||||
|
|
||||||
@DisplayName("Build report is created")
|
@DisplayName("Build report is created")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
fun testBuildReportSmokeTest(gradleVersion: GradleVersion) {
|
fun testBuildReportSmokeTest(gradleVersion: GradleVersion) {
|
||||||
@@ -56,26 +58,23 @@ class BuildReportsIT : KGPBaseTest() {
|
|||||||
build("assemble") {
|
build("assemble") {
|
||||||
assertBuildReportPathIsPrinted()
|
assertBuildReportPathIsPrinted()
|
||||||
}
|
}
|
||||||
val reportFolder = projectPath.resolve("build/reports/kotlin-build").toFile()
|
|
||||||
val reports = reportFolder.listFiles()
|
|
||||||
assertNotNull(reports)
|
|
||||||
assertEquals(1, reports.size)
|
|
||||||
val report = reports[0].readText()
|
|
||||||
|
|
||||||
//Should contains build metrics for all compile kotlin tasks
|
//Should contains build metrics for all compile kotlin tasks
|
||||||
assertTrue { report.contains("Time metrics:") }
|
assertFileContains(
|
||||||
assertTrue { report.contains("Run compilation:") }
|
reportFile,
|
||||||
assertTrue { report.contains("Incremental compilation in daemon:") }
|
"Time metrics:",
|
||||||
assertTrue { report.contains("Size metrics:") }
|
"Run compilation:",
|
||||||
assertTrue { report.contains("Total size of the cache directory:") }
|
"Incremental compilation in daemon:",
|
||||||
assertTrue { report.contains("Total compiler iteration:") }
|
"Size metrics:",
|
||||||
assertTrue { report.contains("ABI snapshot size:") }
|
"Total size of the cache directory:",
|
||||||
//for non-incremental builds
|
"Total compiler iteration:",
|
||||||
assertTrue { report.contains("Build attributes:") }
|
"ABI snapshot size:",
|
||||||
assertTrue { report.contains("REBUILD_REASON:") }
|
//for non-incremental builds
|
||||||
//gc metrics
|
"Build attributes:",
|
||||||
assertTrue {report.contains("GC count:")}
|
"REBUILD_REASON:",
|
||||||
assertTrue {report.contains("GC time:")}
|
//gc metrics
|
||||||
|
"GC count:",
|
||||||
|
"GC time:",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,14 +85,26 @@ class BuildReportsIT : KGPBaseTest() {
|
|||||||
build("assemble") {
|
build("assemble") {
|
||||||
assertBuildReportPathIsPrinted()
|
assertBuildReportPathIsPrinted()
|
||||||
}
|
}
|
||||||
val reportFolder = projectPath.resolve("build/reports/kotlin-build").toFile()
|
assertFileContains(
|
||||||
val reports = reportFolder.listFiles()
|
reportFile,
|
||||||
assertNotNull(reports)
|
"Compiler code analysis:",
|
||||||
assertEquals(1, reports.size)
|
"Compiler code generation:",
|
||||||
val report = reports[0].readText()
|
"Compiler initialization time:",
|
||||||
assertTrue { report.contains("Compiler code analysis:") }
|
)
|
||||||
assertTrue { report.contains("Compiler code generation:") }
|
}
|
||||||
assertTrue { report.contains("Compiler initialization time:") }
|
}
|
||||||
|
|
||||||
|
@DisplayName("with no kotlin task executed")
|
||||||
|
@GradleTest
|
||||||
|
fun testFileReportWithoutKotlinTask(gradleVersion: GradleVersion) {
|
||||||
|
project("simpleProject", gradleVersion) {
|
||||||
|
build("assemble", "--dry-run") {
|
||||||
|
assertBuildReportPathIsPrinted()
|
||||||
|
}
|
||||||
|
assertFileContains(
|
||||||
|
reportFile,
|
||||||
|
"No Kotlin task was run",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,18 +191,20 @@ class BuildReportsIT : KGPBaseTest() {
|
|||||||
project("simpleProject", gradleVersion) {
|
project("simpleProject", gradleVersion) {
|
||||||
|
|
||||||
val lookupsTab = projectPath.resolve("build/kotlin/compileKotlin/cacheable/caches-jvm/lookups/lookups.tab")
|
val lookupsTab = projectPath.resolve("build/kotlin/compileKotlin/cacheable/caches-jvm/lookups/lookups.tab")
|
||||||
buildGradle.appendText("""
|
buildGradle.appendText(
|
||||||
tasks.named("compileKotlin") {
|
"""
|
||||||
doLast {
|
tasks.named("compileKotlin") {
|
||||||
new File("${lookupsTab.toUri().path}").write("Invalid contents")
|
doLast {
|
||||||
|
new File("${lookupsTab.toUri().path}").write("Invalid contents")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
""".trimIndent()
|
||||||
""".trimIndent())
|
)
|
||||||
build("compileKotlin") {
|
build("compileKotlin") {
|
||||||
assertTrue { projectPath.resolve(kotlinErrorPath).listDirectoryEntries().isEmpty() }
|
assertTrue { projectPath.resolve(kotlinErrorPath).listDirectoryEntries().isEmpty() }
|
||||||
}
|
}
|
||||||
val kotlinFile = kotlinSourcesDir().resolve("helloWorld.kt")
|
val kotlinFile = kotlinSourcesDir().resolve("helloWorld.kt")
|
||||||
kotlinFile.modify { it.replace("ArrayList","skjfghsjk") }
|
kotlinFile.modify { it.replace("ArrayList", "skjfghsjk") }
|
||||||
buildAndFail("compileKotlin") {
|
buildAndFail("compileKotlin") {
|
||||||
val buildErrorDir = projectPath.resolve(kotlinErrorPath).toFile()
|
val buildErrorDir = projectPath.resolve(kotlinErrorPath).toFile()
|
||||||
val files = buildErrorDir.listFiles()
|
val files = buildErrorDir.listFiles()
|
||||||
@@ -219,7 +232,7 @@ class BuildReportsIT : KGPBaseTest() {
|
|||||||
assertTrue { projectPath.resolve(kotlinErrorPath).listDirectoryEntries().isEmpty() }
|
assertTrue { projectPath.resolve(kotlinErrorPath).listDirectoryEntries().isEmpty() }
|
||||||
}
|
}
|
||||||
val kotlinFile = kotlinSourcesDir().resolve("helloWorld.kt")
|
val kotlinFile = kotlinSourcesDir().resolve("helloWorld.kt")
|
||||||
kotlinFile.modify { it.replace("ArrayList","skjfghsjk") }
|
kotlinFile.modify { it.replace("ArrayList", "skjfghsjk") }
|
||||||
buildAndFail("compileKotlin") {
|
buildAndFail("compileKotlin") {
|
||||||
assertTrue { projectPath.resolve(kotlinErrorPath).listDirectoryEntries().isEmpty() }
|
assertTrue { projectPath.resolve(kotlinErrorPath).listDirectoryEntries().isEmpty() }
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-10
@@ -10,10 +10,7 @@ import org.jetbrains.kotlin.gradle.testbase.GradleTest
|
|||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
import org.jetbrains.kotlin.gradle.testbase.*
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
import org.jetbrains.kotlin.gradle.util.replaceText
|
import org.jetbrains.kotlin.gradle.util.replaceText
|
||||||
import org.jetbrains.kotlin.test.KtAssert.fail
|
|
||||||
import java.nio.file.Files
|
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlin.streams.asSequence
|
|
||||||
|
|
||||||
@DisplayName("FUS statistic")
|
@DisplayName("FUS statistic")
|
||||||
class FusStatisticsIT : KGPBaseTest() {
|
class FusStatisticsIT : KGPBaseTest() {
|
||||||
@@ -62,13 +59,7 @@ class FusStatisticsIT : KGPBaseTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val GradleProject.fusStatisticsPath: Path
|
private val GradleProject.fusStatisticsPath: Path
|
||||||
get() {
|
get() = projectPath.getSingleFileInDir("kotlin-profile")
|
||||||
val statisticsDir = projectPath.resolve("kotlin-profile")
|
|
||||||
return Files.list(statisticsDir).use {
|
|
||||||
val files = it.asSequence().toList()
|
|
||||||
files.singleOrNull() ?: fail("The directory must contain a single statistics file, but got: $files")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@DisplayName("general fields")
|
@DisplayName("general fields")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
|
|||||||
+13
@@ -11,6 +11,7 @@ import java.nio.file.attribute.BasicFileAttributes
|
|||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
import kotlin.streams.asSequence
|
import kotlin.streams.asSequence
|
||||||
import kotlin.streams.toList
|
import kotlin.streams.toList
|
||||||
|
import kotlin.test.fail
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the file with given [name] in current [Path].
|
* Find the file with given [name] in current [Path].
|
||||||
@@ -128,3 +129,15 @@ fun TestProject.sourceFilesRelativeToProject(
|
|||||||
it.relativeTo(projectPath)
|
it.relativeTo(projectPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a single file located in the [relativePath] subdirectory. If no file or more than one file is found an assertion error will be thrown.
|
||||||
|
*/
|
||||||
|
fun Path.getSingleFileInDir(relativePath: String): Path {
|
||||||
|
val path = resolve(relativePath)
|
||||||
|
return Files.list(path).use {
|
||||||
|
val files = it.asSequence().toList()
|
||||||
|
files.singleOrNull() ?: fail("The directory must contain a single file, but got: $files")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user