From 611a7e9ba52812bfdefc456738311136761b804e Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Sat, 9 Mar 2024 15:25:31 +0100 Subject: [PATCH 01/12] Pass auxiliary class files to zinc so they are deleted together Fixes https://github.com/com-lihaoyi/mill/issues/3068 `*.tasty`, `*.nir` and `*.sjsir` files were not cleaned up by zinc when the companion class files were deleted. This passes the right `AuxiliaryClassFiles` to zinc --- .../repo/app/src/foo.scala | 1 + .../auxiliary-class-files/repo/build.sc | 20 +++++++ .../test/src/AuxiliaryClassFilesTests.scala | 59 +++++++++++++++++++ .../src/mill/scalalib/api/ZincWorkerApi.scala | 40 ++++++++++++- scalalib/src/mill/scalalib/ScalaModule.scala | 2 + .../mill/scalalib/worker/ZincWorkerImpl.scala | 31 +++++++++- 6 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 integration/feature/auxiliary-class-files/repo/app/src/foo.scala create mode 100644 integration/feature/auxiliary-class-files/repo/build.sc create mode 100644 integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala diff --git a/integration/feature/auxiliary-class-files/repo/app/src/foo.scala b/integration/feature/auxiliary-class-files/repo/app/src/foo.scala new file mode 100644 index 00000000000..7ed8ede3e5d --- /dev/null +++ b/integration/feature/auxiliary-class-files/repo/app/src/foo.scala @@ -0,0 +1 @@ +object foo diff --git a/integration/feature/auxiliary-class-files/repo/build.sc b/integration/feature/auxiliary-class-files/repo/build.sc new file mode 100644 index 00000000000..3a783ad4c6e --- /dev/null +++ b/integration/feature/auxiliary-class-files/repo/build.sc @@ -0,0 +1,20 @@ +// Issue https://github.com/com-lihaoyi/mill/issues/3068 +import mill._ +import mill.scalalib._ +import mill.scalajslib._ +import mill.scalanativelib._ + +object app extends Module { + trait Common extends ScalaModule { + def millSourcePath = super.millSourcePath / os.up + def scalaVersion = "3.4.0" + } + + object jvm extends Common + object js extends Common with ScalaJSModule { + def scalaJSVersion = "1.15.0" + } + object native extends Common with ScalaNativeModule { + def scalaNativeVersion = "0.4.17" + } +} diff --git a/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala b/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala new file mode 100644 index 00000000000..e61be90f33f --- /dev/null +++ b/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala @@ -0,0 +1,59 @@ +package mill.integration + +import utest._ + +// Regress test for issue https://github.com/com-lihaoyi/mill/issues/1901 +object AuxiliaryClassFilesTests extends IntegrationTestSuite { + val tests: Tests = Tests { + test("tasty files are deleted together with companion class files") { + initWorkspace() + eval("app.jvm.compile") + + val classes = wd / "out" / "app" / "jvm" / "compile.dest" / "classes" + val firstRun = os.list(classes).map(_.last) + + os.remove(wd / "app" / "src" / "foo.scala") + + eval("app.jvm.compile") + + val secondRun = os.list(classes).map(_.last) + + assert(firstRun == Seq("foo$.class", "foo.class", "foo.tasty")) + assert(secondRun == Seq.empty) + } + + test("nir files are deleted together with companion class files") { + initWorkspace() + eval("app.native.compile") + + val classes = wd / "out" / "app" / "native" / "compile.dest" / "classes" + val firstRun = os.list(classes).map(_.last) + + os.remove(wd / "app" / "src" / "foo.scala") + + eval("app.native.compile") + + val secondRun = os.list(classes).map(_.last) + + assert(firstRun == Seq("foo$.class", "foo$.nir", "foo.class", "foo.nir", "foo.tasty")) + assert(secondRun == Seq.empty) + } + + test("sjsir files are deleted together with companion class files") { + initWorkspace() + eval("app.js.compile") + + val classes = wd / "out" / "app" / "js" / "compile.dest" / "classes" + val firstRun = os.list(classes).map(_.last) + + os.remove(wd / "app" / "src" / "foo.scala") + + eval("app.js.compile") + + val secondRun = os.list(classes).map(_.last) + + assert(firstRun == Seq("foo$.class", "foo$.sjsir", "foo.class", "foo.tasty")) + assert(secondRun == Seq.empty) + } + } +} diff --git a/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala b/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala index dc04fb91a15..f0a1b103ef4 100644 --- a/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala +++ b/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala @@ -56,6 +56,7 @@ trait ZincWorkerApi { compileClasspath: Agg[os.Path], javacOptions: Seq[String], scalaVersion: String, + platformSuffix: String, scalaOrganization: String, scalacOptions: Seq[String], compilerClasspath: Agg[PathRef], @@ -70,13 +71,15 @@ trait ZincWorkerApi { compileClasspath = compileClasspath, javacOptions = javacOptions, scalaVersion = scalaVersion, + platformSuffix = platformSuffix, scalaOrganization = scalaOrganization, scalacOptions = scalacOptions, compilerClasspath = compilerClasspath, scalacPluginClasspath = scalacPluginClasspath, reporter = reporter, - reportCachedProblems = reportCachedProblems - ): @nowarn("cat=deprecation") + reportCachedProblems = reportCachedProblems, + incrementalCompilation = incrementalCompilation + ) /** Compile a mixed Scala/Java or Scala-only project */ @deprecated("Use override with `incrementalCompilation` parameter", "Mill 0.11.6") @@ -99,6 +102,7 @@ trait ZincWorkerApi { compileClasspath = compileClasspath, javacOptions = javacOptions, scalaVersion = scalaVersion, + platformSuffix = "", scalaOrganization = scalaOrganization, scalacOptions = scalacOptions, compilerClasspath = compilerClasspath, @@ -108,6 +112,38 @@ trait ZincWorkerApi { incrementalCompilation = true ) + /** Compile a mixed Scala/Java or Scala-only project */ + @deprecated("Use override with `platformSuffix` parameter", "Mill 0.11.8") + def compileMixed( + upstreamCompileOutput: Seq[CompilationResult], + sources: Agg[os.Path], + compileClasspath: Agg[os.Path], + javacOptions: Seq[String], + scalaVersion: String, + scalaOrganization: String, + scalacOptions: Seq[String], + compilerClasspath: Agg[PathRef], + scalacPluginClasspath: Agg[PathRef], + reporter: Option[CompileProblemReporter], + reportCachedProblems: Boolean, + incrementalCompilation: Boolean + )(implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult] = + compileMixed( + upstreamCompileOutput = upstreamCompileOutput, + sources = sources, + compileClasspath = compileClasspath, + javacOptions = javacOptions, + scalaVersion = scalaVersion, + platformSuffix = "", + scalaOrganization = scalaOrganization, + scalacOptions = scalacOptions, + compilerClasspath = compilerClasspath, + scalacPluginClasspath = scalacPluginClasspath, + reporter = reporter, + reportCachedProblems = reportCachedProblems, + incrementalCompilation = incrementalCompilation + ) + def discoverMainClasses(compilationResult: CompilationResult): Seq[String] def docJar( diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index da7eed4b6c8..8974720a1c9 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -292,6 +292,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => compileClasspath = compileClasspath().map(_.path), javacOptions = javacOptions(), scalaVersion = sv, + platformSuffix = platformSuffix(), scalaOrganization = scalaOrganization(), scalacOptions = allScalacOptions(), compilerClasspath = scalaCompilerClasspath(), @@ -659,6 +660,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => (compileClasspath() ++ resolvedSemanticDbJavaPluginIvyDeps()).map(_.path), javacOptions = javacOpts, scalaVersion = sv, + platformSuffix = platformSuffix(), scalaOrganization = scalaOrganization(), scalacOptions = scalacOptions, compilerClasspath = scalaCompilerClasspath(), diff --git a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala index b604c673d27..d0c68dc4a13 100644 --- a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala +++ b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala @@ -20,6 +20,7 @@ import sbt.internal.util.{ConsoleAppender, ConsoleOut} import sbt.mill.SbtLoggerUtils import xsbti.compile.{ AnalysisContents, + AuxiliaryClassFiles, ClasspathOptions, CompileAnalysis, CompileOrder, @@ -27,7 +28,10 @@ import xsbti.compile.{ IncOptions, JavaTools, MiniSetup, - PreviousResult + PreviousResult, + ScalaJSFiles, + ScalaNativeFiles, + TastyFiles } import xsbti.{PathBasedFile, VirtualFile} @@ -303,6 +307,7 @@ class ZincWorkerImpl( compileClasspath = compileClasspath, javacOptions = javacOptions, scalacOptions = Nil, + platformSuffix = "", compilers = javaOnlyCompilers(javacOptions), reporter = reporter, reportCachedProblems = reportCachedProblems, @@ -316,6 +321,7 @@ class ZincWorkerImpl( compileClasspath: Agg[os.Path], javacOptions: Seq[String], scalaVersion: String, + platformSuffix: String, scalaOrganization: String, scalacOptions: Seq[String], compilerClasspath: Agg[PathRef], @@ -337,6 +343,7 @@ class ZincWorkerImpl( compileClasspath = compileClasspath, javacOptions = javacOptions, scalacOptions = scalacOptions, + platformSuffix = platformSuffix, compilers = compilers, reporter = reporter, reportCachedProblems: Boolean, @@ -420,6 +427,7 @@ class ZincWorkerImpl( compileClasspath: Agg[os.Path], javacOptions: Seq[String], scalacOptions: Seq[String], + platformSuffix: String, compilers: Compilers, reporter: Option[CompileProblemReporter], reportCachedProblems: Boolean, @@ -496,6 +504,25 @@ class ZincWorkerImpl( .map(path => converter.toVirtualFile(path.toNIO)) .toArray + val incOptions = { + val platformSpecificFiles: Array[AuxiliaryClassFiles] = platformSuffix match { + case s"_sjs$_" => Array(ScalaJSFiles.instance()) + case s"_native$_" => Array(ScalaNativeFiles.instance()) + case _ => Array.empty[AuxiliaryClassFiles] + } + + val scalaVersionSpecificFiles: Array[AuxiliaryClassFiles] = + if (ZincWorkerUtil.isDottyOrScala3(compilers.scalac().scalaInstance().version())) + Array(TastyFiles.instance()) + else + Array.empty[AuxiliaryClassFiles] + + val auxiliaryClassFiles: Array[AuxiliaryClassFiles] = + platformSpecificFiles ++ scalaVersionSpecificFiles + + IncOptions.of().withAuxiliaryClassFiles(auxiliaryClassFiles) + } + val inputs = ic.inputs( classpath = classpath, sources = virtualSources, @@ -512,7 +539,7 @@ class ZincWorkerImpl( skip = false, cacheFile = zincFile.toNIO, cache = new FreshCompilerCache, - incOptions = IncOptions.of(), + incOptions = incOptions, reporter = newReporter, progress = None, earlyAnalysisStore = None, From 104a212b020a28b0462aa82b9581af17abb57fd9 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Sun, 10 Mar 2024 12:16:28 +0100 Subject: [PATCH 02/12] Add test to assert that compilation fails after deleting dependency --- .../test/src/AuxiliaryClassFilesTests.scala | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala b/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala index e61be90f33f..fe8d3b97cce 100644 --- a/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala +++ b/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala @@ -22,6 +22,27 @@ object AuxiliaryClassFilesTests extends IntegrationTestSuite { assert(secondRun == Seq.empty) } + test("compilation fails when deleting a class used by other files") { + initWorkspace() + + os.write(wd / "app" / "src" / "bar.scala", "object bar { println(foo) }") + val firstRunSuccessful = eval("app.jvm.compile") + assert(firstRunSuccessful) + + val classes = wd / "out" / "app" / "jvm" / "compile.dest" / "classes" + val firstRun = os.list(classes).map(_.last) + + os.remove(wd / "app" / "src" / "foo.scala") + + val secondRunSuccessful = eval("app.jvm.compile") + assert(!secondRunSuccessful) + + val secondRun = os.list(classes).map(_.last) + + assert(firstRun == Seq("bar$.class", "bar.class", "bar.tasty", "foo$.class", "foo.class", "foo.tasty")) + assert(secondRun == Seq.empty) + } + test("nir files are deleted together with companion class files") { initWorkspace() eval("app.native.compile") From d29d96c65c6841b66130a7894fe9c9ad1d4efdad Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Sun, 10 Mar 2024 12:19:10 +0100 Subject: [PATCH 03/12] Assert that compilation succeeds in AuxiliaryClassFilesTests --- .../test/src/AuxiliaryClassFilesTests.scala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala b/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala index fe8d3b97cce..31729f10d56 100644 --- a/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala +++ b/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala @@ -7,14 +7,14 @@ object AuxiliaryClassFilesTests extends IntegrationTestSuite { val tests: Tests = Tests { test("tasty files are deleted together with companion class files") { initWorkspace() - eval("app.jvm.compile") + assert(eval("app.jvm.compile")) val classes = wd / "out" / "app" / "jvm" / "compile.dest" / "classes" val firstRun = os.list(classes).map(_.last) os.remove(wd / "app" / "src" / "foo.scala") - eval("app.jvm.compile") + assert(eval("app.jvm.compile")) val secondRun = os.list(classes).map(_.last) @@ -45,14 +45,14 @@ object AuxiliaryClassFilesTests extends IntegrationTestSuite { test("nir files are deleted together with companion class files") { initWorkspace() - eval("app.native.compile") + assert(eval("app.native.compile")) val classes = wd / "out" / "app" / "native" / "compile.dest" / "classes" val firstRun = os.list(classes).map(_.last) os.remove(wd / "app" / "src" / "foo.scala") - eval("app.native.compile") + assert(eval("app.native.compile")) val secondRun = os.list(classes).map(_.last) @@ -62,14 +62,14 @@ object AuxiliaryClassFilesTests extends IntegrationTestSuite { test("sjsir files are deleted together with companion class files") { initWorkspace() - eval("app.js.compile") + assert(eval("app.js.compile")) val classes = wd / "out" / "app" / "js" / "compile.dest" / "classes" val firstRun = os.list(classes).map(_.last) os.remove(wd / "app" / "src" / "foo.scala") - eval("app.js.compile") + assert(eval("app.js.compile")) val secondRun = os.list(classes).map(_.last) From 96a060cd43f989f59c1a0318f43db3e6984adac6 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Sun, 10 Mar 2024 12:43:14 +0100 Subject: [PATCH 04/12] Run Scalafmt --- .../test/src/AuxiliaryClassFilesTests.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala b/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala index 31729f10d56..8cf3966a3c7 100644 --- a/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala +++ b/integration/feature/auxiliary-class-files/test/src/AuxiliaryClassFilesTests.scala @@ -39,7 +39,14 @@ object AuxiliaryClassFilesTests extends IntegrationTestSuite { val secondRun = os.list(classes).map(_.last) - assert(firstRun == Seq("bar$.class", "bar.class", "bar.tasty", "foo$.class", "foo.class", "foo.tasty")) + assert(firstRun == Seq( + "bar$.class", + "bar.class", + "bar.tasty", + "foo$.class", + "foo.class", + "foo.tasty" + )) assert(secondRun == Seq.empty) } From 1565d6e6afd434dcd5d101caef5f89d7800b92f8 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 11 Mar 2024 14:28:49 +0100 Subject: [PATCH 05/12] Introduce auxiliaryClassFileExtensions in ScalaModule --- .../src/mill/scalajslib/ScalaJSModule.scala | 2 + .../src/mill/scalalib/api/ZincWorkerApi.scala | 16 +++---- scalalib/src/mill/scalalib/ScalaModule.scala | 16 +++++-- .../mill/scalalib/worker/ZincWorkerImpl.scala | 43 ++++++------------- .../scalanativelib/ScalaNativeModule.scala | 2 + 5 files changed, 36 insertions(+), 43 deletions(-) diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index bc627594361..bbfbee3834c 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -295,6 +295,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => )) } + override protected def auxiliaryClassFileExtensions: T[Seq[String]] = super.auxiliaryClassFileExtensions() :+ "sjsir" + } trait TestScalaJSModule extends ScalaJSModule with TestModule { diff --git a/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala b/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala index f0a1b103ef4..8338a931c16 100644 --- a/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala +++ b/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala @@ -56,14 +56,14 @@ trait ZincWorkerApi { compileClasspath: Agg[os.Path], javacOptions: Seq[String], scalaVersion: String, - platformSuffix: String, scalaOrganization: String, scalacOptions: Seq[String], compilerClasspath: Agg[PathRef], scalacPluginClasspath: Agg[PathRef], reporter: Option[CompileProblemReporter], reportCachedProblems: Boolean, - incrementalCompilation: Boolean + incrementalCompilation: Boolean, + auxiliaryClassFileExtensions: Seq[String] )(implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult] = compileMixed( upstreamCompileOutput = upstreamCompileOutput, @@ -71,14 +71,14 @@ trait ZincWorkerApi { compileClasspath = compileClasspath, javacOptions = javacOptions, scalaVersion = scalaVersion, - platformSuffix = platformSuffix, scalaOrganization = scalaOrganization, scalacOptions = scalacOptions, compilerClasspath = compilerClasspath, scalacPluginClasspath = scalacPluginClasspath, reporter = reporter, reportCachedProblems = reportCachedProblems, - incrementalCompilation = incrementalCompilation + incrementalCompilation = incrementalCompilation, + auxiliaryClassFileExtensions = auxiliaryClassFileExtensions ) /** Compile a mixed Scala/Java or Scala-only project */ @@ -102,14 +102,14 @@ trait ZincWorkerApi { compileClasspath = compileClasspath, javacOptions = javacOptions, scalaVersion = scalaVersion, - platformSuffix = "", scalaOrganization = scalaOrganization, scalacOptions = scalacOptions, compilerClasspath = compilerClasspath, scalacPluginClasspath = scalacPluginClasspath, reporter = reporter, reportCachedProblems = reportCachedProblems, - incrementalCompilation = true + incrementalCompilation = true, + auxiliaryClassFileExtensions = Seq.empty[String] ) /** Compile a mixed Scala/Java or Scala-only project */ @@ -134,14 +134,14 @@ trait ZincWorkerApi { compileClasspath = compileClasspath, javacOptions = javacOptions, scalaVersion = scalaVersion, - platformSuffix = "", scalaOrganization = scalaOrganization, scalacOptions = scalacOptions, compilerClasspath = compilerClasspath, scalacPluginClasspath = scalacPluginClasspath, reporter = reporter, reportCachedProblems = reportCachedProblems, - incrementalCompilation = incrementalCompilation + incrementalCompilation = incrementalCompilation, + auxiliaryClassFileExtensions = Seq.empty[String] ) def discoverMainClasses(compilationResult: CompilationResult): Seq[String] diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index 8974720a1c9..e4c36900897 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -292,14 +292,14 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => compileClasspath = compileClasspath().map(_.path), javacOptions = javacOptions(), scalaVersion = sv, - platformSuffix = platformSuffix(), scalaOrganization = scalaOrganization(), scalacOptions = allScalacOptions(), compilerClasspath = scalaCompilerClasspath(), scalacPluginClasspath = scalacPluginClasspath(), reporter = T.reporter.apply(hashCode), reportCachedProblems = zincReportCachedProblems(), - incrementalCompilation = zincIncrementalCompilation() + incrementalCompilation = zincIncrementalCompilation(), + auxiliaryClassFileExtensions = auxiliaryClassFileExtensions() ) } @@ -549,6 +549,14 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => else ZincWorkerUtil.scalaBinaryVersion(scalaVersion()) } + /** + * Files extensions that need to be managed by Zinc together with class files + */ + protected def auxiliaryClassFileExtensions: T[Seq[String]] = T { + if (ZincWorkerUtil.isScala3(scalaVersion())) Seq("tasty") + else Seq.empty[String] + } + override def artifactSuffix: T[String] = s"${platformSuffix()}_${artifactScalaVersion()}" override def artifactId: T[String] = artifactName() + artifactSuffix() @@ -660,14 +668,14 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => (compileClasspath() ++ resolvedSemanticDbJavaPluginIvyDeps()).map(_.path), javacOptions = javacOpts, scalaVersion = sv, - platformSuffix = platformSuffix(), scalaOrganization = scalaOrganization(), scalacOptions = scalacOptions, compilerClasspath = scalaCompilerClasspath(), scalacPluginClasspath = semanticDbPluginClasspath(), reporter = None, reportCachedProblems = zincReportCachedProblems(), - incrementalCompilation = zincIncrementalCompilation() + incrementalCompilation = zincIncrementalCompilation(), + auxiliaryClassFileExtensions = auxiliaryClassFileExtensions() ) .map(r => SemanticDbJavaModule.copySemanticdbFiles(r.classes.path, T.workspace, T.dest / "data") diff --git a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala index d0c68dc4a13..afcdb92c749 100644 --- a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala +++ b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala @@ -20,7 +20,7 @@ import sbt.internal.util.{ConsoleAppender, ConsoleOut} import sbt.mill.SbtLoggerUtils import xsbti.compile.{ AnalysisContents, - AuxiliaryClassFiles, + AuxiliaryClassFileExtension, ClasspathOptions, CompileAnalysis, CompileOrder, @@ -28,10 +28,7 @@ import xsbti.compile.{ IncOptions, JavaTools, MiniSetup, - PreviousResult, - ScalaJSFiles, - ScalaNativeFiles, - TastyFiles + PreviousResult } import xsbti.{PathBasedFile, VirtualFile} @@ -307,11 +304,11 @@ class ZincWorkerImpl( compileClasspath = compileClasspath, javacOptions = javacOptions, scalacOptions = Nil, - platformSuffix = "", compilers = javaOnlyCompilers(javacOptions), reporter = reporter, reportCachedProblems = reportCachedProblems, - incrementalCompilation = incrementalCompilation + incrementalCompilation = incrementalCompilation, + auxiliaryClassFileExtensions = Seq.empty[String] ) } @@ -321,14 +318,14 @@ class ZincWorkerImpl( compileClasspath: Agg[os.Path], javacOptions: Seq[String], scalaVersion: String, - platformSuffix: String, scalaOrganization: String, scalacOptions: Seq[String], compilerClasspath: Agg[PathRef], scalacPluginClasspath: Agg[PathRef], reporter: Option[CompileProblemReporter], reportCachedProblems: Boolean, - incrementalCompilation: Boolean + incrementalCompilation: Boolean, + auxiliaryClassFileExtensions: Seq[String] )(implicit ctx: ZincWorkerApi.Ctx): Result[CompilationResult] = { withCompilers( scalaVersion = scalaVersion, @@ -343,11 +340,11 @@ class ZincWorkerImpl( compileClasspath = compileClasspath, javacOptions = javacOptions, scalacOptions = scalacOptions, - platformSuffix = platformSuffix, compilers = compilers, reporter = reporter, reportCachedProblems: Boolean, - incrementalCompilation + incrementalCompilation, + auxiliaryClassFileExtensions ) } } @@ -427,11 +424,11 @@ class ZincWorkerImpl( compileClasspath: Agg[os.Path], javacOptions: Seq[String], scalacOptions: Seq[String], - platformSuffix: String, compilers: Compilers, reporter: Option[CompileProblemReporter], reportCachedProblems: Boolean, - incrementalCompilation: Boolean + incrementalCompilation: Boolean, + auxiliaryClassFileExtensions: Seq[String] )(implicit ctx: ZincWorkerApi.Ctx): Result[CompilationResult] = { os.makeDir.all(ctx.dest) @@ -504,24 +501,8 @@ class ZincWorkerImpl( .map(path => converter.toVirtualFile(path.toNIO)) .toArray - val incOptions = { - val platformSpecificFiles: Array[AuxiliaryClassFiles] = platformSuffix match { - case s"_sjs$_" => Array(ScalaJSFiles.instance()) - case s"_native$_" => Array(ScalaNativeFiles.instance()) - case _ => Array.empty[AuxiliaryClassFiles] - } - - val scalaVersionSpecificFiles: Array[AuxiliaryClassFiles] = - if (ZincWorkerUtil.isDottyOrScala3(compilers.scalac().scalaInstance().version())) - Array(TastyFiles.instance()) - else - Array.empty[AuxiliaryClassFiles] - - val auxiliaryClassFiles: Array[AuxiliaryClassFiles] = - platformSpecificFiles ++ scalaVersionSpecificFiles - - IncOptions.of().withAuxiliaryClassFiles(auxiliaryClassFiles) - } + val incOptions = + IncOptions.of().withAuxiliaryClassFiles(auxiliaryClassFileExtensions.map(new AuxiliaryClassFileExtension(_)).toArray) val inputs = ic.inputs( classpath = classpath, diff --git a/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala b/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala index 02fa7c6da26..73e655f686e 100644 --- a/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala +++ b/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala @@ -335,6 +335,8 @@ trait ScalaNativeModule extends ScalaModule { outer => } } + override protected def auxiliaryClassFileExtensions: T[Seq[String]] = super.auxiliaryClassFileExtensions() :+ "nir" + } trait TestScalaNativeModule extends ScalaNativeModule with TestModule { From dfee3791338b4ca6a1b92f67d48ae078c2a3ceda Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 11 Mar 2024 14:31:11 +0100 Subject: [PATCH 06/12] Run Scalafmt --- scalajslib/src/mill/scalajslib/ScalaJSModule.scala | 3 ++- .../worker/src/mill/scalalib/worker/ZincWorkerImpl.scala | 5 +++-- .../src/mill/scalanativelib/ScalaNativeModule.scala | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index bbfbee3834c..38bd20dddc4 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -295,7 +295,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => )) } - override protected def auxiliaryClassFileExtensions: T[Seq[String]] = super.auxiliaryClassFileExtensions() :+ "sjsir" + override protected def auxiliaryClassFileExtensions: T[Seq[String]] = + super.auxiliaryClassFileExtensions() :+ "sjsir" } diff --git a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala index afcdb92c749..4dec3759702 100644 --- a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala +++ b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala @@ -501,8 +501,9 @@ class ZincWorkerImpl( .map(path => converter.toVirtualFile(path.toNIO)) .toArray - val incOptions = - IncOptions.of().withAuxiliaryClassFiles(auxiliaryClassFileExtensions.map(new AuxiliaryClassFileExtension(_)).toArray) + val incOptions = IncOptions.of().withAuxiliaryClassFiles( + auxiliaryClassFileExtensions.map(new AuxiliaryClassFileExtension(_)).toArray + ) val inputs = ic.inputs( classpath = classpath, diff --git a/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala b/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala index 73e655f686e..d86c5032835 100644 --- a/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala +++ b/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala @@ -335,7 +335,8 @@ trait ScalaNativeModule extends ScalaModule { outer => } } - override protected def auxiliaryClassFileExtensions: T[Seq[String]] = super.auxiliaryClassFileExtensions() :+ "nir" + override protected def auxiliaryClassFileExtensions: T[Seq[String]] = + super.auxiliaryClassFileExtensions() :+ "nir" } From 753420186d65dc928aa9ce32d275fd3e2628207f Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 11 Mar 2024 14:48:08 +0100 Subject: [PATCH 07/12] Filter MiMa incompatibilities --- build.sc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.sc b/build.sc index d12fab87193..d535946c39d 100644 --- a/build.sc +++ b/build.sc @@ -438,6 +438,14 @@ trait MillStableScalaModule extends MillPublishScalaModule with Mima { // See https://github.com/com-lihaoyi/mill/pull/2739 ProblemFilter.exclude[ReversedMissingMethodProblem]( "mill.scalajslib.ScalaJSModule.mill$scalajslib$ScalaJSModule$$super$scalaLibraryIvyDeps" + ), + // See https://github.com/com-lihaoyi/mill/pull/3072 + ProblemFilter.exclude[ReversedMissingMethodProblem]( + "mill.scalajslib.ScalaJSModule.mill$scalajslib$ScalaJSModule$$super$auxiliaryClassFileExtensions" + ), + // See https://github.com/com-lihaoyi/mill/pull/3072 + ProblemFilter.exclude[ReversedMissingMethodProblem]( + "mill.scalanativelib.ScalaNativeModule.mill$scalanativelib$ScalaNativeModule$$super$auxiliaryClassFileExtensions" ) ) def mimaPreviousVersions: T[Seq[String]] = Settings.mimaBaseVersions From bbf02cb90c9f1cbb54921a167b0264b04d4012cc Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 11 Mar 2024 15:38:03 +0100 Subject: [PATCH 08/12] Move auxiliaryClassFileExtensions to JavaModule and make public --- scalajslib/src/mill/scalajslib/ScalaJSModule.scala | 2 +- scalalib/src/mill/scalalib/JavaModule.scala | 5 +++++ scalalib/src/mill/scalalib/ScalaModule.scala | 5 +---- .../src/mill/scalanativelib/ScalaNativeModule.scala | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index 38bd20dddc4..c572eefdd1a 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -295,7 +295,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => )) } - override protected def auxiliaryClassFileExtensions: T[Seq[String]] = + override def auxiliaryClassFileExtensions: T[Seq[String]] = super.auxiliaryClassFileExtensions() :+ "sjsir" } diff --git a/scalalib/src/mill/scalalib/JavaModule.scala b/scalalib/src/mill/scalalib/JavaModule.scala index 418d4ab75d0..6d08a306acf 100644 --- a/scalalib/src/mill/scalalib/JavaModule.scala +++ b/scalalib/src/mill/scalalib/JavaModule.scala @@ -1006,6 +1006,11 @@ trait JavaModule def forkWorkingDir: T[Path] = T { T.workspace } + /** + * Files extensions that need to be managed by Zinc together with class files + */ + def auxiliaryClassFileExtensions: T[Seq[String]] = T { Seq.empty[String] } + /** * @param all If `true` fetches also source dependencies */ diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index e4c36900897..008c4c708d1 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -549,10 +549,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => else ZincWorkerUtil.scalaBinaryVersion(scalaVersion()) } - /** - * Files extensions that need to be managed by Zinc together with class files - */ - protected def auxiliaryClassFileExtensions: T[Seq[String]] = T { + override def auxiliaryClassFileExtensions: T[Seq[String]] = T { if (ZincWorkerUtil.isScala3(scalaVersion())) Seq("tasty") else Seq.empty[String] } diff --git a/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala b/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala index d86c5032835..0e62d883f7c 100644 --- a/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala +++ b/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala @@ -335,7 +335,7 @@ trait ScalaNativeModule extends ScalaModule { outer => } } - override protected def auxiliaryClassFileExtensions: T[Seq[String]] = + override def auxiliaryClassFileExtensions: T[Seq[String]] = super.auxiliaryClassFileExtensions() :+ "nir" } From 4a3cef8c8a3566954ab646aa297012c64b0f1728 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 11 Mar 2024 16:09:38 +0100 Subject: [PATCH 09/12] Use `super.auxiliaryClassFileExtensions()` in ScalaModule --- build.sc | 4 ++++ scalalib/src/mill/scalalib/ScalaModule.scala | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/build.sc b/build.sc index d535946c39d..1f000c9caad 100644 --- a/build.sc +++ b/build.sc @@ -440,6 +440,10 @@ trait MillStableScalaModule extends MillPublishScalaModule with Mima { "mill.scalajslib.ScalaJSModule.mill$scalajslib$ScalaJSModule$$super$scalaLibraryIvyDeps" ), // See https://github.com/com-lihaoyi/mill/pull/3072 + ProblemFilter.exclude[ReversedMissingMethodProblem]( + "mill.scalalib.ScalaModule.mill$scalalib$ScalaModule$$super$auxiliaryClassFileExtensions" + ), + // See https://github.com/com-lihaoyi/mill/pull/3072 ProblemFilter.exclude[ReversedMissingMethodProblem]( "mill.scalajslib.ScalaJSModule.mill$scalajslib$ScalaJSModule$$super$auxiliaryClassFileExtensions" ), diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index 008c4c708d1..b26ec5e7478 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -550,8 +550,10 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => } override def auxiliaryClassFileExtensions: T[Seq[String]] = T { - if (ZincWorkerUtil.isScala3(scalaVersion())) Seq("tasty") - else Seq.empty[String] + super.auxiliaryClassFileExtensions() ++ ( + if (ZincWorkerUtil.isScala3(scalaVersion())) Seq("tasty") + else Seq.empty[String] + ) } override def artifactSuffix: T[String] = s"${platformSuffix()}_${artifactScalaVersion()}" From 52e6675f386fb98a095712f96d70e27107bf1ba5 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 11 Mar 2024 20:00:35 +0100 Subject: [PATCH 10/12] Rename `auxiliaryClassFileExtensions` to `zincAuxiliaryClassFileExtensions` --- build.sc | 6 +++--- scalajslib/src/mill/scalajslib/ScalaJSModule.scala | 4 ++-- scalalib/src/mill/scalalib/JavaModule.scala | 2 +- scalalib/src/mill/scalalib/ScalaModule.scala | 8 ++++---- .../src/mill/scalanativelib/ScalaNativeModule.scala | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build.sc b/build.sc index 1f000c9caad..c7935231fc1 100644 --- a/build.sc +++ b/build.sc @@ -441,15 +441,15 @@ trait MillStableScalaModule extends MillPublishScalaModule with Mima { ), // See https://github.com/com-lihaoyi/mill/pull/3072 ProblemFilter.exclude[ReversedMissingMethodProblem]( - "mill.scalalib.ScalaModule.mill$scalalib$ScalaModule$$super$auxiliaryClassFileExtensions" + "mill.scalalib.ScalaModule.mill$scalalib$ScalaModule$$super$zincAuxiliaryClassFileExtensions" ), // See https://github.com/com-lihaoyi/mill/pull/3072 ProblemFilter.exclude[ReversedMissingMethodProblem]( - "mill.scalajslib.ScalaJSModule.mill$scalajslib$ScalaJSModule$$super$auxiliaryClassFileExtensions" + "mill.scalajslib.ScalaJSModule.mill$scalajslib$ScalaJSModule$$super$zincAuxiliaryClassFileExtensions" ), // See https://github.com/com-lihaoyi/mill/pull/3072 ProblemFilter.exclude[ReversedMissingMethodProblem]( - "mill.scalanativelib.ScalaNativeModule.mill$scalanativelib$ScalaNativeModule$$super$auxiliaryClassFileExtensions" + "mill.scalanativelib.ScalaNativeModule.mill$scalanativelib$ScalaNativeModule$$super$zincAuxiliaryClassFileExtensions" ) ) def mimaPreviousVersions: T[Seq[String]] = Settings.mimaBaseVersions diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index c572eefdd1a..cd6ac0baaba 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -295,8 +295,8 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => )) } - override def auxiliaryClassFileExtensions: T[Seq[String]] = - super.auxiliaryClassFileExtensions() :+ "sjsir" + override def zincAuxiliaryClassFileExtensions: T[Seq[String]] = + super.zincAuxiliaryClassFileExtensions() :+ "sjsir" } diff --git a/scalalib/src/mill/scalalib/JavaModule.scala b/scalalib/src/mill/scalalib/JavaModule.scala index 6d08a306acf..132e9e31f6a 100644 --- a/scalalib/src/mill/scalalib/JavaModule.scala +++ b/scalalib/src/mill/scalalib/JavaModule.scala @@ -1009,7 +1009,7 @@ trait JavaModule /** * Files extensions that need to be managed by Zinc together with class files */ - def auxiliaryClassFileExtensions: T[Seq[String]] = T { Seq.empty[String] } + def zincAuxiliaryClassFileExtensions: T[Seq[String]] = T { Seq.empty[String] } /** * @param all If `true` fetches also source dependencies diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index b26ec5e7478..c8c884238f1 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -299,7 +299,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => reporter = T.reporter.apply(hashCode), reportCachedProblems = zincReportCachedProblems(), incrementalCompilation = zincIncrementalCompilation(), - auxiliaryClassFileExtensions = auxiliaryClassFileExtensions() + auxiliaryClassFileExtensions = zincAuxiliaryClassFileExtensions() ) } @@ -549,8 +549,8 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => else ZincWorkerUtil.scalaBinaryVersion(scalaVersion()) } - override def auxiliaryClassFileExtensions: T[Seq[String]] = T { - super.auxiliaryClassFileExtensions() ++ ( + override def zincAuxiliaryClassFileExtensions: T[Seq[String]] = T { + super.zincAuxiliaryClassFileExtensions() ++ ( if (ZincWorkerUtil.isScala3(scalaVersion())) Seq("tasty") else Seq.empty[String] ) @@ -674,7 +674,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => reporter = None, reportCachedProblems = zincReportCachedProblems(), incrementalCompilation = zincIncrementalCompilation(), - auxiliaryClassFileExtensions = auxiliaryClassFileExtensions() + auxiliaryClassFileExtensions = zincAuxiliaryClassFileExtensions() ) .map(r => SemanticDbJavaModule.copySemanticdbFiles(r.classes.path, T.workspace, T.dest / "data") diff --git a/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala b/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala index 0e62d883f7c..d934ada850c 100644 --- a/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala +++ b/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala @@ -335,8 +335,8 @@ trait ScalaNativeModule extends ScalaModule { outer => } } - override def auxiliaryClassFileExtensions: T[Seq[String]] = - super.auxiliaryClassFileExtensions() :+ "nir" + override def zincAuxiliaryClassFileExtensions: T[Seq[String]] = + super.zincAuxiliaryClassFileExtensions() :+ "nir" } From b95b9f8571d291c0650fe16fa5a0d9c507d11e9e Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 11 Mar 2024 21:14:35 +0100 Subject: [PATCH 11/12] Improve scaladoc for auxiliaryClassFileExtensions Co-authored-by: Tobias Roeser --- scalalib/src/mill/scalalib/JavaModule.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scalalib/src/mill/scalalib/JavaModule.scala b/scalalib/src/mill/scalalib/JavaModule.scala index 132e9e31f6a..98af259fa94 100644 --- a/scalalib/src/mill/scalalib/JavaModule.scala +++ b/scalalib/src/mill/scalalib/JavaModule.scala @@ -1007,7 +1007,9 @@ trait JavaModule def forkWorkingDir: T[Path] = T { T.workspace } /** - * Files extensions that need to be managed by Zinc together with class files + * Files extensions that need to be managed by Zinc together with class files. + * This means, if zinc needs to remove a class file, it will also remove files + * which match the class file basename and a listed file extension. */ def zincAuxiliaryClassFileExtensions: T[Seq[String]] = T { Seq.empty[String] } From af161cd84ff584c907a9cd0eb38a844e249e06ed Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 11 Mar 2024 21:14:49 +0100 Subject: [PATCH 12/12] Fix typo in `@deprecated` message Co-authored-by: Tobias Roeser --- scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala b/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala index 8338a931c16..04dfc1d0e98 100644 --- a/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala +++ b/scalalib/api/src/mill/scalalib/api/ZincWorkerApi.scala @@ -113,7 +113,7 @@ trait ZincWorkerApi { ) /** Compile a mixed Scala/Java or Scala-only project */ - @deprecated("Use override with `platformSuffix` parameter", "Mill 0.11.8") + @deprecated("Use override with `auxiliaryClassFileExtensions` parameter", "Mill 0.11.8") def compileMixed( upstreamCompileOutput: Seq[CompilationResult], sources: Agg[os.Path],