Skip to content

Commit

Permalink
More Scala 3 backports (#4370)
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi authored Jan 19, 2025
1 parent 6038f26 commit 8d0c719
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 42 deletions.
1 change: 1 addition & 0 deletions bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import mill.runner.MillBuildRootModule
import mill.scalalib.bsp.{BspModule, JvmBuildTarget, ScalaBuildTarget}
import mill.scalalib.{JavaModule, SemanticDbJavaModule, TestModule}
import mill.util.ColorLogger
import mill.given

import java.io.PrintStream
import java.util.concurrent.CompletableFuture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ object ClientApp {
new dom.RequestInit {
method = dom.HttpMethod.POST
}
).then[String](response => response.text())
.then[Unit] { text =>
).`then`[String](response => response.text())
.`then`[Unit] { text =>
todoApp.innerHTML = text
initListeners()
}
Expand Down Expand Up @@ -57,8 +57,8 @@ object ClientApp {
method = dom.HttpMethod.POST
body = newTodoInput.value
}
).then[String](response => response.text())
.then[Unit] { text =>
).`then`[String](response => response.text())
.`then`[Unit] { text =>
newTodoInput.value = ""
todoApp.innerHTML = text
initListeners()
Expand Down
1 change: 1 addition & 0 deletions idea/src/mill/idea/GenIdea.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mill.idea

import mill.given
import mill.Task
import mill.api.Result
import mill.define.{Command, Discover, ExternalModule}
Expand Down
28 changes: 22 additions & 6 deletions idea/src/mill/idea/GenIdeaImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,13 @@ case class GenIdeaImpl(
<library name={name} type="Scala">
<properties>
{
if (languageLevel.isDefined) <language-level>{languageLevel.get}</language-level>
if (languageLevel.isDefined)
<language-level>{languageLevel.get}</language-level>
else {
// Scala 3: I assume there is some missing implicit conversion from `()` to NodeSeq,
// so use an explicit seq.
NodeSeq.Empty
}
}
<compiler-classpath>
{
Expand All @@ -791,9 +797,15 @@ case class GenIdeaImpl(
}
</compiler-classpath>
{
if (compilerBridgeJar.isDefined) <compiler-bridge-binary-jar>{
relativeFileUrl(compilerBridgeJar.get)
}</compiler-bridge-binary-jar>
if (compilerBridgeJar.isDefined)
<compiler-bridge-binary-jar>{
relativeFileUrl(compilerBridgeJar.get)
}</compiler-bridge-binary-jar>
else {
// Scala 3: I assume there is some missing implicit conversion from `()` to NodeSeq,
// so use an explicit seq.
NodeSeq.Empty
}
}
</properties>
</library>
Expand All @@ -813,8 +825,12 @@ case class GenIdeaImpl(
{
if (sources.isDefined) {
<SOURCES>
<root url={relativeJarUrl(sources.get)}/>
</SOURCES>
<root url={relativeJarUrl(sources.get)}/>
</SOURCES>
} else {
// Scala 3: I assume there is some missing implicit conversion from `()` to NodeSeq,
// so use an explicit seq.
NodeSeq.Empty
}
}
</library>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ object ModuleInitErrorTests extends UtestIntegrationTestSuite {
}

test("tasks") - integrationTest { tester =>
import tester._
// If we specify a task in the root module, we are not
// affected by the sub-modules failing to initialize
import tester._
val res = eval("rootTask")
assert(res.isSuccess == true)
assert(res.out.contains("""Running rootTask"""))

import tester._
// If we specify a task in the root module, we are not
// affected by the sub-modules failing to initialize
val res1 = eval(("rootCommand", "-s", "hello"))
Expand Down
3 changes: 2 additions & 1 deletion integration/feature/full-run-logs/src/FullRunLogsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ object FullRunLogsTests extends UtestIntegrationTestSuite {
.replace("<digits>", "\\E\\d+\\Q")
.replace("<dashes>", "\\E=+\\Q")

assert(expectedErrorRegex.r.matches(res.err.replace('\\', '/').replaceAll("(\r\n)|\r", "\n")))
val normErr = res.err.replace('\\', '/').replaceAll("(\r\n)|\r", "\n")
assert(expectedErrorRegex.r.matches(normErr))
}
test("show") - integrationTest { tester =>
import tester._
Expand Down
15 changes: 5 additions & 10 deletions integration/ide/gen-idea/src/GenIdeaExtendedTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mill.integration
import mill.testkit.UtestIntegrationTestSuite
import utest._

import scala.util.Try
import os.Path

object GenIdeaExtendedTests extends UtestIntegrationTestSuite {
Expand All @@ -18,16 +17,12 @@ object GenIdeaExtendedTests extends UtestIntegrationTestSuite {

eval("mill.idea.GenIdea/")

val checks = resources.map { resource =>
Try {
GenIdeaUtils.assertIdeaXmlResourceMatchesFile(
workspacePath,
resource
)
}
for (resource <- resources) {
GenIdeaUtils.assertIdeaXmlResourceMatchesFile(
workspacePath,
resource
)
}
assert(checks.forall(_.isSuccess))
}
}

}
22 changes: 8 additions & 14 deletions integration/ide/gen-idea/src/GenIdeaUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,15 @@ object GenIdeaUtils {
val expectedResourcePath = workspacePath / "idea" / resource
val actualResourcePath = workspacePath / ".idea" / resource

val check = Try {
val expectedResourceString = os.read.lines(expectedResourcePath).mkString("\n")
val actualResourceString = normaliseLibraryPaths(os.read(actualResourcePath), workspacePath)

assertPartialContentMatches(
found = actualResourceString,
expected = expectedResourceString,
resource.toString()
)
}
println(
s"Checking ${expectedResourcePath.relativeTo(workspacePath)} ... ${if (check.isSuccess) "OK"
else "FAILED"}"
println(s"Checking ${expectedResourcePath.relativeTo(workspacePath)} ...")
val expectedResourceString = os.read.lines(expectedResourcePath).mkString("\n")
val actualResourceString = normaliseLibraryPaths(os.read(actualResourcePath), workspacePath)

assertPartialContentMatches(
found = actualResourceString,
expected = expectedResourceString,
resource.toString()
)
check.get
}

def assertPartialContentMatches(found: String, expected: String, context: String = ""): Unit = {
Expand Down
2 changes: 1 addition & 1 deletion main/codesig/src/ReachabilityAnalysis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ object CallGraphAnalysis {
.groupMap(_._1)(_._2)

val reverseGraphEdges =
indexGraphEdges.indices.map(reverseGraphMap.getOrElse(_, Array())).toArray
indexGraphEdges.indices.map(reverseGraphMap.getOrElse(_, Array[Int]())).toArray

SpanningForest.spanningTreeToJsonTree(
SpanningForest.apply(reverseGraphEdges, nodesWithChangedHashes, false),
Expand Down
4 changes: 3 additions & 1 deletion main/src/mill/main/SelectiveExecution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ private[mill] object SelectiveExecution {

(
changedRootTasks,
breadthFirst(changedRootTasks)(downstreamEdgeMap.getOrElse(_, Nil))
breadthFirst(changedRootTasks) { t =>
downstreamEdgeMap.getOrElse(t.asInstanceOf[Task[Nothing]], Nil)
}
)
}

Expand Down
3 changes: 1 addition & 2 deletions scalalib/src/mill/scalalib/Assembly.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import java.util.Collections
import java.util.jar.JarFile
import java.util.regex.Pattern
import scala.jdk.CollectionConverters._
import scala.tools.nsc.io.Streamable
import scala.util.Using

case class Assembly(pathRef: PathRef, addedEntries: Int)
Expand Down Expand Up @@ -139,7 +138,7 @@ object Assembly {
val shader = Shader.bytecodeShader(shadeRules, verbose = false, skipManifest = true)
(name: String, inputStream: UnopenedInputStream) => {
val is = inputStream()
shader(Streamable.bytes(is), name).map {
shader(is.readAllBytes(), name).map {
case (bytes, name) =>
name -> (() =>
new ByteArrayInputStream(bytes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ object CoursierParametersTests extends TestSuite {
}
def resolutionParams = Task.Anon {
super.resolutionParams()
.addForceVersion((mod"com.lihaoyi:pprint_2.13", "0.8.1"))
.addForceVersion((
coursier.Module(
coursier.Organization("com.lihaoyi"),
coursier.ModuleName("pprint_2.13")
),
"0.8.1"
))
}
}
}
Expand Down

0 comments on commit 8d0c719

Please sign in to comment.