fun createToolchain()

in src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt [102:141]


    fun createToolchain(jvmAbiGenPath: Path): KotlinToolchain {
      val df = FileSystems.getDefault()
      val javaHome = df.getPath(System.getProperty("java.home")).let { path ->
        path.takeIf { !it.endsWith(Paths.get("jre")) } ?: path.parent
      }.verifiedPath()

      val skipCodeGenFile = SKIP_CODE_GEN_PLUGIN.verified().absoluteFile
      val jdepsGenFile = JDEPS_GEN_PLUGIN.verified().absoluteFile

      val kotlinCompilerJar = BazelRunFiles.resolveVerified(
        "external", "com_github_jetbrains_kotlin", "lib", "kotlin-compiler.jar")

      val jvmAbiGenFile = jvmAbiGenPath.verified()
      return KotlinToolchain(
        kotlinCompilerJar.toPath().parent.parent,
        createClassLoader(
          javaHome,
          listOf(
            kotlinCompilerJar,
            COMPILER.verified().absoluteFile,
            // plugins *must* be preloaded. Not doing so causes class conflicts
            // (and a NoClassDef err) in the compiler extension interfaces.
            // This may cause issues in accepting user defined compiler plugins.
            jvmAbiGenFile.absoluteFile,
            skipCodeGenFile,
            jdepsGenFile
          )
        ),
        jvmAbiGen = CompilerPlugin(
          jvmAbiGenFile.absolutePath,
          "org.jetbrains.kotlin.jvm.abi"),
        skipCodeGen = CompilerPlugin(
          skipCodeGenFile.absolutePath,
          "io.bazel.kotlin.plugin.SkipCodeGen"),
        jdepsGen = CompilerPlugin(
          jdepsGenFile.absolutePath,
          "io.bazel.kotlin.plugin.jdeps.JDepsGen"
        )
      )
    }