Skip to content

Commit

Permalink
CodeGen - package_ not always in discover map
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Sep 20, 2024
1 parent 4f27142 commit 6366cc7
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions runner/src/mill/runner/CodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,10 @@ object CodeGen {
def addChildren(initial: String) =
if childSels.nonEmpty then
s"""{
| val childModules: Seq[_root_.mill.define.Module] = Seq(
| ${childSels.mkString(",\n ")}
| val childDiscovers: Seq[_root_.mill.define.Discover] = Seq(
| ${childSels.map(child => s"$child.millDiscover").mkString(",\n ")}
| )
| childModules.foldLeft($initial.value)({ (acc, m) =>
| m match {
| case m: _root_.mill.main.RootModule => acc ++ m.millDiscover.value
| case m: _root_.mill.main.RootModule.Subfolder => acc ++ m.millDiscover.value
| case _ => acc
| }
| })
| childDiscovers.foldLeft($initial.value)(_ ++ _.value)
| }""".stripMargin
else
s"""$initial.value""".stripMargin
Expand All @@ -254,15 +248,22 @@ object CodeGen {
s"""object ${wrapperObjectName} extends $wrapperObjectName {
| ${childAliases.linesWithSeparators.mkString(" ")}
| override lazy val millDiscover: _root_.mill.define.Discover = {
| val initial = ${addChildren("this.innerMillDiscover_")}
| val inner = initial(classOf[$wrapperObjectName])
| _root_.mill.define.Discover.apply2(
| value = initial.updated(classOf[$wrapperObjectName.type], inner),
| )
| val base = this.__innerMillDiscover
| val initial = ${addChildren("base")}
| val subbed = {
| initial.get(classOf[$wrapperObjectName]) match {
| case Some(inner) => initial.updated(classOf[$wrapperObjectName.type], inner)
| case None => initial
| }
| }
| if subbed ne base.value then
| _root_.mill.define.Discover.apply2(value = subbed)
| else
| base
| }
|}
|abstract class $wrapperObjectName $extendsClause {
|protected def innerMillDiscover_: _root_.mill.define.Discover = _root_.mill.define.Discover[this.type]""".stripMargin
|protected def __innerMillDiscover: _root_.mill.define.Discover = _root_.mill.define.Discover[this.type]""".stripMargin

}

Expand Down

0 comments on commit 6366cc7

Please sign in to comment.