Skip to content

Commit 789e684

Browse files
authored
Split MillMain into MillNoDaemonMain and MillMain0 (#5162)
1 parent 8ef3e1d commit 789e684

File tree

6 files changed

+95
-39
lines changed

6 files changed

+95
-39
lines changed

example/package.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ $txt
269269
if (seenCode) ""
270270
else {
271271
val exampleDashed = examplePath.segments.mkString("-")
272-
val download =
272+
val download =
273273
s"{mill-download-url}/mill-dist-${build.millVersion()}-$exampleDashed.zip[download]"
274274
val browse = s"{mill-example-url}/$examplePath[browse]"
275275
s".build.mill ($download, $browse)"

runner/daemon/src/mill/daemon/MillDaemonMain.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import mill.client.ClientUtil
55
import mill.client.lock.{DoubleLock, Lock, Locks}
66
import mill.constants.{OutFiles, DaemonFiles}
77
import sun.misc.{Signal, SignalHandler}
8+
import scala.jdk.CollectionConverters.*
89

910
import scala.util.Try
1011

@@ -52,7 +53,7 @@ class MillDaemonMain(
5253
val out = os.Path(OutFiles.out, mill.define.BuildCtx.workspaceRoot)
5354

5455
val outLock = new DoubleLock(
55-
MillMain.outMemoryLock,
56+
MillMain0.outMemoryLock,
5657
Lock.file((out / OutFiles.millOutLock).toString)
5758
)
5859

@@ -67,7 +68,7 @@ class MillDaemonMain(
6768
initialSystemProperties: Map[String, String],
6869
systemExit: Int => Nothing
6970
): (Boolean, RunnerState) = {
70-
try MillMain.main0(
71+
try MillMain0.main0(
7172
args = args,
7273
stateCache = stateCache,
7374
mainInteractive = mainInteractive,
@@ -80,6 +81,6 @@ class MillDaemonMain(
8081
daemonDir = daemonDir,
8182
outLock = outLock
8283
)
83-
catch MillMain.handleMillException(streams.err, stateCache)
84+
catch MillMain0.handleMillException(streams.err, stateCache)
8485
}
8586
}

runner/daemon/src/mill/daemon/MillMain.scala renamed to runner/daemon/src/mill/daemon/MillMain0.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import scala.util.control.NonFatal
2121
import scala.util.{Properties, Using}
2222

2323
@internal
24-
object MillMain {
24+
object MillMain0 {
2525

2626
def handleMillException[T](
2727
err: PrintStream,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package mill.daemon
2+
3+
import mill.client.lock.{DoubleLock, Lock}
4+
import mill.constants.{DaemonFiles, OutFiles, Util}
5+
import mill.daemon.MillMain0.{handleMillException, main0, outMemoryLock}
6+
import mill.define.BuildCtx
7+
import mill.server.Server
8+
import scala.jdk.CollectionConverters._
9+
import scala.util.Properties
10+
11+
object MillNoDaemonMain {
12+
def main(args: Array[String]): Unit = mill.define.SystemStreams.withTopLevelSystemStreamProxy {
13+
val initialSystemStreams = mill.define.SystemStreams.original
14+
15+
if (Properties.isWin && Util.hasConsole())
16+
io.github.alexarchambault.windowsansi.WindowsAnsi.setup()
17+
18+
val processId = Server.computeProcessId()
19+
val out = os.Path(OutFiles.out, BuildCtx.workspaceRoot)
20+
Server.watchProcessIdFile(
21+
out / OutFiles.millNoDaemon / processId / DaemonFiles.processId,
22+
processId,
23+
running = () => true,
24+
exit = msg => {
25+
System.err.println(msg)
26+
System.exit(0)
27+
}
28+
)
29+
30+
val outLock = new DoubleLock(
31+
outMemoryLock,
32+
Lock.file((out / OutFiles.millOutLock).toString)
33+
)
34+
35+
val daemonDir = os.Path(args.head)
36+
val (result, _) =
37+
try main0(
38+
args = args.tail,
39+
stateCache = RunnerState.empty,
40+
mainInteractive = mill.constants.Util.hasConsole(),
41+
streams0 = initialSystemStreams,
42+
env = System.getenv().asScala.toMap,
43+
setIdle = _ => (),
44+
userSpecifiedProperties0 = Map(),
45+
initialSystemProperties = sys.props.toMap,
46+
systemExit = i => sys.exit(i),
47+
daemonDir = daemonDir,
48+
outLock = outLock
49+
)
50+
catch handleMillException(initialSystemStreams.err, ())
51+
52+
System.exit(if (result) 0 else 1)
53+
}
54+
55+
}

runner/daemon/test/src/mill/daemon/MillMainTests.scala

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,57 +17,57 @@ object MillMainTests extends TestSuite {
1717
test("Parsing --jobs/-j flag") {
1818

1919
test("parse none") {
20-
assert(MillMain.parseThreadCount(None, 10) == Result.Success(10))
20+
assert(MillMain0.parseThreadCount(None, 10) == Result.Success(10))
2121
}
2222

2323
test("parse int number") {
24-
assert(MillMain.parseThreadCount(Some("1"), 10) == Result.Success(1))
25-
assert(MillMain.parseThreadCount(Some("11"), 10) == Result.Success(11))
26-
27-
assertParseErr(MillMain.parseThreadCount(Some("1.0"), 10), "Failed to find a int number")
28-
assertParseErr(MillMain.parseThreadCount(Some("1.1"), 10), "Failed to find a int number")
29-
assertParseErr(MillMain.parseThreadCount(Some("0.1"), 10), "Failed to find a int number")
30-
assert(MillMain.parseThreadCount(Some("0"), 10) == Result.Success(10))
31-
assert(MillMain.parseThreadCount(Some("-1"), 10) == Result.Success(1))
24+
assert(MillMain0.parseThreadCount(Some("1"), 10) == Result.Success(1))
25+
assert(MillMain0.parseThreadCount(Some("11"), 10) == Result.Success(11))
26+
27+
assertParseErr(MillMain0.parseThreadCount(Some("1.0"), 10), "Failed to find a int number")
28+
assertParseErr(MillMain0.parseThreadCount(Some("1.1"), 10), "Failed to find a int number")
29+
assertParseErr(MillMain0.parseThreadCount(Some("0.1"), 10), "Failed to find a int number")
30+
assert(MillMain0.parseThreadCount(Some("0"), 10) == Result.Success(10))
31+
assert(MillMain0.parseThreadCount(Some("-1"), 10) == Result.Success(1))
3232
}
3333

3434
test("parse fraction number") {
35-
assert(MillMain.parseThreadCount(Some("0.5C"), 10) == Result.Success(5))
36-
assert(MillMain.parseThreadCount(Some("0.54C"), 10) == Result.Success(5))
37-
assert(MillMain.parseThreadCount(Some("0.59C"), 10) == Result.Success(5))
38-
assert(MillMain.parseThreadCount(Some(".5C"), 10) == Result.Success(5))
39-
assert(MillMain.parseThreadCount(Some("1.0C"), 10) == Result.Success(10))
40-
assert(MillMain.parseThreadCount(Some("1.5C"), 10) == Result.Success(15))
41-
assert(MillMain.parseThreadCount(Some("0.09C"), 10) == Result.Success(1))
42-
assert(MillMain.parseThreadCount(Some("-0.5C"), 10) == Result.Success(1))
35+
assert(MillMain0.parseThreadCount(Some("0.5C"), 10) == Result.Success(5))
36+
assert(MillMain0.parseThreadCount(Some("0.54C"), 10) == Result.Success(5))
37+
assert(MillMain0.parseThreadCount(Some("0.59C"), 10) == Result.Success(5))
38+
assert(MillMain0.parseThreadCount(Some(".5C"), 10) == Result.Success(5))
39+
assert(MillMain0.parseThreadCount(Some("1.0C"), 10) == Result.Success(10))
40+
assert(MillMain0.parseThreadCount(Some("1.5C"), 10) == Result.Success(15))
41+
assert(MillMain0.parseThreadCount(Some("0.09C"), 10) == Result.Success(1))
42+
assert(MillMain0.parseThreadCount(Some("-0.5C"), 10) == Result.Success(1))
4343
assertParseErr(
44-
MillMain.parseThreadCount(Some("0.5.4C"), 10),
44+
MillMain0.parseThreadCount(Some("0.5.4C"), 10),
4545
"Failed to find a float number before \"C\""
4646
)
4747
}
4848

4949
test("parse subtraction") {
50-
assert(MillMain.parseThreadCount(Some("C-1"), 10) == Result.Success(9))
51-
assert(MillMain.parseThreadCount(Some("C-10"), 10) == Result.Success(1))
52-
assert(MillMain.parseThreadCount(Some("C-11"), 10) == Result.Success(1))
50+
assert(MillMain0.parseThreadCount(Some("C-1"), 10) == Result.Success(9))
51+
assert(MillMain0.parseThreadCount(Some("C-10"), 10) == Result.Success(1))
52+
assert(MillMain0.parseThreadCount(Some("C-11"), 10) == Result.Success(1))
5353

5454
assertParseErr(
55-
MillMain.parseThreadCount(Some("C-1.1"), 10),
55+
MillMain0.parseThreadCount(Some("C-1.1"), 10),
5656
"Failed to find a int number after \"C-\""
5757
)
5858
assertParseErr(
59-
MillMain.parseThreadCount(Some("11-C"), 10),
59+
MillMain0.parseThreadCount(Some("11-C"), 10),
6060
"Failed to find a float number before \"C\""
6161
)
6262
}
6363

6464
test("parse invalid input") {
6565
assertParseErr(
66-
MillMain.parseThreadCount(Some("CCCC"), 10),
66+
MillMain0.parseThreadCount(Some("CCCC"), 10),
6767
"Failed to find a float number before \"C\""
6868
)
6969
assertParseErr(
70-
MillMain.parseThreadCount(Some("abcdefg"), 10),
70+
MillMain0.parseThreadCount(Some("abcdefg"), 10),
7171
"Failed to find a int number"
7272
)
7373
}
@@ -78,19 +78,19 @@ object MillMainTests extends TestSuite {
7878
test("from .mill-version") {
7979
val file = os.temp.dir() / ".mill-version"
8080
os.write(file, "1.2.3")
81-
val read = MillMain.readVersionFile(file)
81+
val read = MillMain0.readVersionFile(file)
8282
assert(read == Some("1.2.3"))
8383
}
8484
test("from .config/mill-version") {
8585
val file = os.temp.dir() / ".config" / "mill-version"
8686
os.write(file, "1.2.3", createFolders = true)
87-
val read = MillMain.readVersionFile(file)
87+
val read = MillMain0.readVersionFile(file)
8888
assert(read == Some("1.2.3"))
8989
}
9090
test("from build.mill") {
9191
val file = os.temp.dir() / "build.mill"
9292
os.write(file, "//| mill-version: 1.2.3")
93-
val read = MillMain.readUsingMillVersionFile(file)
93+
val read = MillMain0.readUsingMillVersionFile(file)
9494
assert(read == Some("1.2.3"))
9595
}
9696
test("precedence") {
@@ -103,33 +103,33 @@ object MillMainTests extends TestSuite {
103103
val file4 = (dir / "build.mill.scala").tap { os.write(_, "//| mill-version: 4") }
104104
val file5 = (dir / "build.sc").tap { os.write(_, "//| mill-version: 5") }
105105
test(".mill-version") {
106-
val read = MillMain.readBestMillVersion(dir)
106+
val read = MillMain0.readBestMillVersion(dir)
107107
assert(read == Some(file1, "1"))
108108
}
109109
test(".config/mill-version") {
110110
os.remove(file1)
111-
val read = MillMain.readBestMillVersion(dir)
111+
val read = MillMain0.readBestMillVersion(dir)
112112
assert(read == Some(file2, "2"))
113113
}
114114
test("build.mill") {
115115
os.remove(file1)
116116
os.remove(file2)
117-
val read = MillMain.readBestMillVersion(dir)
117+
val read = MillMain0.readBestMillVersion(dir)
118118
assert(read == Some(file3, "3"))
119119
}
120120
test("build.mill.scala") {
121121
os.remove(file1)
122122
os.remove(file2)
123123
os.remove(file3)
124-
val read = MillMain.readBestMillVersion(dir)
124+
val read = MillMain0.readBestMillVersion(dir)
125125
assert(read == Some(file4, "4"))
126126
}
127127
test("build.sc") {
128128
os.remove(file1)
129129
os.remove(file2)
130130
os.remove(file3)
131131
os.remove(file4)
132-
val read = MillMain.readBestMillVersion(dir)
132+
val read = MillMain0.readBestMillVersion(dir)
133133
assert(read == Some(file5, "5"))
134134
}
135135
}

runner/launcher/src/mill/launcher/MillProcessLauncher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int launchMillNoServer(String[] args) throws Exception {
2828

2929
final List<String> l = new ArrayList<>();
3030
l.addAll(millLaunchJvmCommand());
31-
l.add("mill.daemon.MillMain");
31+
l.add("mill.daemon.MillNoDaemonMain");
3232
l.add(processDir.toAbsolutePath().toString());
3333
l.addAll(millOpts());
3434
l.addAll(Arrays.asList(args));

0 commit comments

Comments
 (0)