Skip to content

Commit c54f0db

Browse files
authored
WIP Cleanup zinc server (#6128)
1 parent bfc34c8 commit c54f0db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+651
-1669
lines changed

ci/mill-bootstrap.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ index 5c388fafb6e..31763326edf 100644
88
testParallelism(),
99
- testLogLevel()
1010
+ testLogLevel(),
11-
+ jvmWorker = jvmWorker().worker()
11+
+ jvmWorker = jvmWorker().internalWorker()
1212
)
1313
testModuleUtil.runTests()
1414
}

contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ trait HelloWorldTests extends TestSuite {
8181
}
8282
test("compileTwirl") {
8383
skipUnsupportedVersions {
84-
UnitTester(HelloWorld, resourcePath / "hello-world", debugEnabled = true).scoped { eval =>
84+
UnitTester(HelloWorld, resourcePath / "hello-world").scoped { eval =>
8585
val res = eval.apply(HelloWorld.core.compileTwirl)
8686
assert(res.isRight)
8787
val Right(result) = res: @unchecked

integration/ide/bsp-server/resources/snapshots/logging

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
[1-buildInitialize] Entered buildInitialize
44
[1-buildInitialize] Got client semanticdbVersion: * Enabling SemanticDB support.
55
[1-buildInitialize] buildInitialize took * msec
6-
[bsp-init-mill-build/build.mill-59] [info] compiling * Scala sources to * ...
7-
[bsp-init-mill-build/build.mill-59] [info] done compiling
8-
[bsp-init-build.mill-59] [info] compiling * Scala sources to * ...
9-
[bsp-init-build.mill-59] [info] done compiling
10-
[bsp-init-106] [info] compiling * Scala source to * ...
11-
[bsp-init-106] [info] done compiling
6+
[bsp-init-mill-build/build.mill-60] [info] compiling * Scala sources to * ...
7+
[bsp-init-mill-build/build.mill-60] [info] done compiling
8+
[bsp-init-build.mill-60] [info] compiling * Scala sources to * ...
9+
[bsp-init-build.mill-60] [info] done compiling
10+
[bsp-init-107] [info] compiling * Scala source to * ...
11+
[bsp-init-107] [info] done compiling
1212
[bsp-init] BSP disabled for target file:///workspace/dependsOnSkipped because of its dependencies file:///workspace/skipped
1313
[bsp-init] BSP disabled for target file:///workspace/skipped via BspModuleApi#enableBsp
1414
[bsp-init] SNAPSHOT
@@ -37,12 +37,12 @@
3737
[4-compile] buildTargetCompile took * msec
3838
[5-compile] Entered buildTargetCompile
3939
[5-compile] Evaluating 1 task
40-
[5-compile-55] [info] compiling * Scala source to * ...
41-
[5-compile-55] [error] *:2:3: not found: value nope
42-
[5-compile-55] [error] nope
43-
[5-compile-55] [error] ^
44-
[5-compile-55] [error] one error found
45-
[5-compile-55] errored.compilation-error.semanticDbDataDetailed task failed
40+
[5-compile-56] [info] compiling * Scala source to * ...
41+
[5-compile-56] [error] *:2:3: not found: value nope
42+
[5-compile-56] [error] nope
43+
[5-compile-56] [error] ^
44+
[5-compile-56] [error] one error found
45+
[5-compile-56] errored.compilation-error.semanticDbDataDetailed task failed
4646
[5-compile] Done
4747
[5-compile] buildTargetCompile took * msec
4848
[6-compile] Entered buildTargetCompile

libs/androidlib/src/mill/androidlib/AndroidModule.scala

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -516,22 +516,21 @@ trait AndroidModule extends JavaModule { outer =>
516516
* The Java compiled classes of [[androidResources]]
517517
*/
518518
def androidCompiledRClasses: T[CompilationResult] = Task(persistent = true) {
519-
val jOpts = JavaCompilerOptions(javacOptions() ++ mandatoryJavacOptions())
520-
jvmWorker()
521-
.internalWorker()
522-
.compileJava(
523-
ZincCompileJava(
524-
upstreamCompileOutput = upstreamCompileOutput(),
525-
sources = androidLibsRClasses().map(_.path),
526-
compileClasspath = Seq.empty,
527-
javacOptions = jOpts.compiler,
528-
incrementalCompilation = true
529-
),
530-
javaHome = javaHome().map(_.path),
531-
javaRuntimeOptions = jOpts.runtime,
532-
reporter = Task.reporter.apply(hashCode),
533-
reportCachedProblems = zincReportCachedProblems()
534-
)
519+
val jOpts = JavaCompilerOptions.split(javacOptions() ++ mandatoryJavacOptions())
520+
val worker = jvmWorker().internalWorker()
521+
worker.apply(
522+
ZincCompileJava(
523+
upstreamCompileOutput = upstreamCompileOutput(),
524+
sources = androidLibsRClasses().map(_.path),
525+
compileClasspath = Seq.empty,
526+
javacOptions = jOpts.compiler,
527+
incrementalCompilation = true
528+
),
529+
javaHome = javaHome().map(_.path),
530+
javaRuntimeOptions = jOpts.runtime,
531+
reporter = Task.reporter.apply(hashCode),
532+
reportCachedProblems = zincReportCachedProblems()
533+
)
535534
}
536535

537536
def androidLibRClasspath: T[Seq[PathRef]] = Task {
@@ -729,10 +728,10 @@ trait AndroidModule extends JavaModule { outer =>
729728

730729
val rJar = Task.dest / "R.jar"
731730

732-
val jOpts = JavaCompilerOptions(javacOptions() ++ mandatoryJavacOptions())
733-
val classesDest = jvmWorker()
734-
.internalWorker()
735-
.compileJava(
731+
val jOpts = JavaCompilerOptions.split(javacOptions() ++ mandatoryJavacOptions())
732+
val worker = jvmWorker().internalWorker()
733+
val classesDest = worker
734+
.apply(
736735
ZincCompileJava(
737736
upstreamCompileOutput = upstreamCompileOutput(),
738737
sources = sources.map(_.path),

libs/javalib/api/src/mill/javalib/api/JvmWorkerApi.scala

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,4 @@ trait JvmWorkerApi {
4747
javaHome: Option[os.Path],
4848
args: Seq[String]
4949
)(using ctx: JvmWorkerApi.Ctx): Boolean
50-
51-
def discoverTests(
52-
value: mill.javalib.api.internal.ZincDiscoverTests,
53-
javaHome: Option[os.Path]
54-
)(using ctx: JvmWorkerApi.Ctx): Seq[String] = Nil
55-
56-
def getTestTasks(
57-
value: mill.javalib.api.internal.ZincGetTestTasks,
58-
javaHome: Option[os.Path]
59-
)(using ctx: JvmWorkerApi.Ctx): Seq[String] = Nil
60-
61-
def discoverJunit5Tests(
62-
value: mill.javalib.api.internal.ZincDiscoverJunit5Tests,
63-
javaHome: Option[os.Path]
64-
)(using ctx: JvmWorkerApi.Ctx): Seq[String] = Nil
6550
}

libs/javalib/api/src/mill/javalib/api/internal/JvmWorkerApi.scala renamed to libs/javalib/api/src/mill/javalib/api/internal/InternalJvmWorkerApi.scala

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,19 @@ import mill.api.daemon.internal.CompileProblemReporter
55
import mill.javalib.api.CompilationResult
66
import mill.javalib.api.JvmWorkerApi as PublicJvmWorkerApi
77
import mill.javalib.api.JvmWorkerApi.Ctx
8+
import mill.javalib.api.internal.ZincOperation
89
import os.Path
910

10-
trait JvmWorkerApi extends PublicJvmWorkerApi {
11+
trait InternalJvmWorkerApi extends PublicJvmWorkerApi {
1112

1213
/** Compile a Java-only project. */
13-
def compileJava(
14-
op: ZincCompileJava,
14+
def apply(
15+
op: ZincOperation,
1516
javaHome: Option[os.Path],
16-
javaRuntimeOptions: JavaRuntimeOptions,
17-
reporter: Option[CompileProblemReporter],
18-
reportCachedProblems: Boolean
19-
)(using context: JvmWorkerApi.Ctx): Result[CompilationResult]
20-
21-
/** Compile a mixed Scala/Java or Scala-only project. */
22-
def compileMixed(
23-
op: ZincCompileMixed,
24-
javaHome: Option[os.Path],
25-
javaRuntimeOptions: JavaRuntimeOptions,
26-
reporter: Option[CompileProblemReporter],
27-
reportCachedProblems: Boolean
28-
)(using context: JvmWorkerApi.Ctx): Result[CompilationResult]
29-
30-
/** Compiles a Scaladoc jar. */
31-
def scaladocJar(
32-
op: ZincScaladocJar,
33-
javaHome: Option[os.Path]
34-
)(using context: JvmWorkerApi.Ctx): Boolean
17+
javaRuntimeOptions: Seq[String] = Nil,
18+
reporter: Option[CompileProblemReporter] = None,
19+
reportCachedProblems: Boolean = false
20+
)(using context: InternalJvmWorkerApi.Ctx): op.Response
3521

3622
// public API forwarder
3723
override def compileJava(
@@ -44,8 +30,8 @@ trait JvmWorkerApi extends PublicJvmWorkerApi {
4430
reportCachedProblems: Boolean,
4531
incrementalCompilation: Boolean
4632
)(using ctx: Ctx): Result[CompilationResult] = {
47-
val jOpts = JavaCompilerOptions(javacOptions)
48-
compileJava(
33+
val jOpts = JavaCompilerOptions.split(javacOptions)
34+
apply(
4935
ZincCompileJava(
5036
upstreamCompileOutput = upstreamCompileOutput,
5137
sources = sources,
@@ -77,8 +63,8 @@ trait JvmWorkerApi extends PublicJvmWorkerApi {
7763
incrementalCompilation: Boolean,
7864
auxiliaryClassFileExtensions: Seq[String]
7965
)(using ctx: Ctx): Result[CompilationResult] = {
80-
val jOpts = JavaCompilerOptions(javacOptions)
81-
compileMixed(
66+
val jOpts = JavaCompilerOptions.split(javacOptions)
67+
apply(
8268
ZincCompileMixed(
8369
upstreamCompileOutput = upstreamCompileOutput,
8470
sources = sources,
@@ -108,18 +94,21 @@ trait JvmWorkerApi extends PublicJvmWorkerApi {
10894
javaHome: Option[Path],
10995
args: Seq[String]
11096
)(using ctx: Ctx): Boolean = {
111-
scaladocJar(
97+
apply(
11298
ZincScaladocJar(
11399
scalaVersion = scalaVersion,
114100
scalaOrganization = scalaOrganization,
115101
compilerClasspath = compilerClasspath,
116102
scalacPluginClasspath = scalacPluginClasspath,
117103
args = args
118104
),
119-
javaHome = javaHome
105+
javaHome = javaHome,
106+
javaRuntimeOptions = Nil,
107+
None,
108+
false
120109
)
121110
}
122111
}
123-
object JvmWorkerApi {
112+
object InternalJvmWorkerApi {
124113
type Ctx = PublicJvmWorkerApi.Ctx
125114
}
Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
11
package mill.javalib.api.internal
22

3-
/** Java compiler options, without the `-J` options (the Java runtime options). */
4-
case class JavaCompilerOptions private (options: Seq[String]) {
5-
{
6-
val runtimeOptions = options.filter(_.startsWith("-J"))
7-
if (runtimeOptions.nonEmpty) throw new IllegalArgumentException(
8-
s"Providing Java runtime options to javac is not supported."
9-
)
10-
}
11-
}
123
object JavaCompilerOptions {
13-
given rw: upickle.ReadWriter[JavaCompilerOptions] =
14-
summon[upickle.ReadWriter[Seq[String]]]
15-
.bimap(_.options, new JavaCompilerOptions(_))
16-
17-
def empty: JavaCompilerOptions = new JavaCompilerOptions(Seq.empty)
18-
19-
/** Constructs without filtering. */
20-
def unsafe(options: Seq[String]): JavaCompilerOptions = new JavaCompilerOptions(options)
21-
22-
def apply(options: Seq[String]): (runtime: JavaRuntimeOptions, compiler: JavaCompilerOptions) = {
4+
def split(options: Seq[String]): (runtime: Seq[String], compiler: Seq[String]) = {
235
val prefix = "-J"
246
val (runtimeOptions0, compilerOptions) = options.partition(_.startsWith(prefix))
25-
val runtimeOptions = JavaRuntimeOptions(runtimeOptions0.map(_.drop(prefix.length)))
26-
(runtimeOptions, new JavaCompilerOptions(compilerOptions))
7+
val runtimeOptions = runtimeOptions0.map(_.drop(prefix.length))
8+
(runtimeOptions, compilerOptions)
279
}
2810
}
29-
30-
/** Options that are passed to the Java runtime. */
31-
case class JavaRuntimeOptions(options: Seq[String])

libs/javalib/api/src/mill/javalib/api/internal/zinc_operations.scala

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,37 @@ package mill.javalib.api.internal
33
import mill.api.PathRef
44
import mill.javalib.api.CompilationResult
55
import mill.api.JsonFormatters.*
6+
import mill.api.daemon.Result
7+
8+
sealed trait ZincOperation extends mill.rpc.MillRpcChannel.Message derives upickle.ReadWriter {}
69

710
/** Compiles Java-only sources. */
811
case class ZincCompileJava(
912
upstreamCompileOutput: Seq[CompilationResult],
1013
sources: Seq[os.Path],
1114
compileClasspath: Seq[os.Path],
12-
javacOptions: JavaCompilerOptions,
15+
javacOptions: Seq[String],
1316
incrementalCompilation: Boolean
14-
) derives upickle.ReadWriter
17+
) extends ZincOperation {
18+
type Response = Result[CompilationResult]
19+
}
1520

1621
/** Compiles Java and Scala sources. */
1722
case class ZincCompileMixed(
1823
upstreamCompileOutput: Seq[CompilationResult],
1924
sources: Seq[os.Path],
2025
compileClasspath: Seq[os.Path],
21-
javacOptions: JavaCompilerOptions,
26+
javacOptions: Seq[String],
2227
scalaVersion: String,
2328
scalaOrganization: String,
2429
scalacOptions: Seq[String],
2530
compilerClasspath: Seq[PathRef],
2631
scalacPluginClasspath: Seq[PathRef],
2732
incrementalCompilation: Boolean,
2833
auxiliaryClassFileExtensions: Seq[String]
29-
) derives upickle.ReadWriter
34+
) extends ZincOperation {
35+
type Response = Result[CompilationResult]
36+
}
3037

3138
/** Creates a Scaladoc jar. */
3239
case class ZincScaladocJar(
@@ -35,21 +42,25 @@ case class ZincScaladocJar(
3542
compilerClasspath: Seq[PathRef],
3643
scalacPluginClasspath: Seq[PathRef],
3744
args: Seq[String]
38-
) derives upickle.ReadWriter
45+
) extends ZincOperation {
3946

40-
case class ZincDiscoverTests(runCp: Seq[os.Path], testCp: Seq[os.Path], framework: String)
41-
derives upickle.ReadWriter
47+
type Response = Boolean
48+
}
4249

50+
case class ZincDiscoverTests(runCp: Seq[os.Path], testCp: Seq[os.Path], framework: String)
51+
extends ZincOperation {
52+
type Response = Seq[String]
53+
}
4354
case class ZincGetTestTasks(
4455
runCp: Seq[os.Path],
4556
testCp: Seq[os.Path],
4657
framework: String,
4758
selectors: Seq[String],
4859
args: Seq[String]
49-
) derives upickle.ReadWriter
60+
) extends ZincOperation { type Response = Seq[String] }
5061

5162
case class ZincDiscoverJunit5Tests(
5263
runCp: Seq[os.Path],
5364
testCp: Seq[os.Path],
5465
classesDir: Option[os.Path]
55-
) derives upickle.ReadWriter
66+
) extends ZincOperation { type Response = Seq[String] }

libs/javalib/api/test/src/mill/javalib/api/internal/JavaCompilerOptionsTests.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import utest.*
55
object JavaCompilerOptionsTests extends TestSuite {
66
val tests = Tests {
77
test("apply") {
8-
val options = JavaCompilerOptions(Seq(
8+
val options = JavaCompilerOptions.split(Seq(
99
"1",
1010
"2",
1111
"-J-Xmx1g",
@@ -18,16 +18,16 @@ object JavaCompilerOptionsTests extends TestSuite {
1818
))
1919

2020
assert(
21-
options.runtime == JavaRuntimeOptions(Seq(
21+
options.runtime == Seq(
2222
"-Xmx1g",
2323
"-Dfoo=bar"
2424
// "-XDcompilePolicy=simple",
2525
// "-processorpath", "foo",
2626
// "-Xplugin:ErrorProne -XepAllErrorsAsWarnings"
27-
))
27+
)
2828
)
2929

30-
assert(options.compiler == JavaCompilerOptions.unsafe(Seq("1", "2", "3", "4")))
30+
assert(options.compiler == Seq("1", "2", "3", "4"))
3131
}
3232
}
3333
}

libs/javalib/package.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ object `package` extends MillStableScalaModule {
6060
}
6161

6262
object api extends MillStableScalaModule with BuildInfo {
63-
def moduleDeps = Seq(build.core.api)
63+
def moduleDeps = Seq(build.core.api, build.libs.rpc)
6464
def buildInfoPackageName = "mill.javalib.api"
6565
def buildInfoObjectName = "Versions"
6666

0 commit comments

Comments
 (0)