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

Warn user if configured Mill version differs from runtime #2171

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Changes from all commits
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
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
)
}
}
}

}