Skip to content

Commit 3b3563b

Browse files
GedochaoMee-Tree
authored andcommitted
Update scalafmt to 3.9.1 & switch to using native images from scalameta (VirtusLab#3521)
1 parent 0ebfe40 commit 3b3563b

File tree

10 files changed

+37
-30
lines changed

10 files changed

+37
-30
lines changed

.scalafmt.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "3.8.6"
1+
version = "3.9.1"
22

33
align.preset = more
44
maxColumn = 100

DEV.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ Here's some of the more important external projects used by Scala CLI:
192192
[libsodium](https://github.com/jedisct1/libsodium), that is used by Scala CLI to encrypt secrets
193193
uploaded as GitHub repository secrets in the `publish setup` sub-command
194194
- [scala-cli-setup](https://github.com/VirtusLab/scala-cli-setup): a GitHub Action to install Scala CLI.
195-
- [scalafmt-native-image](https://github.com/VirtusLab/scalafmt-native-image): GraalVM native-image launchers
196-
for `scalafmt`.
197195
- [bloop-core](https://github.com/scala-cli/bloop-core): a fork of [bloop](https://github.com/scalacenter/bloop)
198196
stripped up of its benchmark infrastructure and build integrations.
199197
- [no-crc32-zip-input-stream](https://github.com/VirtusLab/no-crc32-zip-input-stream): A copy of `ZipInputStream`
@@ -203,6 +201,10 @@ Here's some of the more important external projects used by Scala CLI:
203201
- [java-class-name](https://github.com/VirtusLab/java-class-name): a small library to extract class names
204202
from Java sources.
205203

204+
Legacy projects:
205+
- [scalafmt-native-image](https://github.com/VirtusLab/scalafmt-native-image): GraalVM native-image launchers
206+
for `scalafmt` (used for `scalafmt` versions < 3.9.1, no longer maintained)
207+
206208
The use of external binaries allows to make the Scala CLI binary slimmer and faster
207209
to generate, but also allow to lower memory requirements to generate it (allowing to
208210
generate these binaries on the GitHub-provided GitHub actions hosts).

modules/cli/src/main/scala/scala/cli/commands/fmt/FmtOptions.scala

+12-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import scala.build.options.BuildOptions
1010
import scala.cli.ScalaCli.fullRunnerName
1111
import scala.cli.commands.shared.{HasSharedOptions, HelpGroup, HelpMessages, SharedOptions}
1212
import scala.cli.commands.{Constants, tags}
13+
import scala.cli.coursierVersion
1314
import scala.util.Properties
1415

1516
// format: off
@@ -96,12 +97,18 @@ final case class FmtOptions(
9697
.getOrElse(FetchExternalBinary.platformSuffix())
9798
val tag0 = scalafmtTag.getOrElse("v" + version)
9899
val gitHubOrgName0 = scalafmtGithubOrgName.getOrElse {
99-
if (Version(version) < Version("3.5.9"))
100-
"scala-cli/scalafmt-native-image"
101-
else // from version 3.5.9 scalafmt-native-image repository was moved to VirtusLab organisation
102-
"virtuslab/scalafmt-native-image"
100+
version.coursierVersion match {
101+
case v if v < "3.5.9".coursierVersion => "scala-cli/scalafmt-native-image"
102+
// since version 3.5.9 scalafmt-native-image repository was moved to VirtusLab organisation
103+
case v if v < "3.9.1".coursierVersion => "virtuslab/scalafmt-native-image"
104+
// since version 3.9.1 native images for all platforms are provided by ScalaMeta
105+
case _ => "scalameta/scalafmt"
106+
}
107+
}
108+
val extension0 = version match {
109+
case v if v.coursierVersion >= "3.9.1".coursierVersion || Properties.isWin => ".zip"
110+
case _ => ".gz"
103111
}
104-
val extension0 = if (Properties.isWin) ".zip" else ".gz"
105112
val url =
106113
s"https://github.com/$gitHubOrgName0/releases/download/$tag0/scalafmt-$osArchSuffix0$extension0"
107114
(url, !tag0.startsWith("v"))

modules/cli/src/test/scala/cli/tests/ScalafmtTest.scala

+11-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import scala.cli.commands.fmt.{FmtOptions, FmtUtil}
1010
import scala.cli.commands.update.Update.Release
1111

1212
class ScalafmtTests extends munit.FunSuite {
13+
private lazy val defaultScalafmtVersion = Constants.defaultScalafmtVersion
1314

1415
test("readVersionFromFile with non-default scalafmt version") {
1516
val confFile = """runner.dialect = scala213
@@ -34,27 +35,25 @@ class ScalafmtTests extends munit.FunSuite {
3435
}
3536
}
3637

37-
test("check native launcher availability for scalafmt") {
38+
test(s"check native launcher availability for scalafmt $defaultScalafmtVersion") {
3839
final case class Asset(name: String)
3940
final case class Release(tag_name: String, assets: List[Asset])
4041
lazy val releaseCodec: JsonValueCodec[Release] = JsonCodecMaker.make
41-
42-
val scalaFmtVersion = Constants.defaultScalafmtVersion
4342
val url =
44-
s"https://api.github.com/repos/virtuslab/scalafmt-native-image/releases/tags/v$scalaFmtVersion"
43+
s"https://api.github.com/repos/scalameta/scalafmt/releases/tags/v$defaultScalafmtVersion"
4544

4645
val expectedAssets = Seq(
47-
"scalafmt-x86_64-apple-darwin.gz",
48-
"scalafmt-x86_64-pc-linux-mostly-static.gz",
49-
"scalafmt-x86_64-pc-linux-static.gz",
50-
"scalafmt-x86_64-pc-linux.gz",
51-
"scalafmt-x86_64-pc-win32.zip"
46+
"scalafmt-x86_64-apple-darwin.zip",
47+
"scalafmt-x86_64-pc-linux.zip",
48+
"scalafmt-x86_64-pc-win32.zip",
49+
"scalafmt-aarch64-apple-darwin.zip",
50+
"scalafmt-aarch64-pc-linux.zip"
5251
)
5352
val errorMsg =
54-
s"""scalafmt native images missing for v$scalaFmtVersion, make a release at https://github.com/VirtusLab/scalafmt-native-image
53+
s"""scalafmt native images missing for v$defaultScalafmtVersion at https://github.com/scalameta/scalafmt
5554
|Ensure that all expected assets are available in the release:
5655
| ${expectedAssets.mkString(", ")}
57-
|for scalafmt-native-image under tag v$scalaFmtVersion.""".stripMargin
56+
|under tag v$defaultScalafmtVersion.""".stripMargin
5857
try {
5958
val resp = TestUtil.downloadFile(url).orThrow
6059
val release = readFromArray(resp)(releaseCodec)
@@ -68,7 +67,7 @@ class ScalafmtTests extends munit.FunSuite {
6867
catch {
6968
case e: JsonReaderException => throw new Exception(s"Error reading $url", e)
7069
case e: Throwable => throw new Exception(
71-
s"""Failed to check for the ScalaFmt native launcher assets: ${e.getMessage}
70+
s"""Failed to check for the ScalaFmt $defaultScalafmtVersion native launcher assets: ${e.getMessage}
7271
|
7372
|$errorMsg
7473
|""".stripMargin,

modules/integration/src/test/scala/scala/cli/integration/DependencyUpdateTests.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class DependencyUpdateTests extends ScalaCliSuite {
2525
)
2626
expect(p.out.trim().contains("Updated dependency"))
2727
expect( // check if dependency update command modify file
28-
os.read(root / fileName) != fileContent)
28+
os.read(root / fileName) != fileContent
29+
)
2930

3031
// after updating dependencies app should run
3132
val out = os.proc(TestUtil.cli, fileName).call(cwd = root).out.trim()

modules/integration/src/test/scala/scala/cli/integration/FmtTests.scala

+2-5
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,8 @@ class FmtTests extends ScalaCliSuite {
9595

9696
test("filter correctly with --check") {
9797
simpleInputsWithFilter.fromRoot { root =>
98-
val out = os.proc(TestUtil.cli, "fmt", ".", "--check").call(cwd = root).out.trim()
99-
val outLines = out.linesIterator.toSeq
100-
expect(outLines.length == 2)
101-
expect(outLines.head == "Looking for unformatted files...")
102-
expect(outLines.last == "All files are formatted with scalafmt :)")
98+
val out = os.proc(TestUtil.cli, "fmt", ".", "--check").call(cwd = root).out.trim()
99+
expect(out == "All files are formatted with scalafmt :)")
103100
}
104101
}
105102

project/deps.sc

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ object Deps {
118118
def jsoniterScalaJava8 = "2.13.5.2"
119119
def jsoup = "1.18.3"
120120
def scalaMeta = "4.13.2"
121+
def scalafmt = "3.9.1"
121122
def scalaNative04 = "0.4.17"
122123
def scalaNative05 = "0.5.7"
123124
def scalaNative = scalaNative05
@@ -211,7 +212,7 @@ object Deps {
211212
def scala3Compiler(sv: String) = ivy"org.scala-lang:scala3-compiler_3:$sv"
212213
def scalaAsync = ivy"org.scala-lang.modules::scala-async:1.0.1".exclude("*" -> "*")
213214
def scalac(sv: String) = ivy"org.scala-lang:scala-compiler:$sv"
214-
def scalafmtCli = ivy"org.scalameta:scalafmt-cli_2.13:3.8.6"
215+
def scalafmtCli = ivy"org.scalameta:scalafmt-cli_2.13:${Versions.scalafmt}"
215216
// Force using of 2.13 - is there a better way?
216217
def scalaJsEnvJsdomNodejs =
217218
ivy"org.scala-js:scalajs-env-jsdom-nodejs_2.13:1.1.0"

website/docs/reference/cli-options.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ Pass a global dialect for scalafmt. This overrides whatever value is configured
501501

502502
Aliases: `--fmt-version`
503503

504-
Pass scalafmt version before running it (3.8.6 by default). If passed, this overrides whatever value is configured in the .scalafmt.conf file.
504+
Pass scalafmt version before running it (3.9.1 by default). If passed, this overrides whatever value is configured in the .scalafmt.conf file.
505505

506506
## Global suppress warning options
507507

website/docs/reference/scala-command/cli-options.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ Aliases: `--fmt-version`
370370

371371
`IMPLEMENTATION specific` per Scala Runner specification
372372

373-
Pass scalafmt version before running it (3.8.6 by default). If passed, this overrides whatever value is configured in the .scalafmt.conf file.
373+
Pass scalafmt version before running it (3.9.1 by default). If passed, this overrides whatever value is configured in the .scalafmt.conf file.
374374

375375
## Global suppress warning options
376376

website/docs/reference/scala-command/runner-specification.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3936,7 +3936,7 @@ Aliases: `--dialect`
39363936

39373937
**--scalafmt-version**
39383938

3939-
Pass scalafmt version before running it (3.8.6 by default). If passed, this overrides whatever value is configured in the .scalafmt.conf file.
3939+
Pass scalafmt version before running it (3.9.1 by default). If passed, this overrides whatever value is configured in the .scalafmt.conf file.
39403940

39413941
Aliases: `--fmt-version`
39423942

0 commit comments

Comments
 (0)