Skip to content

Commit

Permalink
Show the correct buildfile name in the progress (#3847)
Browse files Browse the repository at this point in the history
Instead of always using `build.mill` we now use the actual buildfile
name in the progress logger.

```
> mill resolve _
[build.sc-57/61] compile
...

> mv build.sc build.mill.scala

> mill resolve _
[build.mill.scala-57/61] compile
...
```

Fix #3831

Pull request: #3847
  • Loading branch information
lefou authored Oct 27, 2024
1 parent 6c7563c commit fbc6e2e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ object MissingBuildFileTests extends UtestIntegrationTestSuite {
test - integrationTest { tester =>
val res = tester.eval(("resolve", "_"))
assert(!res.isSuccess)
val s"${prefix}build.mill file not found in $msg. Are you in a Mill project folder?" = res.err
val s"${prefix}No build file (build.mill, build.mill.scala, build.sc) found in $msg. Are you in a Mill project directory?" =
res.err
}
}
}
6 changes: 4 additions & 2 deletions runner/src/mill/runner/FileImportGraph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ case class FileImportGraph(
repos: Seq[(String, os.Path)],
ivyDeps: Set[String],
errors: Seq[String],
millImport: Boolean
millImport: Boolean,
buildFile: String
)

/**
Expand Down Expand Up @@ -215,7 +216,8 @@ object FileImportGraph {
seenRepo.toSeq,
seenIvy.toSet,
errors.toSeq,
millImport
millImport,
foundRootBuildFileName
)
}

Expand Down
26 changes: 16 additions & 10 deletions runner/src/mill/runner/MillBuildBootstrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MillBuildBootstrap(
prevRunnerState: RunnerState,
logger: ColorLogger,
disableCallgraph: Boolean,
needBuildSc: Boolean,
needBuildFile: Boolean,
requestedMetaLevel: Option[Int],
allowPositionalCommandArgs: Boolean,
systemExit: Int => Nothing,
Expand Down Expand Up @@ -79,7 +79,7 @@ class MillBuildBootstrap(
if (depth == 0) {
// On this level we typically want assume a Mill project, which means we want to require an existing `build.mill`.
// Unfortunately, some targets also make sense without a `build.mill`, e.g. the `init` command.
// Hence we only report a missing `build.mill` as an problem if the command itself does not succeed.
// Hence we only report a missing `build.mill` as a problem if the command itself does not succeed.
lazy val state = evaluateRec(depth + 1)
if (
rootBuildFileNames.exists(rootBuildFileName =>
Expand All @@ -88,12 +88,12 @@ class MillBuildBootstrap(
) state
else {
val msg =
s"${rootBuildFileNames.head} file not found in $projectRoot. Are you in a Mill project folder?"
if (needBuildSc) {
RunnerState(None, Nil, Some(msg))
s"No build file (${rootBuildFileNames.mkString(", ")}) found in $projectRoot. Are you in a Mill project directory?"
if (needBuildFile) {
RunnerState(None, Nil, Some(msg), None)
} else {
state match {
case RunnerState(bootstrapModuleOpt, frames, Some(error)) =>
case RunnerState(bootstrapModuleOpt, frames, Some(error), None) =>
// Add a potential clue (missing build.mill) to the underlying error message
RunnerState(bootstrapModuleOpt, frames, Some(msg + "\n" + error))
case state => state
Expand All @@ -118,7 +118,7 @@ class MillBuildBootstrap(
projectRoot
)
)
RunnerState(Some(bootstrapModule), Nil, None)
RunnerState(Some(bootstrapModule), Nil, None, Some(parsedScriptFiles.buildFile))
}
}

Expand Down Expand Up @@ -174,7 +174,8 @@ class MillBuildBootstrap(
.flatMap(_.classLoaderOpt)
.map(_.hashCode())
.getOrElse(0),
depth
depth,
actualBuildFileName = nestedState.buildFile
)

if (depth != 0) {
Expand Down Expand Up @@ -330,12 +331,17 @@ class MillBuildBootstrap(
rootModule: BaseModule,
millClassloaderSigHash: Int,
millClassloaderIdentityHash: Int,
depth: Int
depth: Int,
actualBuildFileName: Option[String] = None
): Evaluator = {

val bootLogPrefix: Seq[String] =
if (depth == 0) Nil
else Seq((Seq.fill(depth - 1)(millBuild) ++ Seq("build.mill")).mkString("/"))
else Seq(
(Seq.fill(depth - 1)(millBuild) ++
Seq(actualBuildFileName.getOrElse("<build>")))
.mkString("/")
)

mill.eval.EvaluatorImpl(
home,
Expand Down
4 changes: 2 additions & 2 deletions runner/src/mill/runner/MillMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ object MillMain {
prevRunnerState = prevState.getOrElse(stateCache),
logger = logger,
disableCallgraph = config.disableCallgraph.value,
needBuildSc = needBuildSc(config),
needBuildFile = needBuildFile(config),
requestedMetaLevel = config.metaLevel,
config.allowPositional.value,
systemExit = systemExit,
Expand Down Expand Up @@ -373,7 +373,7 @@ object MillMain {
/**
* Determine, whether we need a `build.mill` or not.
*/
private def needBuildSc(config: MillCliConfig): Boolean = {
private def needBuildFile(config: MillCliConfig): Boolean = {
// Tasks, for which running Mill without an existing buildfile is allowed.
val noBuildFileTaskWhitelist = Seq(
"init",
Expand Down
3 changes: 2 additions & 1 deletion runner/src/mill/runner/RunnerState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import mill.main.RootModule
case class RunnerState(
bootstrapModuleOpt: Option[RootModule],
frames: Seq[RunnerState.Frame],
errorOpt: Option[String]
errorOpt: Option[String],
buildFile: Option[String] = None
) {
def add(
frame: RunnerState.Frame = RunnerState.Frame.empty,
Expand Down

0 comments on commit fbc6e2e

Please sign in to comment.