Skip to content

e2e4b6b7/KtGlean

Repository files navigation

KtGlean

Kotlin support in Glean using FIR compiler plugin.

General Info

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.

Usage in your projects

  • 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:
      buildscript {
         dependencies {
             classpath("org.jetbrains.research.ktglean:gradle-plugin:0.1.0")
         }
      }
      For all modules:
      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
          }
      }
      For single module:
      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
      }
  • Run compilation
    • Clean caches (To force a rebuild):
      ./gradlew clean
    • Compile code:
      ./gradlew compileKotlin
      (or any other similar command)
  • Facts will be in the directory KtGleanData. Can be fully added to the database using command:
    glean write --service $service --repo $repo KtGleanData/*/*

New index creation pipeline

  • Write new schema in schema/kotlin.angle (or any other schema/*.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, package org.jetbrains.research.ktglean.factories
  • Implement indexers in module kotlinc-plugin, package org.jetbrains.research.ktglean.indexers
  • Register all of them to the org.jetbrains.research.ktglean.Config

Architecture

  • :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 facts
    • org.jetbrains.research.ktglean.factories -- factories that generate facts from FIR elements
    • org.jetbrains.research.ktglean.indexers -- indexers registered to the compiler as a plugins
    • org.jetbrains.research.ktglean.predicates -- data classes generated by :codegen
    • org.jetbrains.research.ktglean.Config -- configuration of storage, indexers and factories
    • org.jetbrains.research.ktglean.KtGleanCommandLineProcessor -- parser of configuration from :gradle-plugin
    • org.jetbrains.research.ktglean.KtGleanComponentRegistrar -- registrar of all components

About

Kotlin support in Glean

Resources

License

Stars

Watchers

Forks

Releases

No releases published