Skip to content

Commit

Permalink
Cleanup Kotlin classes (#3733)
Browse files Browse the repository at this point in the history
Pull request: #3733
  • Loading branch information
lefou authored Oct 15, 2024
1 parent 7c0f7a0 commit cbd51e9
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 44 deletions.
33 changes: 18 additions & 15 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -191,32 +191,35 @@ object Deps {
val kotlinCompiler = ivy"org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion"

object RuntimeDeps {
val dokkaVersion = "1.9.20"
val koverVersion = "0.8.3"

val detektCli = ivy"io.gitlab.arturbosch.detekt:detekt-cli:1.23.7"
val dokkaAnalysisDescriptors = ivy"org.jetbrains.dokka:analysis-kotlin-descriptors:$dokkaVersion"
val dokkaBase = ivy"org.jetbrains.dokka:dokka-base:$dokkaVersion"
val dokkaCli = ivy"org.jetbrains.dokka:dokka-cli:$dokkaVersion"
val errorProneCore = ivy"com.google.errorprone:error_prone_core:2.31.0"
val freemarker = ivy"org.freemarker:freemarker:2.3.31"
val jupiterInterface = ivy"com.github.sbt.junit:jupiter-interface:0.11.4"
val sbtTestInterface = ivy"com.github.sbt:junit-interface:0.13.2"
val koverVersion = "0.8.3"
val kotlinxHtmlJvm = ivy"org.jetbrains.kotlinx:kotlinx-html-jvm:0.8.0"
val koverCli = ivy"org.jetbrains.kotlinx:kover-cli:$koverVersion"
val koverJvmAgent = ivy"org.jetbrains.kotlinx:kover-jvm-agent:$koverVersion"
val ktfmtVersion = "0.52"
val ktfmt = ivy"com.facebook:ktfmt:$ktfmtVersion"
val detektVersion = "1.23.7"
val detektCli = ivy"io.gitlab.arturbosch.detekt:detekt-cli:$detektVersion"
val dokkaVersion = "1.9.20"
val dokkaCli = ivy"org.jetbrains.dokka:dokka-cli:$dokkaVersion"
val dokkaBase = ivy"org.jetbrains.dokka:dokka-base:$dokkaVersion"
val dokkaAnalysisDescriptors = ivy"org.jetbrains.dokka:analysis-kotlin-descriptors:$dokkaVersion"
val ktfmt = ivy"com.facebook:ktfmt:0.52"
val sbtTestInterface = ivy"com.github.sbt:junit-interface:0.13.2"

def all = Seq(
detektCli,
dokkaAnalysisDescriptors,
dokkaBase,
dokkaCli,
errorProneCore,
freemarker,
jupiterInterface,
sbtTestInterface,
kotlinxHtmlJvm,
koverCli,
koverJvmAgent,
ktfmt,
detektCli,
dokkaCli,
dokkaBase,
dokkaAnalysisDescriptors
sbtTestInterface,
)
}

Expand Down
8 changes: 5 additions & 3 deletions kotlinlib/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ object `package` extends RootModule with build.MillPublishScalaModule with Build
def buildInfoMembers = Seq(
BuildInfo.Value("kotlinVersion", build.Deps.kotlinVersion, "Version of Kotlin"),
BuildInfo.Value("koverVersion", build.Deps.RuntimeDeps.koverVersion, "Version of Kover."),
BuildInfo.Value("ktfmtVersion", build.Deps.RuntimeDeps.ktfmtVersion, "Version of Ktfmt."),
BuildInfo.Value("detektVersion", build.Deps.RuntimeDeps.detektVersion, "Version of Detekt."),
BuildInfo.Value("dokkaVersion", build.Deps.RuntimeDeps.dokkaVersion, "Version of Dokka.")
BuildInfo.Value("ktfmtVersion", build.Deps.RuntimeDeps.ktfmt.version, "Version of Ktfmt."),
BuildInfo.Value("detektVersion", build.Deps.RuntimeDeps.detektCli.version, "Version of Detekt."),
BuildInfo.Value("dokkaVersion", build.Deps.RuntimeDeps.dokkaVersion, "Version of Dokka."),
BuildInfo.Value("kotlinxHtmlJvmDep", Dep.unparse(build.Deps.RuntimeDeps.kotlinxHtmlJvm).get, "kotlinx-html-jvm dependency (used for Dokka)"),
BuildInfo.Value("freemarkerDep", Dep.unparse(build.Deps.RuntimeDeps.freemarker).get, "freemarker dependency (used for Dokka)")
)

trait MillKotlinModule extends build.MillPublishScalaModule {
Expand Down
25 changes: 13 additions & 12 deletions kotlinlib/src/mill/kotlinlib/KotlinModule.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* Copyright 2020-Present Original lefou/mill-kotlin repository contributors.
* Original code copied from https://github.com/lefou/mill-kotlin
* Original code published under the Apache License Version 2
* Original Copyright 2020-2024 Tobias Roeser
*/

package mill
package kotlinlib

import mill.api.{Loose, PathRef, Result, internal}
import mill.api.{PathRef, Result, internal}
import mill.define.{Command, ModuleRef, Task}
import mill.kotlinlib.worker.api.{KotlinWorker, KotlinWorkerTarget}
import mill.scalalib.api.{CompilationResult, ZincWorkerApi}
Expand Down Expand Up @@ -140,6 +141,7 @@ trait KotlinModule extends JavaModule { outer =>
if (files.nonEmpty) {
val pluginClasspathOption = Seq(
"-pluginsClasspath",
// `;` separator is used on all platforms!
dokkaPluginsClasspath().map(_.path).mkString(";")
)

Expand Down Expand Up @@ -178,21 +180,21 @@ trait KotlinModule extends JavaModule { outer =>
/**
* Classpath for running Dokka.
*/
private def dokkaCliClasspath: T[Loose.Agg[PathRef]] = Task {
private def dokkaCliClasspath: T[Agg[PathRef]] = Task {
defaultResolver().resolveDeps(
Agg(
ivy"org.jetbrains.dokka:dokka-cli:${dokkaVersion()}"
)
)
}

private def dokkaPluginsClasspath: T[Loose.Agg[PathRef]] = Task {
private def dokkaPluginsClasspath: T[Agg[PathRef]] = Task {
defaultResolver().resolveDeps(
Agg(
ivy"org.jetbrains.dokka:dokka-base:${dokkaVersion()}",
ivy"org.jetbrains.dokka:analysis-kotlin-descriptors:${dokkaVersion()}",
ivy"org.jetbrains.kotlinx:kotlinx-html-jvm:0.8.0",
ivy"org.freemarker:freemarker:2.3.31"
Dep.parse(Versions.kotlinxHtmlJvmDep),
Dep.parse(Versions.freemarkerDep)
)
)
}
Expand Down Expand Up @@ -241,7 +243,7 @@ trait KotlinModule extends JavaModule { outer =>
)
val compilerArgs: Seq[String] = Seq(
// destdir
Seq("-d", classes.toIO.getAbsolutePath()),
Seq("-d", classes.toString()),
// classpath
when(compileCp.iterator.nonEmpty)(
"-classpath",
Expand All @@ -250,10 +252,10 @@ trait KotlinModule extends JavaModule { outer =>
kotlincOptions(),
extraKotlinArgs,
// parameters
(kotlinSourceFiles ++ javaSourceFiles).map(_.toIO.getAbsolutePath())
(kotlinSourceFiles ++ javaSourceFiles).map(_.toString())
).flatten

val workerResult = kotlinWorkerTask().compile(KotlinWorkerTarget.Jvm, compilerArgs: _*)
val workerResult = kotlinWorkerTask().compile(KotlinWorkerTarget.Jvm, compilerArgs)

val analysisFile = dest / "kotlin.analysis.dummy"
os.write(target = analysisFile, data = "", createFolders = true)
Expand Down Expand Up @@ -325,11 +327,10 @@ trait KotlinModule extends JavaModule { outer =>
/**
* A test sub-module linked to its parent module best suited for unit-tests.
*/
trait KotlinTests extends JavaModuleTests with KotlinModule {
trait KotlinTests extends JavaTests with KotlinModule {
override def kotlinVersion: T[String] = Task { outer.kotlinVersion() }
override def kotlinCompilerVersion: T[String] = Task { outer.kotlinCompilerVersion() }
override def kotlincOptions: T[Seq[String]] = Task { outer.kotlincOptions() }
override def defaultCommandName(): String = super.defaultCommandName()
}

}
5 changes: 3 additions & 2 deletions kotlinlib/src/mill/kotlinlib/KotlinWorkerManager.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* Copyright 2020-Present Original lefou/mill-kotlin repository contributors.
* Original code copied from https://github.com/lefou/mill-kotlin
* Original code published under the Apache License Version 2
* Original Copyright 2020-2024 Tobias Roeser
*/

package mill.kotlinlib

import mill.api.{Ctx, PathRef}
Expand Down
7 changes: 4 additions & 3 deletions kotlinlib/src/mill/kotlinlib/KotlinWorkerManagerImpl.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* Copyright 2020-Present Original lefou/mill-kotlin repository contributors.
* Original code copied from https://github.com/lefou/mill-kotlin
* Original code published under the Apache License Version 2
* Original Copyright 2020-20 24 Tobias Roeser
*/

package mill.kotlinlib

import mill.PathRef
Expand All @@ -18,7 +19,7 @@ class KotlinWorkerManagerImpl(ctx: Ctx) extends KotlinWorkerManager with AutoClo
val toolsCp = toolsClasspath.distinct
val (worker, count) = workerCache.get(toolsCp) match {
case Some((w, count)) =>
ctx.log.debug(s"Reusing existing AspectjWorker for classpath: ${toolsCp}")
ctx.log.debug(s"Reusing existing KotlinWorker for classpath: ${toolsCp}")
w -> count
case None =>
ctx.log.debug(s"Creating Classloader with classpath: [${toolsCp}]")
Expand Down
5 changes: 3 additions & 2 deletions kotlinlib/src/mill/kotlinlib/KotlinWorkerModule.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* Copyright 2020-Present Original lefou/mill-kotlin repository contributors.
* Original code copied from https://github.com/lefou/mill-kotlin
* Original code published under the Apache License Version 2
* Original Copyright 2020-2024 Tobias Roeser
*/

package mill.kotlinlib

import mill.{T, Task}
Expand Down
2 changes: 1 addition & 1 deletion kotlinlib/src/mill/kotlinlib/js/KotlinJSModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ trait KotlinJSModule extends KotlinModule { outer =>
} else {
T.log.info(s"Linking IR to $compileDestination")
}
val workerResult = worker.compile(KotlinWorkerTarget.Js, compilerArgs: _*)
val workerResult = worker.compile(KotlinWorkerTarget.Js, compilerArgs)

val analysisFile = T.dest / "kotlin.analysis.dummy"
if (!os.exists(analysisFile)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* Copyright 2020-Present Original lefou/mill-kotlin repository contributors.
* Original code copied from https://github.com/lefou/mill-kotlin
* Original code published under the Apache License Version 2
* Original Copyright 2020-2024 Tobias Roeser
*/

package mill.kotlinlib.worker.impl

import mill.api.{Ctx, Result}
Expand All @@ -11,7 +12,7 @@ import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler

class KotlinWorkerImpl extends KotlinWorker {

def compile(target: KotlinWorkerTarget, args: String*)(implicit ctx: Ctx): Result[Unit] = {
def compile(target: KotlinWorkerTarget, args: Seq[String])(implicit ctx: Ctx): Result[Unit] = {
ctx.log.debug("Using kotlin compiler arguments: " + args.map(v => s"'${v}'").mkString(" "))

val compiler = target match {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*
* Copyright 2020-Present Original lefou/mill-kotlin repository contributors.
* Original code copied from https://github.com/lefou/mill-kotlin
* Original code published under the Apache License Version 2
* Original Copyright 2020-2024 Tobias Roeser
*/

package mill.kotlinlib.worker.api

import mill.api.{Ctx, Result}

trait KotlinWorker {

def compile(target: KotlinWorkerTarget, args: String*)(implicit ctx: Ctx): Result[Unit]
def compile(target: KotlinWorkerTarget, args: Seq[String])(implicit ctx: Ctx): Result[Unit]

}

Expand Down

0 comments on commit cbd51e9

Please sign in to comment.