From fbc6e2e4e0b91a1ad254c6c71ebad91f38d85681 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Sun, 27 Oct 2024 17:20:38 +0100 Subject: [PATCH] Show the correct buildfile name in the progress (#3847) 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 https://github.com/com-lihaoyi/mill/issues/3831 Pull request: https://github.com/com-lihaoyi/mill/pull/3847 --- .../src/MissingBuildFileTests.scala | 3 ++- runner/src/mill/runner/FileImportGraph.scala | 6 +++-- .../src/mill/runner/MillBuildBootstrap.scala | 26 ++++++++++++------- runner/src/mill/runner/MillMain.scala | 4 +-- runner/src/mill/runner/RunnerState.scala | 3 ++- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/integration/failure/missing-build-file/src/MissingBuildFileTests.scala b/integration/failure/missing-build-file/src/MissingBuildFileTests.scala index 892f5439a42..131c6f170e6 100644 --- a/integration/failure/missing-build-file/src/MissingBuildFileTests.scala +++ b/integration/failure/missing-build-file/src/MissingBuildFileTests.scala @@ -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 } } } diff --git a/runner/src/mill/runner/FileImportGraph.scala b/runner/src/mill/runner/FileImportGraph.scala index 6299844dddc..05fd98dd095 100644 --- a/runner/src/mill/runner/FileImportGraph.scala +++ b/runner/src/mill/runner/FileImportGraph.scala @@ -21,7 +21,8 @@ case class FileImportGraph( repos: Seq[(String, os.Path)], ivyDeps: Set[String], errors: Seq[String], - millImport: Boolean + millImport: Boolean, + buildFile: String ) /** @@ -215,7 +216,8 @@ object FileImportGraph { seenRepo.toSeq, seenIvy.toSet, errors.toSeq, - millImport + millImport, + foundRootBuildFileName ) } diff --git a/runner/src/mill/runner/MillBuildBootstrap.scala b/runner/src/mill/runner/MillBuildBootstrap.scala index e50b17edd6c..4ac6af2e6fa 100644 --- a/runner/src/mill/runner/MillBuildBootstrap.scala +++ b/runner/src/mill/runner/MillBuildBootstrap.scala @@ -39,7 +39,7 @@ class MillBuildBootstrap( prevRunnerState: RunnerState, logger: ColorLogger, disableCallgraph: Boolean, - needBuildSc: Boolean, + needBuildFile: Boolean, requestedMetaLevel: Option[Int], allowPositionalCommandArgs: Boolean, systemExit: Int => Nothing, @@ -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 => @@ -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 @@ -118,7 +118,7 @@ class MillBuildBootstrap( projectRoot ) ) - RunnerState(Some(bootstrapModule), Nil, None) + RunnerState(Some(bootstrapModule), Nil, None, Some(parsedScriptFiles.buildFile)) } } @@ -174,7 +174,8 @@ class MillBuildBootstrap( .flatMap(_.classLoaderOpt) .map(_.hashCode()) .getOrElse(0), - depth + depth, + actualBuildFileName = nestedState.buildFile ) if (depth != 0) { @@ -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(""))) + .mkString("/") + ) mill.eval.EvaluatorImpl( home, diff --git a/runner/src/mill/runner/MillMain.scala b/runner/src/mill/runner/MillMain.scala index 3f42d60247c..9a5dcf29056 100644 --- a/runner/src/mill/runner/MillMain.scala +++ b/runner/src/mill/runner/MillMain.scala @@ -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, @@ -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", diff --git a/runner/src/mill/runner/RunnerState.scala b/runner/src/mill/runner/RunnerState.scala index 7d111b67547..c1876c3cc1e 100644 --- a/runner/src/mill/runner/RunnerState.scala +++ b/runner/src/mill/runner/RunnerState.scala @@ -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,