Skip to content

Commit 503e117

Browse files
authored
Cleanup after simple/script modules (#5953)
Follow ups to #5951 to clean up things that were messy in the original PR - `def discover` forwarder was unnecessary - Break up `FileImportGraph.parseBuildFiles` and split out and inline the parts we need in `MillBuildRootModule`
1 parent a993068 commit 503e117

File tree

5 files changed

+25
-51
lines changed

5 files changed

+25
-51
lines changed

core/api/src/mill/api/internal/RootModule0.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ abstract class RootModule0(
3030
// `Discover` needs to be defined by every concrete `BaseModule` object, to gather
3131
// compile-time metadata about the tasks and commands at for use at runtime
3232
protected def millDiscover: Discover
33-
def discover: Discover = millDiscover
3433

3534
// We need to propagate the `Discover` object implicitly throughout the module tree
3635
// so it can be used for override detection

core/resolve/src/mill/resolve/Resolve.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private[mill] object Resolve {
211211
p,
212212
r.segments.last.value,
213213
p match {
214-
case e: ExternalModule => e.discover
214+
case e: ExternalModule => e.moduleCtx.discover
215215
case _ => rootModule.moduleCtx.discover
216216
},
217217
args,

runner/daemon/src/mill/daemon/MillBuildBootstrap.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import mill.api.daemon.internal.{
44
BuildFileApi,
55
CompileProblemReporter,
66
EvaluatorApi,
7-
MillScalaParser,
87
PathRefApi,
98
RootModuleApi
109
}
@@ -15,8 +14,9 @@ import mill.api.daemon.Watchable
1514
import mill.api.internal.RootModule
1615
import mill.api.{BuildCtx, PathRef, SelectMode}
1716
import mill.internal.PrefixLogger
18-
import mill.meta.{FileImportGraph, MillBuildRootModule}
17+
import mill.meta.MillBuildRootModule
1918
import mill.meta.CliImports
19+
import mill.meta.FileImportGraph.findRootBuildFiles
2020
import mill.server.Server
2121
import mill.util.BuildInfo
2222

@@ -122,12 +122,13 @@ class MillBuildBootstrap(
122122
res
123123
}
124124
} else {
125-
val parsedScriptFiles = FileImportGraph
126-
.parseBuildFiles(
127-
projectRoot,
128-
currentRoot / os.up,
129-
output,
130-
MillScalaParser.current.value
125+
val (useDummy, foundRootBuildFileName) = findRootBuildFiles(projectRoot)
126+
127+
val headerData =
128+
if (!os.exists(projectRoot / foundRootBuildFileName)) ""
129+
else mill.constants.Util.readBuildHeader(
130+
(projectRoot / foundRootBuildFileName).toNIO,
131+
foundRootBuildFileName
131132
)
132133

133134
val state =
@@ -143,10 +144,10 @@ class MillBuildBootstrap(
143144
upickle.read[Map[
144145
String,
145146
ujson.Value
146-
]](mill.internal.Util.parsedHeaderData(parsedScriptFiles.headerData))
147+
]](mill.internal.Util.parsedHeaderData(headerData))
147148
)
148149
)
149-
RunnerState(Some(bootstrapModule), Nil, None, Some(parsedScriptFiles.buildFile))
150+
RunnerState(Some(bootstrapModule), Nil, None, Some(foundRootBuildFileName))
150151
}
151152

152153
state

runner/meta/src/mill/meta/FileImportGraph.scala

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ import mill.internal.Util.backtickWrap
1717
* @param metaBuild If `true`, a meta-build is enabled
1818
*/
1919
@internal
20-
case class FileImportGraph(
21-
seenScripts: Map[os.Path, String],
22-
errors: Seq[String],
23-
buildFile: String,
24-
headerData: String
25-
)
20+
case class FileImportGraph(seenScripts: Map[os.Path, String], errors: Seq[String])
2621

2722
/**
2823
* Logic around traversing the `import $file` graph, extracting necessary info
@@ -43,7 +38,8 @@ object FileImportGraph {
4338
topLevelProjectRoot: os.Path,
4439
projectRoot: os.Path,
4540
output: os.Path,
46-
parser: MillScalaParser = MillScalaParser.current.value
41+
parser: MillScalaParser,
42+
walked: Seq[os.Path]
4743
): FileImportGraph = {
4844
val seenScripts = mutable.Map.empty[os.Path, String]
4945
val errors = mutable.Buffer.empty[String]
@@ -97,22 +93,9 @@ object FileImportGraph {
9793

9894
processScript(projectRoot / foundRootBuildFileName, useDummy)
9995

100-
val walked = walkBuildFiles(projectRoot, output)
10196
walked.foreach(processScript(_))
10297

103-
val headerData =
104-
if (!os.exists(projectRoot / foundRootBuildFileName)) ""
105-
else mill.constants.Util.readBuildHeader(
106-
(projectRoot / foundRootBuildFileName).toNIO,
107-
foundRootBuildFileName
108-
)
109-
110-
new FileImportGraph(
111-
seenScripts.toMap,
112-
errors.toSeq,
113-
foundRootBuildFileName,
114-
headerData
115-
)
98+
new FileImportGraph(seenScripts.toMap, errors.toSeq)
11699
}
117100

118101
def findRootBuildFiles(projectRoot: os.Path) = {

runner/meta/src/mill/meta/MillBuildRootModule.scala

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,24 @@ trait MillBuildRootModule()(using
4444
val scriptSourcesPaths = BuildCtx.withFilesystemCheckerDisabled {
4545
FileImportGraph
4646
.walkBuildFiles(rootModuleInfo.projectRoot / os.up, rootModuleInfo.output)
47-
.sorted
47+
.sorted // Ensure ordering is deterministic
4848
}
4949

5050
/**
5151
* All script files (that will get wrapped later)
5252
* @see [[generatedSources]]
5353
*/
54-
def scriptSources: T[Seq[PathRef]] = Task.Sources(
55-
scriptSourcesPaths* // Ensure ordering is deterministic
56-
)
54+
def scriptSources: T[Seq[PathRef]] = Task.Sources(scriptSourcesPaths*)
5755

5856
def parseBuildFiles: T[FileImportGraph] = Task {
59-
scriptSources()
6057
BuildCtx.withFilesystemCheckerDisabled {
61-
MillBuildRootModule.parseBuildFiles(MillScalaParser.current.value, rootModuleInfo)
58+
FileImportGraph.parseBuildFiles(
59+
rootModuleInfo.topLevelProjectRoot,
60+
rootModuleInfo.projectRoot / os.up,
61+
rootModuleInfo.output,
62+
MillScalaParser.current.value,
63+
scriptSources().map(_.path)
64+
)
6265
}
6366
}
6467

@@ -369,16 +372,4 @@ object MillBuildRootModule {
369372
output: os.Path,
370373
topLevelProjectRoot: os.Path
371374
)
372-
373-
def parseBuildFiles(
374-
parser: MillScalaParser,
375-
millBuildRootModuleInfo: RootModule.Info
376-
): FileImportGraph = {
377-
FileImportGraph.parseBuildFiles(
378-
millBuildRootModuleInfo.topLevelProjectRoot,
379-
millBuildRootModuleInfo.projectRoot / os.up,
380-
millBuildRootModuleInfo.output,
381-
parser
382-
)
383-
}
384375
}

0 commit comments

Comments
 (0)