Skip to content

Commit

Permalink
Give some love to the project
Browse files Browse the repository at this point in the history
- Update Scala version
- Update sbt and sbt plugins
- Remove deprecated sbt syntax usages
- Update Scalafix and improve its configuration
- Install Scala Steward to help us maintain this project
- Fix Scalafix issues in code
  • Loading branch information
guizmaii committed Jul 16, 2023
1 parent 40a86b2 commit e8fac8a
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 62 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/scala-steward.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Scala Steward

# This workflow will launch everyday at 00:00
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch: {}

jobs:
scala-steward:
timeout-minutes: 30
runs-on: ubuntu-latest
name: Scala Steward
steps:
- name: Scala Steward
uses: scala-steward-org/[email protected]
25 changes: 24 additions & 1 deletion .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
rules = [
OrganizeImports,
DisableSyntax
ExplicitResultTypes
LeakingImplicitClassVal
NoAutoTupling
NoValInForComprehension
ProcedureSyntax
RemoveUnused
OrganizeImports
]

RemoveUnused {
imports = false // See https://github.com/scalacenter/scalafix/blob/v0.11.0/docs/rules/OrganizeImports.md#configuration
}

Disable {
ifSynthetic = [
"scala/Option.option2Iterable"
"scala/Predef.any2stringadd"
]
}

DisableSyntax.noReturns = true
DisableSyntax.noXml = true
DisableSyntax.noFinalize = true
DisableSyntax.noValPatterns = true

ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = false

OrganizeImports.groupedImports = Explode
Expand Down
15 changes: 8 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
def scala212 = "2.12.12"
def scala212 = "2.12.18"

Global / onChangedBuildSource := ReloadOnSourceChanges

inThisBuild(
List(
organization := "org.scalameta",
Expand All @@ -15,16 +18,14 @@ inThisBuild(
)
),
scalaVersion := scala212,
scalafixDependencies +=
"com.github.liancheng" %% "organize-imports" % "0.5.0",
scalacOptions ++= List("-Ywarn-unused-import"),
scalafixCaching := true,
semanticdbEnabled := true
)
)

crossScalaVersions := Nil
skip.in(publish) := true
publish / skip := true

commands +=
Command.command("fixAll") { s =>
Expand All @@ -42,7 +43,7 @@ lazy val plugin = project
.settings(
moduleName := "sbt-native-image",
sbtPlugin := true,
sbtVersion.in(pluginCrossBuild) := "1.0.0",
pluginCrossBuild / sbtVersion := "1.0.0",
crossScalaVersions := List(scala212),
buildInfoPackage := "sbtnativeimage",
buildInfoKeys := Seq[BuildInfoKey](version),
Expand All @@ -55,8 +56,8 @@ lazy val plugin = project
lazy val example = project
.in(file("example"))
.settings(
skip.in(publish) := true,
mainClass.in(Compile) := Some("example.Hello"),
publish / skip := true,
Compile / mainClass := Some("example.Hello"),
test := {
val binary = nativeImage.value
val output = scala.sys.process.Process(List(binary.toString)).!!.trim
Expand Down
87 changes: 42 additions & 45 deletions plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,10 @@ object NativeImagePlugin extends AutoPlugin {

override lazy val projectSettings: Seq[Def.Setting[_]] = List(
libraryDependencies += "org.scalameta" % "svm-subs" % "101.0.0",
target.in(NativeImage) := target.in(Compile).value / "native-image",
target.in(NativeImageTest) := target.in(Test).value / "native-image-test",
target.in(NativeImageInternal) :=
target.in(Compile).value / "native-image-internal",
target.in(NativeImageTestInternal) :=
target.in(Test).value / "native-image-test-internal",
NativeImage / target := (Compile / target).value / "native-image",
NativeImageTest / target := (Test / target).value / "native-image-test",
NativeImageInternal / target := (Compile / target).value / "native-image-internal",
NativeImageTestInternal / target := (Test / target).value / "native-image-test-internal",
nativeImageReady := {
val s = streams.value

Expand All @@ -163,15 +161,15 @@ object NativeImagePlugin extends AutoPlugin {
nativeImageJvm := "graalvm-java11",
nativeImageJvmIndex := "cs",
nativeImageVersion := "20.2.0",
name.in(NativeImage) := name.value,
name.in(NativeImageTest) := name.in(Test).value,
mainClass.in(NativeImage) := mainClass.in(Compile).value,
mainClass.in(NativeImageTest) := mainClass.in(Test).value,
nativeImageOptions := List(),
NativeImage / name := name.value,
NativeImageTest / name := (Test / name).value,
NativeImage / mainClass := (Compile / mainClass).value,
NativeImageTest / mainClass := (Test / mainClass).value,
nativeImageOptions := List.empty,
nativeImageTestOptions := nativeImageOptions.value,
nativeImageTestRunOptions := List(),
nativeImageTestRunOptions := List.empty,
nativeImageCoursier := {
val dir = target.in(NativeImageInternal).value
val dir = (NativeImageInternal / target).value
val out = copyResource("coursier", dir)
if (Properties.isWin) {
copyResource("coursier.bat", dir)
Expand Down Expand Up @@ -297,7 +295,7 @@ object NativeImagePlugin extends AutoPlugin {
arguments.mkString(" ")
Project
.extract(newState)
.runInputTask(run in (tpr, Compile), input, newState)
.runInputTask(tpr / Compile / run, input, newState)
},
nativeImageTestRunAgent := {
val _ = nativeImageTestCommand.value
Expand All @@ -313,11 +311,11 @@ object NativeImagePlugin extends AutoPlugin {

val options = (javaOptions in (Test, run)).value ++ Seq(agentOption)

val __ = compile.in(Test).value
val main = mainClass.in(NativeImageTest).value
val cp = fullClasspath.in(Test).value.map(_.data)
val manifest = target.in(NativeImageTestInternal).value / "manifest.jar"
manifest.getParentFile().mkdirs()
val __ = (Test / compile).value
val main = (NativeImageTest / mainClass).value
val cp = (Test / fullClasspath).value.map(_.data)
val manifest = (NativeImageTestInternal / target).value / "manifest.jar"
manifest.getParentFile.mkdirs()
createManifestJar(manifest, cp)
val nativeClasspath = manifest.absolutePath

Expand All @@ -331,7 +329,7 @@ object NativeImagePlugin extends AutoPlugin {
throw new MessageOnlyException(
"no mainClass is specified for tests. " +
"To fix this problem, update build.sbt to include the settings " +
"`mainClass.in(Test) := Some(\"com.MainTestClass\")`"
"`Test / mainClass := Some(\"com.MainTestClass\")`"
)
)
command ++= nativeImageTestRunOptions.value
Expand All @@ -344,12 +342,12 @@ object NativeImagePlugin extends AutoPlugin {
}
},
nativeImageOutput :=
target.in(NativeImage).value / name.in(NativeImage).value,
(NativeImage / target).value / (NativeImage / name).value,
nativeImageTestOutput :=
target.in(NativeImageTest).value / name.in(NativeImageTest).value,
(NativeImageTest / target).value / (NativeImageTest / name).value,
nativeImageCopy := {
val binary = nativeImage.value
val out = fileParser(baseDirectory.in(ThisBuild).value).parsed
val out = fileParser((ThisBuild / baseDirectory).value).parsed
Files.copy(
binary.toPath(),
out.toPath(),
Expand Down Expand Up @@ -384,17 +382,17 @@ object NativeImagePlugin extends AutoPlugin {
}
},
nativeImage := {
val _ = compile.in(Compile).value
val main = mainClass.in(NativeImage).value
val _ = (Compile / compile).value
val main = (NativeImage / mainClass).value
val binaryName = nativeImageOutput.value
val cp = fullClasspath.in(Compile).value.map(_.data)
val cp = (Compile / fullClasspath).value.map(_.data)
// NOTE(olafur): we pass in a manifest jar instead of the full classpath
// for two reasons:
// * large classpaths quickly hit on the "argument list too large"
// error, especially on Windows.
// * we print the full command to the console and the manifest jar makes
// it more readable and easier to copy-paste.
val manifest = target.in(NativeImageInternal).value / "manifest.jar"
val manifest = (NativeImageInternal / target).value / "manifest.jar"
manifest.getParentFile().mkdirs()
createManifestJar(manifest, cp)
val nativeClasspath = manifest.absolutePath
Expand All @@ -410,14 +408,14 @@ object NativeImagePlugin extends AutoPlugin {
throw new MessageOnlyException(
"no mainClass is specified. " +
"To fix this problem, update build.sbt to include the settings " +
"`mainClass.in(Compile) := Some(\"com.MainClass\")`"
"`Compile / mainClass := Some(\"com.MainClass\")`"
)
)
command += binaryName.absolutePath

// Start native-image linker.
streams.value.log.info(command.mkString(" "))
val cwd = target.in(NativeImage).value
val cwd = (NativeImage / target).value
cwd.mkdirs()
val exit = Process(command, cwd = Some(cwd)).!
if (exit != 0) {
Expand All @@ -431,17 +429,17 @@ object NativeImagePlugin extends AutoPlugin {
binaryName
},
nativeImageTest := {
val _ = compile.in(Test).value
val main = mainClass.in(NativeImageTest).value
val _ = (Test / compile).value
val main = (NativeImageTest / mainClass).value
val binaryName = nativeImageTestOutput.value
val cp = fullClasspath.in(Test).value.map(_.data)
val cp = (Test / fullClasspath).value.map(_.data)
// NOTE(olafur): we pass in a manifest jar instead of the full classpath
// for two reasons:
// * large classpaths quickly hit on the "argument list too large"
// error, especially on Windows.
// * we print the full command to the console and the manifest jar makes
// it more readable and easier to copy-paste.
val manifest = target.in(NativeImageTestInternal).value / "manifest.jar"
val manifest = (NativeImageTestInternal / target).value / "manifest.jar"
manifest.getParentFile().mkdirs()
createManifestJar(manifest, cp)
val nativeClasspath = manifest.absolutePath
Expand All @@ -457,14 +455,14 @@ object NativeImagePlugin extends AutoPlugin {
throw new MessageOnlyException(
"no mainClass is specified for tests. " +
"To fix this problem, update build.sbt to include the settings " +
"`mainClass.in(Test) := Some(\"com.MainTestClass\")`"
"`Test / mainClass := Some(\"com.MainTestClass\")`"
)
)
command += binaryName.absolutePath

// Start native-image linker.
streams.value.log.info(command.mkString(" "))
val cwd = target.in(NativeImageTest).value
val cwd = (NativeImageTest / target).value
cwd.mkdirs()
val exit = Process(command, cwd = Some(cwd)).!
if (exit != 0) {
Expand Down Expand Up @@ -519,8 +517,7 @@ object NativeImagePlugin extends AutoPlugin {
//this happens if the dependency jar resides on a different drive then the manifest, i.e. C:\Coursier\Cache and D:\myapp\target
//copy dependency next to manifest as fallback
case _: IllegalArgumentException =>
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.nio.file.{Files, StandardCopyOption}
Files.copy(
dependencyPath,
manifestPath.resolve(path.getName),
Expand All @@ -546,15 +543,15 @@ object NativeImagePlugin extends AutoPlugin {

private def alertUser(streams: std.TaskStreams[_], message: String): Unit = {
streams.log.info(message)
if (isCI)
return
try {
if (Properties.isMac) {
Process(List("say", message)).!
if (!isCI) {
try {
if (Properties.isMac) {
Process(List("say", message)).!
}
// NOTE(olafur): feel free to add support for Linux/Windows.
} catch {
case NonFatal(_) =>
}
// NOTE(olafur): feel free to add support for Linux/Windows.
} catch {
case NonFatal(_) =>
}
}
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.4.4
sbt.version=1.9.2
16 changes: 8 additions & 8 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.27")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0")

libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value

unmanagedSourceDirectories.in(Compile) +=
baseDirectory.in(ThisBuild).value.getParentFile / "plugin" / "src" / "main" /
Compile / unmanagedSourceDirectories +=
(ThisBuild / baseDirectory).value.getParentFile / "plugin" / "src" / "main" /
"scala"
unmanagedResourceDirectories.in(Compile) +=
baseDirectory.in(ThisBuild).value.getParentFile / "plugin" / "src" / "main" /
Compile / unmanagedResourceDirectories +=
(ThisBuild / baseDirectory).value.getParentFile / "plugin" / "src" / "main" /
"resources"

0 comments on commit e8fac8a

Please sign in to comment.