Skip to content

Commit

Permalink
Add an option to disable incremental compilation with zinc.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdziuban committed Oct 30, 2023
1 parent a3bd10c commit 1a39164
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
6 changes: 4 additions & 2 deletions scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ trait ZincWorkerApi {
compileClasspath: Agg[os.Path],
javacOptions: Seq[String],
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean
reportCachedProblems: Boolean,
disableIncrementalCompilation: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult]

/** Compile a mixed Scala/Java or Scala-only project */
Expand All @@ -30,7 +31,8 @@ trait ZincWorkerApi {
compilerClasspath: Agg[PathRef],
scalacPluginClasspath: Agg[PathRef],
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean
reportCachedProblems: Boolean,
disableIncrementalCompilation: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult]

def discoverMainClasses(compilationResult: CompilationResult): Seq[String]
Expand Down
7 changes: 6 additions & 1 deletion scalalib/src/mill/scalalib/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ trait JavaModule
).equalsIgnoreCase("true")
}

def zincDisableIncrementalCompilation: T[Boolean] = T {
false
}

/**
* Compiles the current module to generate compiled classfiles/bytecode.
*
Expand All @@ -370,7 +374,8 @@ trait JavaModule
compileClasspath = compileClasspath().map(_.path),
javacOptions = javacOptions(),
reporter = T.reporter.apply(hashCode),
reportCachedProblems = zincReportCachedProblems()
reportCachedProblems = zincReportCachedProblems(),
disableIncrementalCompilation = zincDisableIncrementalCompilation()
)
}

Expand Down
6 changes: 4 additions & 2 deletions scalalib/src/mill/scalalib/ScalaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer =>
compilerClasspath = scalaCompilerClasspath(),
scalacPluginClasspath = scalacPluginClasspath(),
reporter = T.reporter.apply(hashCode),
reportCachedProblems = zincReportCachedProblems()
reportCachedProblems = zincReportCachedProblems(),
disableIncrementalCompilation = zincDisableIncrementalCompilation()
)
}

Expand Down Expand Up @@ -579,7 +580,8 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer =>
compilerClasspath = scalaCompilerClasspath(),
scalacPluginClasspath = semanticDbPluginClasspath(),
reporter = None,
reportCachedProblems = zincReportCachedProblems()
reportCachedProblems = zincReportCachedProblems(),
disableIncrementalCompilation = zincDisableIncrementalCompilation()
)
.map(r =>
SemanticDbJavaModule.copySemanticdbFiles(r.classes.path, T.workspace, T.dest / "data")
Expand Down
4 changes: 3 additions & 1 deletion scalalib/src/mill/scalalib/SemanticDbJavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ trait SemanticDbJavaModule extends CoursierModule {
def zincWorker: ModuleRef[ZincWorkerModule]
def upstreamCompileOutput: T[Seq[CompilationResult]]
def zincReportCachedProblems: T[Boolean]
def zincDisableIncrementalCompilation: T[Boolean]
def allSourceFiles: T[Seq[PathRef]]
def compile: T[mill.scalalib.api.CompilationResult]
def bspBuildTarget: BspBuildTarget
Expand Down Expand Up @@ -116,7 +117,8 @@ trait SemanticDbJavaModule extends CoursierModule {
(compileClasspath() ++ resolvedSemanticDbJavaPluginIvyDeps()).map(_.path),
javacOptions = javacOpts,
reporter = None,
reportCachedProblems = zincReportCachedProblems()
reportCachedProblems = zincReportCachedProblems(),
disableIncrementalCompilation = zincDisableIncrementalCompilation()
).map(r =>
SemanticDbJavaModule.copySemanticdbFiles(r.classes.path, T.workspace, T.dest / "data")
)
Expand Down
22 changes: 16 additions & 6 deletions scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ class ZincWorkerImpl(
compileClasspath: Agg[os.Path],
javacOptions: Seq[String],
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean
reportCachedProblems: Boolean,
disableIncrementalCompilation: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): Result[CompilationResult] = {
compileInternal(
upstreamCompileOutput = upstreamCompileOutput,
Expand All @@ -305,7 +306,8 @@ class ZincWorkerImpl(
scalacOptions = Nil,
compilers = javaOnlyCompilers(javacOptions),
reporter = reporter,
reportCachedProblems = reportCachedProblems
reportCachedProblems = reportCachedProblems,
disableIncrementalCompilation = disableIncrementalCompilation
)
}

Expand All @@ -320,7 +322,8 @@ class ZincWorkerImpl(
compilerClasspath: Agg[PathRef],
scalacPluginClasspath: Agg[PathRef],
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean
reportCachedProblems: Boolean,
disableIncrementalCompilation: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): Result[CompilationResult] = {
withCompilers(
scalaVersion = scalaVersion,
Expand All @@ -337,7 +340,8 @@ class ZincWorkerImpl(
scalacOptions = scalacOptions,
compilers = compilers,
reporter = reporter,
reportCachedProblems: Boolean
reportCachedProblems: Boolean,
disableIncrementalCompilation
)
}
}
Expand Down Expand Up @@ -419,7 +423,8 @@ class ZincWorkerImpl(
scalacOptions: Seq[String],
compilers: Compilers,
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean
reportCachedProblems: Boolean,
disableIncrementalCompilation: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): Result[CompilationResult] = {
os.makeDir.all(ctx.dest)

Expand Down Expand Up @@ -514,7 +519,12 @@ class ZincWorkerImpl(
earlyAnalysisStore = None,
extra = Array()
),
pr = {
pr = if (disableIncrementalCompilation) {
PreviousResult.of(
Optional.empty[CompileAnalysis],
Optional.empty[MiniSetup]
)
} else {
val prev = store.get()
PreviousResult.of(
prev.map(_.getAnalysis): Optional[CompileAnalysis],
Expand Down

0 comments on commit 1a39164

Please sign in to comment.