Skip to content

Commit

Permalink
fix: don't pass mill version as arg to command line (#6542)
Browse files Browse the repository at this point in the history
* fix: don't pass mill version as arg to command line

* fix tests
  • Loading branch information
kasiaMarek authored Jun 26, 2024
1 parent d37b794 commit 0206537
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ case class MillBuildTool(
with BuildServerProvider
with VersionRecommendation {

private def getMillVersion(workspace: AbsolutePath): String = {
private[builds] def getMillVersion(workspace: AbsolutePath): String = {
import scala.meta.internal.jdk.CollectionConverters._
val millVersionPath = workspace.resolve(".mill-version")
lazy val altMillVersionPath =
Expand Down Expand Up @@ -66,18 +66,14 @@ case class MillBuildTool(

private def putTogetherArgs(
cmd: List[String],
millVersion: String,
workspace: AbsolutePath,
) = {
// In some environments (such as WSL or cygwin), mill must be run using interactive mode (-i)
val fullcmd = if (Properties.isWin) "-i" :: cmd else cmd

userConfig().millScript match {
case Some(script) =>
script :: cmd
case None =>
embeddedMillWrapper(workspace)
.toString() :: "--mill-version" :: millVersion :: fullcmd
case Some(script) => script :: cmd
case None => embeddedMillWrapper(workspace).toString() :: fullcmd
}

}
Expand Down Expand Up @@ -110,10 +106,9 @@ case class MillBuildTool(

override def bloopInstallArgs(workspace: AbsolutePath): List[String] = {
val millVersion = getMillVersion(projectRoot)

val cmd =
bloopImportArgs(millVersion) ::: bloopCmd(millVersion) :: Nil
putTogetherArgs(cmd, millVersion, workspace)
putTogetherArgs(cmd, workspace)
}

override def digest(workspace: AbsolutePath): Option[String] =
Expand Down Expand Up @@ -141,7 +136,7 @@ case class MillBuildTool(
): Option[List[String]] =
Option.when(workspaceSupportsBsp(workspace: AbsolutePath)) {
val cmd = "mill.bsp.BSP/install" :: "--jobs" :: "0" :: Nil
putTogetherArgs(cmd, getMillVersion(projectRoot), workspace)
putTogetherArgs(cmd, workspace)
}

def workspaceSupportsBsp(workspace: AbsolutePath): Boolean = {
Expand Down
2 changes: 2 additions & 0 deletions tests/slow/src/test/scala/tests/mill/MillLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class MillLspSuite extends BaseImportSuite("mill-import") {
| def scalaVersion = "${V.scala213}"
| def scalacOptions = Seq("-Xfatal-warnings", "-Ywarn-unused")
|}
|/.mill-version
|${V.millVersion}
|/foo/src/Warning.scala
|import scala.concurrent.Future // unused
|object Warning
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/src/test/scala/tests/MillVersionSuite.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package tests
package scala.meta.internal.builds.tests

import scala.meta.internal.builds.MillBuildTool
import scala.meta.internal.metals.UserConfiguration

import tests._

class MillVersionSuite extends BaseSuite {

def check(
Expand All @@ -12,8 +14,8 @@ class MillVersionSuite extends BaseSuite {
test(expected) {
val root = FileLayout.fromString(layout)
val obtained =
MillBuildTool(() => UserConfiguration(), root).bloopInstallArgs(root)
assert(obtained.contains(expected))
MillBuildTool(() => UserConfiguration(), root).getMillVersion(root)
assertEquals(obtained, expected)
}
}

Expand Down

0 comments on commit 0206537

Please sign in to comment.