Hello Kotlin Team! We are currently integrating t...
# compiler
i
Hello Kotlin Team! We are currently integrating the Kotlin Incremental Compiler into our build tool and we need some clarification regarding the provision of classpath snapshots. At the moment, we use the BuildToolsApi (pointer) for generating classpath snapshots. Our build tool, however, already has a mechanism for creating hashes at the file, class, and library levels to support incremental actions. We are wandering if we can leverage this existing functionality, as it appears similar to what Gradle does (pointer). Is there an available API that would allow us to create classpath entry snapshot files using the hashes provided by our build tool? Thanks for any help.
d
cc @Anton Lakotka [JB]
i
A gentle reminder here. 🙈
sorry 1
a
I'm sorry for taking this long!
We are currently integrating the Kotlin Incremental Compiler into our build tool
Just curious what is this build tool? How deep do you want support Kotlin in there?
Is there an available API that would allow us to create classpath entry snapshot files using the hashes provided by our build tool?
So you want to use your implementation of Classpath Snapshoter? But then I'm wondering how you'd want to use it further? Do you use
BuildToolsApi
to invoke Kotlin Compiler? Or do you invoke it via your own infrastructure? If you want to Integrate your ClasspathSnapshoter into
BuildToolsApi
I'm not sure if it is correct but it looks like you can provide your implementation of
CompilationService
i.e. instead of this:
Copy code
override fun calculateClasspathSnapshot(classpathEntry: File, granularity: ClassSnapshotGranularity) =
        ClasspathEntrySnapshotImpl(ClasspathEntrySnapshotter.snapshot(classpathEntry, granularity, DoNothingBuildMetricsReporter))
implement via your snapshotter:
Copy code
override fun calculateClasspathSnapshot(classpathEntry: File, granularity: ClassSnapshotGranularity) =
        ClasspathEntrySnapshotImpl(CustomSnapshotter.snapshot(classpathEntry, granularity, DoNothingBuildMetricsReporter))
But I'll CC relevant people, that were designing and implementing BTA cc: @Alexander.Likhachev @tapchicoma
t
Classpath snapshot is not about hashes, but about extracting ABI from compilation dependencies
a
I'd say hash of ABI declarations publicly accessible from a given Class file. i.e. this
Copy code
sealed class AccessibleClassSnapshot : ClassSnapshot() {
    abstract val classId: ClassId

    /** The hash of the class's ABI. */
    abstract val classAbiHash: Long

    override fun toString() = classId.toString()
}
👍 1
i
Just curious what is this build tool? How deep do you want support Kotlin in there?
Buck. Kotlin compilation using the K2JVMCompiler is already supported (pointer).
So you want to use your implementation of Classpath Snapshoter? But then I'm wondering how you'd want to use it further?
Do you use
BuildToolsApi
to invoke Kotlin Compiler? Or do you invoke it via your own infrastructure?
We are currently experimenting with the BuildToolsApi to enable incremental Kotlin compilation and create classpath snapshot files, which need to be provided here. However, Buck already has its own support for incremental actions, as documented here. We are wondering if we can reuse this data instead of recalculating it on the Kotlin side.
Classpath snapshot is not about hashes, but about extracting ABI from compilation dependencies
Isn't it represented by a hash at the end? (assuming by looking at AccessibleClassSnapshot).
you can provide your implementation of
CompilationService
I was already looking into this, but the documentation for the CompilationService states that "This interface is not intended to be implemented by API consumers," so I was not sure if it was the right approach.
Let me know if it makes sense. blob thinking upside down
I don't have much context about Gradle's internals, but I notice that classpath snapshots are also provided in the KotlinCompile task (pointer) in the Kotlin-Gradle plugin. However, I could not find more details about the implementation.