Skip to content

Commit 81fab4f

Browse files
committed
Add mill.api.Debug helper (#6311)
Easier to use than constantly writing `mill.constants.DebugLog.println("foo " + pprint.apply(foo))` Also add a check that `DebugLog.println` isn't run in CI, so we don't accidentally forget to remove some calls before publishing
1 parent 5d6e4b1 commit 81fab4f

File tree

12 files changed

+54
-17
lines changed

12 files changed

+54
-17
lines changed

core/api/src/mill/api/Debug.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package mill.api
2+
3+
import mill.api.daemon.experimental
4+
5+
import java.io.{ByteArrayOutputStream, PrintStream}
6+
7+
@experimental
8+
object Debug {
9+
def apply[T](
10+
x: sourcecode.Text[T],
11+
tag: String = "",
12+
width: Int = 100,
13+
height: Int = 500,
14+
indent: Int = 2,
15+
escapeUnicode: Boolean = true,
16+
showFieldNames: Boolean = true
17+
)(implicit line: sourcecode.Line, fileName: sourcecode.FileName): T = {
18+
19+
val baos = new ByteArrayOutputStream()
20+
pprint.logTo(
21+
x,
22+
tag,
23+
width,
24+
height,
25+
indent,
26+
escapeUnicode,
27+
showFieldNames,
28+
new PrintStream(baos)
29+
)
30+
mill.constants.DebugLog.println(baos.toString)
31+
x.value
32+
}
33+
}

core/constants/src/mill/constants/DebugLog.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public static synchronized void apply(String s) {
1414
}
1515

1616
public static synchronized void println(String s) {
17+
if (System.getenv("CI") != null) {
18+
throw new RuntimeException("DebugLog cannot be run in CI");
19+
}
20+
1721
Path path = Paths.get(System.getProperty("user.home"), "mill-debug-log.txt");
1822
try {
1923
if (!Files.exists(path)) Files.createFile(path);

developer.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ The following table contains the main ways you can test the code in
3333

3434
In general, `println` or `pprint.log` should work in most places and be sufficient for
3535
instrumenting and debugging the Mill codebase. In the occasional spot where `println`
36-
doesn't work you can use `mill.constants.DebugLog.println` which writes to a file
37-
`~/mill-debug-log.txt` in your home folder. `DebugLog` is useful for scenarios like
38-
debugging Mill's terminal UI (where `println` would mess things up) or subprocesses
36+
doesn't work you can use `mill.constants.DebugLog.println`/`mill.api.Debug` which writes
37+
to a file `~/mill-debug-log.txt` in your home folder. `DebugLog` is useful for scenarios
38+
like debugging Mill's terminal UI (where `println` would mess things up) or subprocesses
3939
(where stdout/stderr may get captured or used and cannot be used to display your own
4040
debug statements).
4141

integration/ide/bsp-server/resources/snapshots/build-targets-compile-classpaths.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
},
153153
"classpath": [
154154
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/<scala3-version>/scala3-library_3-<scala3-version>.jar",
155-
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.5.jar",
155+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.6.jar",
156156
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_3/0.11.5/os-lib_3-0.11.5.jar",
157157
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/upickle_3/4.4.1/upickle_3-4.4.1.jar",
158158
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/requests_3/0.9.0/requests_3-0.9.0.jar",
@@ -230,7 +230,7 @@
230230
},
231231
"classpath": [
232232
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/<scala3-version>/scala3-library_3-<scala3-version>.jar",
233-
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.5.jar",
233+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.6.jar",
234234
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_3/0.11.5/os-lib_3-0.11.5.jar",
235235
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/upickle_3/4.4.1/upickle_3-4.4.1.jar",
236236
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/requests_3/0.9.0/requests_3-0.9.0.jar",

integration/ide/bsp-server/resources/snapshots/build-targets-dependency-sources.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
},
127127
"sources": [
128128
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/<scala3-version>/scala3-library_3-<scala3-version>-sources.jar",
129-
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.5-sources.jar",
129+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.6-sources.jar",
130130
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_3/0.11.5/os-lib_3-0.11.5-sources.jar",
131131
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/upickle_3/4.4.1/upickle_3-4.4.1-sources.jar",
132132
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/requests_3/0.9.0/requests_3-0.9.0-sources.jar",
@@ -202,7 +202,7 @@
202202
},
203203
"sources": [
204204
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/<scala3-version>/scala3-library_3-<scala3-version>-sources.jar",
205-
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.5-sources.jar",
205+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.6-sources.jar",
206206
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_3/0.11.5/os-lib_3-0.11.5-sources.jar",
207207
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/upickle_3/4.4.1/upickle_3-4.4.1-sources.jar",
208208
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/requests_3/0.9.0/requests_3-0.9.0-sources.jar",

integration/ide/bsp-server/resources/snapshots/build-targets-javac-options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
"options": [],
182182
"classpath": [
183183
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/<scala3-version>/scala3-library_3-<scala3-version>.jar",
184-
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.5.jar",
184+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.6.jar",
185185
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_3/0.11.5/os-lib_3-0.11.5.jar",
186186
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/upickle_3/4.4.1/upickle_3-4.4.1.jar",
187187
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/requests_3/0.9.0/requests_3-0.9.0.jar",
@@ -267,7 +267,7 @@
267267
"options": [],
268268
"classpath": [
269269
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/<scala3-version>/scala3-library_3-<scala3-version>.jar",
270-
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.5.jar",
270+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.6.jar",
271271
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_3/0.11.5/os-lib_3-0.11.5.jar",
272272
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/upickle_3/4.4.1/upickle_3-4.4.1.jar",
273273
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/requests_3/0.9.0/requests_3-0.9.0.jar",

integration/ide/bsp-server/resources/snapshots/build-targets-jvm-run-environments.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
},
245245
"classpath": [
246246
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/<scala3-version>/scala3-library_3-<scala3-version>.jar",
247-
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.5.jar",
247+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.6.jar",
248248
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_3/0.11.5/os-lib_3-0.11.5.jar",
249249
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/upickle_3/4.4.1/upickle_3-4.4.1.jar",
250250
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/requests_3/0.9.0/requests_3-0.9.0.jar",
@@ -367,7 +367,7 @@
367367
},
368368
"classpath": [
369369
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/<scala3-version>/scala3-library_3-<scala3-version>.jar",
370-
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.5.jar",
370+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.6.jar",
371371
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_3/0.11.5/os-lib_3-0.11.5.jar",
372372
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/upickle_3/4.4.1/upickle_3-4.4.1.jar",
373373
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/requests_3/0.9.0/requests_3-0.9.0.jar",

integration/ide/bsp-server/resources/snapshots/build-targets-scalac-options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"options": [],
9595
"classpath": [
9696
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/<scala3-version>/scala3-library_3-<scala3-version>.jar",
97-
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.5.jar",
97+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.6.jar",
9898
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_3/0.11.5/os-lib_3-0.11.5.jar",
9999
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/upickle_3/4.4.1/upickle_3-4.4.1.jar",
100100
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/requests_3/0.9.0/requests_3-0.9.0.jar",
@@ -120,7 +120,7 @@
120120
"options": [],
121121
"classpath": [
122122
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/<scala3-version>/scala3-library_3-<scala3-version>.jar",
123-
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.5.jar",
123+
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.5/pprint_3-0.9.6.jar",
124124
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_3/0.11.5/os-lib_3-0.11.5.jar",
125125
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/upickle_3/4.4.1/upickle_3-4.4.1.jar",
126126
"file:///coursier-cache/https/repo1.maven.org/maven2/com/lihaoyi/requests_3/0.9.0/requests_3-0.9.0.jar",

integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<orderEntry type="library" scope="RUNTIME" name="plexus-container-default-2.1.1.jar" level="project"/>
9797
<orderEntry type="library" scope="RUNTIME" name="plexus-io-3.5.1.jar" level="project"/>
9898
<orderEntry type="library" scope="RUNTIME" name="plexus-utils-4.0.2.jar" level="project"/>
99-
<orderEntry type="library" name="pprint_3-0.9.5.jar" level="project"/>
99+
<orderEntry type="library" name="pprint_3-0.9.6.jar" level="project"/>
100100
<orderEntry type="library" name="requests_3-0.9.0.jar" level="project"/>
101101
<orderEntry type="library" scope="RUNTIME" name="scala-collection-compat_2.13-2.13.0.jar" level="project"/>
102102
<orderEntry type="library" name="scala-collection-compat_3-2.12.0.jar" level="project"/>

integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.mill-build.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<orderEntry type="library" scope="RUNTIME" name="plexus-container-default-2.1.1.jar" level="project"/>
9999
<orderEntry type="library" scope="RUNTIME" name="plexus-io-3.5.1.jar" level="project"/>
100100
<orderEntry type="library" scope="RUNTIME" name="plexus-utils-4.0.2.jar" level="project"/>
101-
<orderEntry type="library" name="pprint_3-0.9.5.jar" level="project"/>
101+
<orderEntry type="library" name="pprint_3-0.9.6.jar" level="project"/>
102102
<orderEntry type="library" name="requests_3-0.9.0.jar" level="project"/>
103103
<orderEntry type="library" scope="RUNTIME" name="scala-collection-compat_2.13-2.13.0.jar" level="project"/>
104104
<orderEntry type="library" name="scala-collection-compat_3-2.12.0.jar" level="project"/>

0 commit comments

Comments
 (0)