Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify codegen prelude implicits #3749

Merged
merged 8 commits into from
Oct 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
.
lihaoyi committed Oct 15, 2024
commit c608be5c94b86752bb14794dc25fcb945974dca0
25 changes: 22 additions & 3 deletions main/src/mill/main/RootModule.scala
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ abstract class RootModule()(implicit
millModuleEnclosing0: sourcecode.Enclosing,
millModuleLine0: sourcecode.Line,
millFile0: sourcecode.File
) extends mill.define.BaseModule(baseModuleInfo.millSourcePath0)(
) extends mill.define.BaseModule(baseModuleInfo.projectRoot)(
millModuleEnclosing0,
millModuleLine0,
millFile0,
@@ -33,7 +33,26 @@ abstract class RootModule()(implicit

@internal
object RootModule {
case class Info(millSourcePath0: os.Path, discover: Discover)
class Info(val enclosingClasspath: Seq[os.Path],
val projectRoot: os.Path,
val output: os.Path,
val topLevelProjectRoot: os.Path){
def this(
enclosingClasspath0: Seq[String],
projectRoot0: String,
output0: String,
topLevelProjectRoot0: String
) = this(
enclosingClasspath0.map(os.Path(_)),
os.Path(projectRoot0),
os.Path(output0),
os.Path(topLevelProjectRoot0)
)

implicit val millMiscInfo: Info = this

}

object Info {
// Dummy `RootModule.Info` available in implicit scope but never actually used.
// as it is provided by the codegen. Defined for IDEs to think that one is available
@@ -70,7 +89,7 @@ object RootModule {
millModuleEnclosing0: sourcecode.Enclosing,
millModuleLine0: sourcecode.Line,
millFile0: sourcecode.File
) extends BaseModule(baseModuleInfo.millSourcePath0, foreign0 = foreign0)(
) extends BaseModule(baseModuleInfo.projectRoot, foreign0 = foreign0)(
millModuleEnclosing0,
millModuleLine0,
millFile0,
18 changes: 7 additions & 11 deletions runner/src/mill/runner/MillBuildBootstrap.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package mill.runner

import mill.util.{ColorLogger, PrefixLogger, Watchable}
import mill.main.BuildInfo
import mill.main.client.CodeGenConstants._
import mill.main.{BuildInfo, RootModule, RunScript}
import mill.main.client.CodeGenConstants.*
import mill.api.{PathRef, SystemStreams, Val, internal}
import mill.eval.Evaluator
import mill.main.RunScript
import mill.resolve.SelectMode
import mill.define.{BaseModule, Discover, Segments}
import mill.main.client.OutFiles.{millBuild, millRunnerState}
@@ -111,15 +110,12 @@ class MillBuildBootstrap(
if (parsedScriptFiles.millImport) evaluateRec(depth + 1)
else {
val bootstrapModule =
new MillBuildRootModule.BootstrapModule(
projectRoot,
recRoot(projectRoot, depth),
output,
millBootClasspath
)(
mill.main.RootModule.Info(
new MillBuildRootModule.BootstrapModule()(
new RootModule.Info(
millBootClasspath,
recRoot(projectRoot, depth),
Discover[MillBuildRootModule.BootstrapModule]
output,
projectRoot
)
)
RunnerState(Some(bootstrapModule), Nil, None)
61 changes: 14 additions & 47 deletions runner/src/mill/runner/MillBuildRootModule.scala
Original file line number Diff line number Diff line change
@@ -25,17 +25,16 @@ import mill.define.Target
*/
@internal
abstract class MillBuildRootModule()(implicit
baseModuleInfo: RootModule.Info,
millBuildRootModuleInfo: MillBuildRootModule.Info
rootModuleInfo: RootModule.Info,
) extends RootModule() with ScalaModule {
override def bspDisplayName0: String = millBuildRootModuleInfo
override def bspDisplayName0: String = rootModuleInfo
.projectRoot
.relativeTo(millBuildRootModuleInfo.topLevelProjectRoot)
.relativeTo(rootModuleInfo.topLevelProjectRoot)
.segments
.++(super.bspDisplayName0.split("/"))
.mkString("/")

override def millSourcePath: os.Path = millBuildRootModuleInfo.projectRoot / os.up / millBuild
override def millSourcePath: os.Path = rootModuleInfo.projectRoot / os.up / millBuild
override def intellijModulePath: os.Path = millSourcePath / os.up

override def scalaVersion: T[String] = BuildInfo.scalaVersion
@@ -45,15 +44,15 @@ abstract class MillBuildRootModule()(implicit
* @see [[generateScriptSources]]
*/
def scriptSources: Target[Seq[PathRef]] = Task.Sources {
MillBuildRootModule.parseBuildFiles(millBuildRootModuleInfo)
MillBuildRootModule.parseBuildFiles(rootModuleInfo)
.seenScripts
.keys.map(PathRef(_))
.toSeq
}

def parseBuildFiles: T[FileImportGraph] = Task {
scriptSources()
MillBuildRootModule.parseBuildFiles(millBuildRootModuleInfo)
MillBuildRootModule.parseBuildFiles(rootModuleInfo)
}

override def repositoriesTask: Task[Seq[Repository]] = {
@@ -116,13 +115,13 @@ abstract class MillBuildRootModule()(implicit
if (parsed.errors.nonEmpty) Result.Failure(parsed.errors.mkString("\n"))
else {
CodeGen.generateWrappedSources(
millBuildRootModuleInfo.projectRoot / os.up,
rootModuleInfo.projectRoot / os.up,
scriptSources(),
parsed.seenScripts,
T.dest,
millBuildRootModuleInfo.enclosingClasspath,
millBuildRootModuleInfo.topLevelProjectRoot,
millBuildRootModuleInfo.output
rootModuleInfo.enclosingClasspath,
rootModuleInfo.topLevelProjectRoot,
rootModuleInfo.output
)
Result.Success(Seq(PathRef(T.dest)))
}
@@ -212,7 +211,7 @@ abstract class MillBuildRootModule()(implicit
}

def enclosingClasspath: Target[Seq[PathRef]] = Task.Sources {
millBuildRootModuleInfo.enclosingClasspath.map(p => mill.api.PathRef(p, quick = true))
rootModuleInfo.enclosingClasspath.map(p => mill.api.PathRef(p, quick = true))
}

/**
@@ -266,22 +265,8 @@ abstract class MillBuildRootModule()(implicit

object MillBuildRootModule {

class BootstrapModule(
topLevelProjectRoot0: os.Path,
projectRoot: os.Path,
output: os.Path,
enclosingClasspath: Seq[os.Path]
)(implicit baseModuleInfo: RootModule.Info) extends MillBuildRootModule()(
implicitly,
MillBuildRootModule.Info(
enclosingClasspath,
projectRoot,
output,
topLevelProjectRoot0
)
) {

override lazy val millDiscover: Discover = baseModuleInfo.discover
class BootstrapModule()(implicit rootModuleInfo: RootModule.Info) extends MillBuildRootModule() {
override lazy val millDiscover: Discover = Discover[this.type]
}

case class Info(
@@ -291,29 +276,11 @@ object MillBuildRootModule {
topLevelProjectRoot: os.Path
)

def parseBuildFiles(millBuildRootModuleInfo: MillBuildRootModule.Info): FileImportGraph = {
def parseBuildFiles(millBuildRootModuleInfo: RootModule.Info): FileImportGraph = {
FileImportGraph.parseBuildFiles(
millBuildRootModuleInfo.topLevelProjectRoot,
millBuildRootModuleInfo.projectRoot / os.up,
millBuildRootModuleInfo.output
)
}

class MillMiscInfo(
enclosingClasspath: Seq[String],
projectRoot: String,
output: String,
topLevelProjectRoot: String
) {
implicit lazy val millBuildRootModuleInfo: MillBuildRootModule.Info = MillBuildRootModule.Info(
enclosingClasspath.map(os.Path(_)),
os.Path(projectRoot),
os.Path(output),
os.Path(topLevelProjectRoot)
)
implicit lazy val millBaseModuleInfo: RootModule.Info = RootModule.Info(
millBuildRootModuleInfo.projectRoot,
null
)
}
}