From bbef5479b869fb8fa862696a86d5df819d99bbf9 Mon Sep 17 00:00:00 2001 From: Scala Steward <43047562+scala-steward@users.noreply.github.com> Date: Tue, 21 Jan 2025 09:35:58 +0100 Subject: [PATCH] Update scala-library to 2.13.16 & downgrade JLine to 3.25.0 (#64) --- build.sc | 68 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/build.sc b/build.sc index 57765d1..1cc3fd2 100644 --- a/build.sc +++ b/build.sc @@ -8,12 +8,39 @@ import io.github.alexarchambault.millnativeimage.upload.Upload import mill._ import mill.scalalib._ -def scalafmtVersion = "3.8.3" +object Versions { + def scalafmtVersion = "3.8.3" -trait ScalafmtNativeImage extends ScalaModule with NativeImage { - def scalaVersion = "2.13.13" + def scalaVersion = "2.13.16" - def nativeImageClassPath = T{ + def jline = "3.25.0" + + def coursier = "2.1.0-M5-18-gfebf9838c" +} + +trait ScalafmtNativeImageModule extends ScalaModule { + override def scalaVersion = Versions.scalaVersion + + override def transitiveIvyDeps = T { + super.transitiveIvyDeps() + .map(_.exclude("org.jline" -> "jline-native")) + .map(_.exclude("org.jline" -> "jline-reader")) + .map(_.exclude("org.jline" -> "jline-terminal")) + .map(_.exclude("org.jline" -> "jline-terminal-jna")) + } + + def jlineDeps = Agg( + ivy"org.jline:jline-native:${Versions.jline}", + ivy"org.jline:jline-reader:${Versions.jline}", + ivy"org.jline:jline-terminal:${Versions.jline}", + ivy"org.jline:jline-terminal-jna:${Versions.jline}" + ) + + override def ivyDeps = super.ivyDeps() ++ jlineDeps +} + +trait ScalafmtNativeImage extends ScalafmtNativeImageModule with NativeImage { + def nativeImageClassPath = T { val origCp = runClasspath() val tmpDir = T.dest / "jars" os.makeDir.all(tmpDir) @@ -35,7 +62,7 @@ trait ScalafmtNativeImage extends ScalaModule with NativeImage { zf = new ZipFile(path.toIO) fos = new FileOutputStream(dest.toIO) zos = new ZipOutputStream(fos) - val buf = Array.ofDim[Byte](64*1024) + val buf = Array.ofDim[Byte](64 * 1024) for (ent <- zf.entries.asScala) { val postProcess = ent.getName == "META-INF/native-image/org.scalafmt/scalafmt-cli/native-image.properties" @@ -48,7 +75,7 @@ trait ScalafmtNativeImage extends ScalaModule with NativeImage { zos.putNextEntry(ent0) val baos = new ByteArrayOutputStream var read = -1 - while ({ + while ( { read = is.read(buf) read >= 0 }) { @@ -62,7 +89,7 @@ trait ScalafmtNativeImage extends ScalaModule with NativeImage { else { zos.putNextEntry(ent) var read = -1 - while ({ + while ( { read = is.read(buf) read >= 0 }) { @@ -88,20 +115,27 @@ trait ScalafmtNativeImage extends ScalaModule with NativeImage { p } } - def nativeImageOptions = T{ + + def nativeImageOptions = T { super.nativeImageOptions() ++ Seq( "--no-fallback" ) } + def nativeImagePersist = System.getenv("CI") != null + def nativeImageGraalVmJvmId = "graalvm-java17:22.2.0" + def nativeImageName = "scalafmt" - def ivyDeps = super.ivyDeps() ++ Seq( - ivy"org.scalameta::scalafmt-cli:$scalafmtVersion" + + def ivyDeps = super.ivyDeps() ++ jlineDeps ++ Seq( + ivy"org.scalameta::scalafmt-cli:${Versions.scalafmtVersion}".excludeOrg("org.jline") ) + def nativeImageMainClass = "org.scalafmt.cli.Cli" def nameSuffix = "" + def copyToArtifacts(directory: String = "artifacts/") = T.command { val _ = Upload.copyLauncher( nativeImage().path, @@ -115,24 +149,25 @@ trait ScalafmtNativeImage extends ScalaModule with NativeImage { object native extends ScalafmtNativeImage -def csDockerVersion = "2.1.0-M5-18-gfebf9838c" - object `native-static` extends ScalafmtNativeImage { def nameSuffix = "-static" + def buildHelperImage = T { os.proc("docker", "build", "-t", "scala-cli-base-musl:latest", ".") .call(cwd = os.pwd / "musl-image", stdout = os.Inherit) () } - def nativeImageDockerParams = T{ + + def nativeImageDockerParams = T { buildHelperImage() Some( NativeImage.linuxStaticParams( "scala-cli-base-musl:latest", - s"https://github.com/coursier/coursier/releases/download/v$csDockerVersion/cs-x86_64-pc-linux.gz" + s"https://github.com/coursier/coursier/releases/download/v${Versions.coursier}/cs-x86_64-pc-linux.gz" ) ) } + def writeNativeImageScript(scriptDest: String, imageDest: String = "") = T.command { buildHelperImage() super.writeNativeImageScript(scriptDest, imageDest)() @@ -141,16 +176,17 @@ object `native-static` extends ScalafmtNativeImage { object `native-mostly-static` extends ScalafmtNativeImage { def nameSuffix = "-mostly-static" + def nativeImageDockerParams = Some( NativeImage.linuxMostlyStaticParams( "ubuntu:18.04", // TODO Pin that? - s"https://github.com/coursier/coursier/releases/download/v$csDockerVersion/cs-x86_64-pc-linux.gz" + s"https://github.com/coursier/coursier/releases/download/v${Versions.coursier}/cs-x86_64-pc-linux.gz" ) ) } -def publishVersion = T{ +def publishVersion = T { val state = VcsVersion.vcsState() if (state.commitsSinceLastTag > 0) { val versionOrEmpty = state.lastTag