Kotlin support in Glean using FIR compiler plugin.
Schema is in schema/kotlin.angle. Facts are extracted during compilation and serialized into a json files supported by Glean.
FIR is currently unstable, and it is unlikely that your project will successfully build with FIR on versions 1.6.21 and 1.7.0.
- Clone this repository
git clone --depth=1 https://github.com/e2e4b6b7/KtGlean.git
- Publish libraries to local Maven repository
./gradlew build publishToMavenLocal
- Add dependencies to your project
- In
settings.gradle.kts
(Strictly at the beginning of the file):pluginManagement { repositories { gradlePluginPortal() mavenLocal() // optional, dev compiler versions maven { url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") } } }
- In
build.gradle.kts
:For all modules:buildscript { dependencies { classpath("org.jetbrains.research.ktglean:gradle-plugin:0.1.0") } }
For single module:allprojects { plugins.apply("org.jetbrains.research.ktglean") repositories { // optional, dev compiler versions maven { url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") } mavenLocal() } tasks.withType<KotlinCompile> { kotlinOptions.useFir = true } }
plugins { // ... id("org.jetbrains.research.ktglean") version "0.1.0" } repositories { // optional, dev compiler versions maven { url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") } mavenLocal() } tasks.withType<KotlinCompile> { kotlinOptions.useFir = true }
- In
- Run compilation
- Clean caches (To force a rebuild):
./gradlew clean
- Compile code:
(or any other similar command)
./gradlew compileKotlin
- Clean caches (To force a rebuild):
- Facts will be in the directory
KtGleanData
. Can be fully added to the database using command:glean write --service $service --repo $repo KtGleanData/*/*
- Write new schema in
schema/kotlin.angle
(or any otherschema/*.angle
). - Add your schema to the list of inherited by
all
schema. - Regenerate data classes.
./gradlew :codegen:fatJar java -jar codegen/bild/libs/codegen.jar -o kotlinc-plugin/src/main/kotlin -p org.jetbrains.research.ktglean.predicates schema/kotlin.angle
- Implement factories in module
kotlinc-plugin
, packageorg.jetbrains.research.ktglean.factories
- Implement indexers in module
kotlinc-plugin
, packageorg.jetbrains.research.ktglean.indexers
- Register all of them to the
org.jetbrains.research.ktglean.Config
:codegen
-- generation of data classes from Angle schema for serialization. Deserialization is not supported yet:codegen-runtime
-- runtime dependency for generated files:core
-- common constants:gradle-plugin
-- gradle plugin for registration and configuration of compiler plugin:kotlinc-plugin
-- compiler plugin that extract factsorg.jetbrains.research.ktglean.factories
-- factories that generate facts from FIR elementsorg.jetbrains.research.ktglean.indexers
-- indexers registered to the compiler as a pluginsorg.jetbrains.research.ktglean.predicates
-- data classes generated by:codegen
org.jetbrains.research.ktglean.Config
-- configuration of storage, indexers and factoriesorg.jetbrains.research.ktglean.KtGleanCommandLineProcessor
-- parser of configuration from:gradle-plugin
org.jetbrains.research.ktglean.KtGleanComponentRegistrar
-- registrar of all components