From 442d1cf711223a7945542d9d6d0db1a1d9003419 Mon Sep 17 00:00:00 2001 From: "Alexander.Likhachev" Date: Tue, 18 Jul 2023 23:05:34 +0200 Subject: [PATCH] [BT] Move ClassSnapshotGranularity to the Build Tools API package --- .../api/jvm/ClassSnapshotGranularity.kt | 33 +++++++++++++++++++ .../classpathDiff/ClasspathSnapshot.kt | 29 +--------------- .../classpathDiff/ClasspathSnapshotter.kt | 3 +- .../ClasspathChangesComputerTest.kt | 5 +-- .../ClasspathSnapshotTestCommon.kt | 1 + .../classpathDiff/ClasspathSnapshotterTest.kt | 1 + .../ClasspathEntrySnapshotTransform.kt | 6 ++-- 7 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/buildtools/api/jvm/ClassSnapshotGranularity.kt diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/buildtools/api/jvm/ClassSnapshotGranularity.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/buildtools/api/jvm/ClassSnapshotGranularity.kt new file mode 100644 index 00000000000..26494fd47ab --- /dev/null +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/buildtools/api/jvm/ClassSnapshotGranularity.kt @@ -0,0 +1,33 @@ +/* + * 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.buildtools.api.jvm + +/** + * The granularity of a [ClassSnapshot]. + * + * There are currently two granularity levels: + * - [CLASS_LEVEL]) (coarse-grained): The size of the snapshot will be smaller, but we will have coarse-grained classpath changes, which + * means more source files will be recompiled. + * - [CLASS_MEMBER_LEVEL] (fine-grained): The size of the snapshot will be larger, but we will have fine-grained classpath changes, which + * means fewer source files will be recompiled. + * + * Therefore, [CLASS_LEVEL] is typically suitable for classes that are infrequently changed (e.g., external libraries), whereas + * [CLASS_MEMBER_LEVEL] is suitable for classes that are frequently changed (e.g., classes produced by the current project). + */ +enum class ClassSnapshotGranularity { + + /** + * Snapshotting level that allows tracking whether a .class file has changed without tracking what specific parts of the .class file + * (e.g., fields or methods) have changed. + */ + CLASS_LEVEL, + + /** + * Snapshotting level that allows tracking not only whether a .class file has changed but also what specific parts of the .class file + * (e.g., fields or methods) have changed. + */ + CLASS_MEMBER_LEVEL +} \ No newline at end of file diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshot.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshot.kt index 2c692b37f3c..d6666d5f230 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshot.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshot.kt @@ -6,8 +6,7 @@ package org.jetbrains.kotlin.incremental.classpathDiff import org.jetbrains.kotlin.incremental.KotlinClassInfo -import org.jetbrains.kotlin.incremental.classpathDiff.ClassSnapshotGranularity.CLASS_LEVEL -import org.jetbrains.kotlin.incremental.classpathDiff.ClassSnapshotGranularity.CLASS_MEMBER_LEVEL +import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity.CLASS_MEMBER_LEVEL import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader.Kind.* import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.resolve.jvm.JvmClassName @@ -138,29 +137,3 @@ class JavaElementSnapshot( */ data object InaccessibleClassSnapshot : ClassSnapshot() -/** - * The granularity of a [ClassSnapshot]. - * - * There are currently two granularity levels: - * - [CLASS_LEVEL]) (coarse-grained): The size of the snapshot will be smaller, but we will have coarse-grained classpath changes, which - * means more source files will be recompiled. - * - [CLASS_MEMBER_LEVEL] (fine-grained): The size of the snapshot will be larger, but we will have fine-grained classpath changes, which - * means fewer source files will be recompiled. - * - * Therefore, [CLASS_LEVEL] is typically suitable for classes that are infrequently changed (e.g., external libraries), whereas - * [CLASS_MEMBER_LEVEL] is suitable for classes that are frequently changed (e.g., classes produced by the current project). - */ -enum class ClassSnapshotGranularity { - - /** - * Snapshotting level that allows tracking whether a .class file has changed without tracking what specific parts of the .class file - * (e.g., fields or methods) have changed. - */ - CLASS_LEVEL, - - /** - * Snapshotting level that allows tracking not only whether a .class file has changed but also what specific parts of the .class file - * (e.g., fields or methods) have changed. - */ - CLASS_MEMBER_LEVEL -} diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotter.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotter.kt index e6be81c7fcf..e4f9d329bb5 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotter.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotter.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.incremental.classpathDiff import org.jetbrains.kotlin.build.report.metrics.* +import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity import org.jetbrains.kotlin.incremental.ClassNodeSnapshotter.snapshotClass import org.jetbrains.kotlin.incremental.ClassNodeSnapshotter.snapshotClassExcludingMembers import org.jetbrains.kotlin.incremental.ClassNodeSnapshotter.snapshotField @@ -15,7 +16,7 @@ import org.jetbrains.kotlin.incremental.DifferenceCalculatorForPackageFacade.Com import org.jetbrains.kotlin.incremental.KotlinClassInfo import org.jetbrains.kotlin.incremental.PackagePartProtoData import org.jetbrains.kotlin.incremental.SelectiveClassVisitor -import org.jetbrains.kotlin.incremental.classpathDiff.ClassSnapshotGranularity.CLASS_MEMBER_LEVEL +import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity.CLASS_MEMBER_LEVEL import org.jetbrains.kotlin.incremental.hashToLong import org.jetbrains.kotlin.incremental.storage.toByteArray import org.jetbrains.kotlin.konan.file.use diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathChangesComputerTest.kt b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathChangesComputerTest.kt index ac8a9c5c859..a9a9888938e 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathChangesComputerTest.kt +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathChangesComputerTest.kt @@ -6,10 +6,11 @@ package org.jetbrains.kotlin.incremental.classpathDiff import org.jetbrains.kotlin.build.report.DoNothingBuildReporter +import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity import org.jetbrains.kotlin.incremental.ChangesEither import org.jetbrains.kotlin.incremental.LookupSymbol -import org.jetbrains.kotlin.incremental.classpathDiff.ClassSnapshotGranularity.CLASS_LEVEL -import org.jetbrains.kotlin.incremental.classpathDiff.ClassSnapshotGranularity.CLASS_MEMBER_LEVEL +import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity.CLASS_LEVEL +import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity.CLASS_MEMBER_LEVEL import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotTestCommon.ClassFileUtil.asFile import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotTestCommon.ClassFileUtil.snapshot import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotTestCommon.CompileUtil.compileAll diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotTestCommon.kt b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotTestCommon.kt index 4f65460c2f5..e87032e461e 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotTestCommon.kt +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotTestCommon.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.incremental.classpathDiff import com.google.gson.GsonBuilder +import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity import org.jetbrains.kotlin.cli.common.isWindows import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotTestCommon.ClassFileUtil.snapshot import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotTestCommon.CompileUtil.compile diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotterTest.kt b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotterTest.kt index f061de8f3c2..d85d00ab9e2 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotterTest.kt +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotterTest.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.incremental.classpathDiff +import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotTestCommon.ClassFileUtil.snapshot import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotTestCommon.SourceFile.JavaSourceFile import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathSnapshotTestCommon.SourceFile.KotlinSourceFile diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/transforms/ClasspathEntrySnapshotTransform.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/transforms/ClasspathEntrySnapshotTransform.kt index 2a48d0bf2cb..0eb10e681d8 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/transforms/ClasspathEntrySnapshotTransform.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/transforms/ClasspathEntrySnapshotTransform.kt @@ -14,9 +14,9 @@ import org.gradle.api.tasks.Classpath import org.gradle.api.tasks.Internal import org.jetbrains.kotlin.build.report.metrics.* import org.jetbrains.kotlin.gradle.report.BuildMetricsService -import org.jetbrains.kotlin.incremental.classpathDiff.ClassSnapshotGranularity -import org.jetbrains.kotlin.incremental.classpathDiff.ClassSnapshotGranularity.CLASS_LEVEL -import org.jetbrains.kotlin.incremental.classpathDiff.ClassSnapshotGranularity.CLASS_MEMBER_LEVEL +import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity +import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity.CLASS_LEVEL +import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity.CLASS_MEMBER_LEVEL import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathEntrySnapshotExternalizer import org.jetbrains.kotlin.incremental.classpathDiff.ClasspathEntrySnapshotter import org.jetbrains.kotlin.incremental.storage.saveToFile