Skip to content

Commit e48c37e

Browse files
committed
enableDebugLog
1 parent d9593de commit e48c37e

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

runner/src/mill/runner/Watching.scala

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package mill.runner
22

3-
import mill.api.internal
4-
import mill.util.{Colors, Watchable}
5-
import mill.api.SystemStreams
3+
import mill.api.{SystemStreams, internal}
64
import mill.main.client.DebugLog
5+
import mill.util.{Colors, Watchable}
76

87
import java.io.InputStream
98
import scala.annotation.tailrec
@@ -15,22 +14,24 @@ import scala.util.Using
1514
*/
1615
@internal
1716
object Watching {
17+
private final val enableDebugLog = false
18+
1819
case class Result[T](watched: Seq[Watchable], error: Option[String], result: T)
1920

2021
trait Evaluate[T] {
2122
def apply(enterKeyPressed: Boolean, previousState: Option[T]): Result[T]
2223
}
2324

2425
case class WatchArgs(
25-
setIdle: Boolean => Unit,
26-
colors: Colors
26+
setIdle: Boolean => Unit,
27+
colors: Colors
2728
)
2829

2930
def watchLoop[T](
3031
ringBell: Boolean,
3132
watch: Option[WatchArgs],
3233
streams: SystemStreams,
33-
evaluate: Evaluate[T],
34+
evaluate: Evaluate[T]
3435
): (Boolean, T) = {
3536
def handleError(errorOpt: Option[String]): Unit = {
3637
errorOpt.foreach(streams.err.println)
@@ -106,50 +107,59 @@ object Watching {
106107

107108
// oslib watch only works with folders, so we have to watch the parent folders instead
108109

109-
mill.main.client.DebugLog.println(
110-
colors.info(s"[watch:watched-paths:unfiltered] ${watchedPathsSet.toSeq.sorted.mkString("\n")}").toString
110+
if (enableDebugLog) DebugLog.println(
111+
colors.info(
112+
s"[watch:watched-paths:unfiltered] ${watchedPathsSet.toSeq.sorted.mkString("\n")}"
113+
).toString
111114
)
112115

116+
/** A hardcoded list of folders to ignore that we know have no impact on the build. */
113117
val ignoredFolders = Seq(
114118
mill.api.WorkspaceRoot.workspaceRoot / "out",
115119
mill.api.WorkspaceRoot.workspaceRoot / ".bloop",
116120
mill.api.WorkspaceRoot.workspaceRoot / ".metals",
117121
mill.api.WorkspaceRoot.workspaceRoot / ".idea",
118122
mill.api.WorkspaceRoot.workspaceRoot / ".git",
119-
mill.api.WorkspaceRoot.workspaceRoot / ".bsp",
123+
mill.api.WorkspaceRoot.workspaceRoot / ".bsp"
120124
)
121-
mill.main.client.DebugLog.println(
125+
if (enableDebugLog) DebugLog.println(
122126
colors.info(s"[watch:ignored-paths] ${ignoredFolders.toSeq.sorted.mkString("\n")}").toString
123127
)
124128

125129
val osLibWatchPaths = watchedPathsSet.iterator.map(p => p / "..").toSet
126-
mill.main.client.DebugLog.println(
130+
if (enableDebugLog) DebugLog.println(
127131
colors.info(s"[watch:watched-paths] ${osLibWatchPaths.toSeq.sorted.mkString("\n")}").toString
128132
)
129133

130134
Using.resource(os.watch.watch(
131135
osLibWatchPaths.toSeq,
132-
// filter = path => {
133-
// val shouldBeIgnored = ignoredFolders.exists(ignored => path.startsWith(ignored))
134-
// mill.main.client.DebugLog.println(
135-
// colors.info(s"[watch:filter] $path (ignored=$shouldBeIgnored), ignoredFolders=${ignoredFolders.mkString("[\n ", "\n ", "\n]")}").toString
136-
// )
137-
// !shouldBeIgnored
138-
// },
136+
filter = path => {
137+
val shouldBeIgnored = ignoredFolders.exists(ignored => path.startsWith(ignored))
138+
if (enableDebugLog) {
139+
val ignoredFoldersStr = ignoredFolders.mkString("[\n ", "\n ", "\n]")
140+
DebugLog.println(
141+
colors.info(s"[watch:filter] $path (ignored=$shouldBeIgnored), ignoredFolders=$ignoredFoldersStr").toString
142+
)
143+
}
144+
!shouldBeIgnored
145+
},
139146
onEvent = changedPaths => {
140147
// Make sure that the changed paths are actually the ones in our watch list and not some adjacent files in the
141148
// same folder
142-
val hasWatchedPath = changedPaths.exists(p => watchedPathsSet.exists(watchedPath => p.startsWith(watchedPath)))
143-
mill.main.client.DebugLog.println(colors.info(
149+
val hasWatchedPath =
150+
changedPaths.exists(p => watchedPathsSet.exists(watchedPath => p.startsWith(watchedPath)))
151+
if (enableDebugLog) DebugLog.println(colors.info(
144152
s"[watch:changed-paths] (hasWatchedPath=$hasWatchedPath) ${changedPaths.mkString("\n")}"
145153
).toString)
146154
if (hasWatchedPath) {
147155
pathChangesDetected = true
148156
}
149157
},
150-
logger = (eventType, data) => {
151-
mill.main.client.DebugLog.println(colors.info(s"[watch] $eventType: ${pprint.apply(data)}").toString)
152-
}
158+
logger =
159+
if (enableDebugLog) (eventType, data) => {
160+
DebugLog.println(colors.info(s"[watch] $eventType: ${pprint.apply(data)}").toString)
161+
}
162+
else (_, _) => {}
153163
)) { _ =>
154164
val enterKeyPressed =
155165
statWatchWait(watchedPollables, stdin, notifiablesChanged = () => pathChangesDetected)
@@ -163,7 +173,11 @@ object Watching {
163173
*
164174
* @return `true` if enter key is pressed to re-run tasks explicitly, false if changes in watched files occured.
165175
*/
166-
def statWatchWait(watched: Seq[Watchable], stdin: InputStream, notifiablesChanged: () => Boolean): Boolean = {
176+
def statWatchWait(
177+
watched: Seq[Watchable],
178+
stdin: InputStream,
179+
notifiablesChanged: () => Boolean
180+
): Boolean = {
167181
val buffer = new Array[Byte](4 * 1024)
168182

169183
@tailrec def statWatchWait0(): Boolean = {

0 commit comments

Comments
 (0)