Skip to content

Commit

Permalink
Warn user if configured Mill version differs from runtime (#2171)
Browse files Browse the repository at this point in the history
Pull request: #2171
  • Loading branch information
lefou authored Dec 6, 2022
1 parent 35d6b5a commit fa6c678
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions main/src/mill/MillMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ object MillMain {
): (Boolean, Option[EvaluatorState]) = {

MillConfigParser.parse(args) match {
// Cannot parse args
case Left(msg) =>
stderr.println(msg)
(false, None)

case Right(config) if config.ammoniteCore.help.value =>
stdout.println(MillConfigParser.usageText)
(true, None)

case Right(config) if config.showVersion.value =>
def p(k: String, d: String = "<unknown>") = System.getProperty(k, d)
stdout.println(
Expand All @@ -97,6 +100,7 @@ object MillMain {
)}""".stripMargin
)
(true, None)

case Right(config)
if (
config.interactive.value || config.repl.value || config.noServer.value || config.bsp.value
Expand All @@ -106,6 +110,7 @@ object MillMain {
"-i/--interactive/--repl/--no-server/--bsp must be passed in as the first argument"
)
(false, None)

case Right(config)
if Seq(
config.interactive.value,
Expand All @@ -117,7 +122,12 @@ object MillMain {
"Only one of -i/--interactive, --repl, --no-server or --bsp may be given"
)
(false, None)

case Right(config) =>
if(!config.ammoniteCore.silent.value) {
checkMillVersionFromFile(os.pwd, stderr)
}

val useRepl =
config.repl.value || (config.interactive.value && config.leftoverArgs.value.isEmpty)

Expand Down Expand Up @@ -340,4 +350,24 @@ object MillMain {
(success, nextStateCache)
}
}

private def checkMillVersionFromFile(projectDir: os.Path, stderr: PrintStream) = {
Seq(
projectDir / ".config" / "mill-version",
projectDir / ".mill-version"
).collectFirst {
case f if os.exists(f) =>
(f, os.read.lines(f).filter(l => l.trim().nonEmpty).headOption)
}.foreach { case (file, Some(version)) =>
if (BuildInfo.millVersion != version) {
val msg =
s"""Mill version ${BuildInfo.millVersion} is different than configured for this directory!
|Configured version is ${version} (${file})""".stripMargin
stderr.println(
msg
)
}
}
}

}

0 comments on commit fa6c678

Please sign in to comment.