Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop incremental compilation state for Mill modules when version changes #3884

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion runner/src/mill/runner/MillBuildRootModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import mill.define.{Discover, Task}
import mill.scalalib.{BoundDep, Dep, DepSyntax, Lib, ScalaModule}
import mill.util.CoursierSupport
import mill.util.Util.millProjectModule
import mill.scalalib.api.Versions
import mill.scalalib.api.{CompilationResult, Versions}
import mill.main.client.OutFiles._
import mill.main.client.CodeGenConstants.buildFileExtensions
import mill.main.{BuildInfo, RootModule}
Expand Down Expand Up @@ -261,6 +261,49 @@ abstract class MillBuildRootModule()(implicit

/** Used in BSP IntelliJ, which can only work with directories */
def dummySources: Sources = Task.Sources(T.dest)

def millVersion = T.input { BuildInfo.millVersion }

override def compile: T[CompilationResult] = Task(persistent = true) {
val mv = millVersion()

val prevMillVersionFile = T.dest / s"mill-version"
val prevMillVersion = Option(prevMillVersionFile)
.filter(os.exists)
.map(os.read(_).trim)
.getOrElse("?")

if (prevMillVersion != mv) {
// Mill version changed, drop all previous incremental state
// see https://github.com/com-lihaoyi/mill/issues/3874
T.log.debug(
s"Detected Mill version change ${prevMillVersion} -> ${mv}. Dropping previous incremental compilation state"
)
os.remove.all(T.dest)
os.makeDir(T.dest)
os.write(prevMillVersionFile, mv)
}

// copied from `ScalaModule`
zincWorker()
.worker()
.compileMixed(
upstreamCompileOutput = upstreamCompileOutput(),
sources = Agg.from(allSourceFiles().map(_.path)),
compileClasspath = compileClasspath().map(_.path),
javacOptions = javacOptions() ++ mandatoryJavacOptions(),
scalaVersion = scalaVersion(),
scalaOrganization = scalaOrganization(),
scalacOptions = allScalacOptions(),
compilerClasspath = scalaCompilerClasspath(),
scalacPluginClasspath = scalacPluginClasspath(),
reporter = T.reporter.apply(hashCode),
reportCachedProblems = zincReportCachedProblems(),
incrementalCompilation = zincIncrementalCompilation(),
auxiliaryClassFileExtensions = zincAuxiliaryClassFileExtensions()
)
}

}

object MillBuildRootModule {
Expand Down
Loading