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

Add an option to disable incremental compilation with zinc #2851

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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,
incrementalCompilation: 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,
incrementalCompilation: 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 zincIncrementalCompilation: T[Boolean] = T {
true
}

/**
* 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(),
incrementalCompilation = zincIncrementalCompilation()
)
}

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(),
incrementalCompilation = zincIncrementalCompilation()
)
}

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(),
incrementalCompilation = zincIncrementalCompilation()
)
.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 zincIncrementalCompilation: 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(),
incrementalCompilation = zincIncrementalCompilation()
).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,
incrementalCompilation: 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,
incrementalCompilation = incrementalCompilation
)
}

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

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