Skip to content

Commit 960f708

Browse files
committed
.
1 parent b94ddfb commit 960f708

File tree

1 file changed

+6
-29
lines changed

1 file changed

+6
-29
lines changed

runner/meta/src/mill/meta/CodeGen.scala

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ object CodeGen {
307307
val expectedModuleMsg =
308308
if (projectRoot != millTopLevelProjectRoot) "MillBuildRootModule" else "mill.Module"
309309

310+
val newParent =
311+
if (segments.isEmpty) "_root_.mill.util.MainRootModule"
312+
else "_root_.mill.api.internal.SubfolderModule(build.millDiscover)"
313+
310314
val headerCode =
311315
s"""|$generatedFileHeader
312316
|package $pkg
@@ -315,16 +319,13 @@ object CodeGen {
315319
|$importSiblingScripts
316320
|$prelude
317321
|
318-
|object ${CGConst.wrapperObjectName} extends ${CGConst.wrapperObjectName} {
322+
|object ${CGConst.wrapperObjectName} extends $newParent with ${CGConst.wrapperObjectName} {
319323
| ${childAliases.linesWithSeparators.mkString(" ")}
320324
| ${exportSiblingScripts.linesWithSeparators.mkString(" ")}
321325
| ${millDiscover(segments.nonEmpty)}
322326
|}
323327
|""".stripMargin
324328

325-
val newParent =
326-
if (segments.isEmpty) "_root_.mill.util.MainRootModule"
327-
else "_root_.mill.api.internal.SubfolderModule(build.millDiscover)"
328329

329330
objectData.find(o => o.name.text == "`package`") match {
330331
case Some(objectData) =>
@@ -347,29 +348,6 @@ object CodeGen {
347348
case None => ()
348349
}
349350

350-
newScriptCode = objectData.parent.applyTo(
351-
newScriptCode,
352-
if (objectData.parent.text == null) {
353-
throw new Result.Exception(
354-
s"object `package` in ${scriptPath.relativeTo(millTopLevelProjectRoot)} " +
355-
s"must extend a subclass of `$expectedModuleMsg`"
356-
)
357-
} else {
358-
// `extends` clauses can have the parent followed by either `with` or `,`
359-
// separators, but it needs to be consistent. So we need to try and see if
360-
// any separators are already present and if so follow suite. Not 100%
361-
// precise, but probably works well enough people will rarely hit issues
362-
val postParent = newScriptCode.drop(objectData.parent.end).trim
363-
val sep = {
364-
if (postParent.startsWith(",")) ", "
365-
else if (postParent.startsWith("with")) " with "
366-
else ", " // no separator found, just use `,` by default
367-
}
368-
369-
newParent + sep + objectData.parent.text
370-
}
371-
)
372-
373351
newScriptCode = objectData.name.applyTo(newScriptCode, CGConst.wrapperObjectName)
374352
newScriptCode = objectData.obj.applyTo(newScriptCode, "trait")
375353

@@ -380,8 +358,7 @@ object CodeGen {
380358

381359
case None =>
382360
s"""$headerCode
383-
|trait ${CGConst.wrapperObjectName}
384-
| extends $newParent { this: ${CGConst.wrapperObjectName}.type =>
361+
|trait ${CGConst.wrapperObjectName} extends mill.Module{ this: ${CGConst.wrapperObjectName}.type =>
385362
|$markerComment
386363
|$scriptCode
387364
|}""".stripMargin

0 commit comments

Comments
 (0)