Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/scala-steward-action@v2.59.0
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
3 changes: 2 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "2.7.5"
version = "3.7.8"
runner.dialect = sbt1
assumeStandardLibraryStripMargin = true
docstrings.style = Asterisk
docstrings.wrap = "yes"
Expand Down
14 changes: 7 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,6 @@ lazy val plugin = project
.settings(
moduleName := "sbt-native-image",
sbtPlugin := true,
sbtVersion.in(pluginCrossBuild) := "1.0.0",
crossScalaVersions := List(scala212),
buildInfoPackage := "sbtnativeimage",
buildInfoKeys := Seq[BuildInfoKey](version),
Expand All @@ -55,8 +55,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
106 changes: 55 additions & 51 deletions plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ 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 +165,18 @@ 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 @@ -282,9 +287,9 @@ object NativeImagePlugin extends AutoPlugin {
s"-agentlib:native-image-agent=$agentConfig=${nativeImageAgentOutputDir.value}"
val tpr = thisProjectRef.value
val settings = Seq(
fork in (tpr, Compile, run) := true,
javaHome in (tpr, Compile, run) := Some(graalHome),
javaOptions in (tpr, Compile, run) += agentOption
tpr / Compile / run / fork := true,
tpr / Compile / run / javaHome := Some(graalHome),
tpr / Compile / run / javaOptions += agentOption
)
val state0 = state.value
val extracted = Project.extract(state0)
Expand All @@ -297,7 +302,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 @@ -311,12 +316,12 @@ object NativeImagePlugin extends AutoPlugin {
val agentOption =
s"-agentlib:native-image-agent=$agentConfig=${nativeImageTestAgentOutputDir.value}"

val options = (javaOptions in (Test, run)).value ++ Seq(agentOption)
val options = (Test / run / javaOptions).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"
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 +336,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 +349,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 +389,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 +415,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 +436,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 +462,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 @@ -515,12 +520,11 @@ object NativeImagePlugin extends AutoPlugin {
try {
manifestPath.relativize(dependencyPath).toString
} catch {
//java.lang.IllegalArgumentException: 'other' has different root
//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
// java.lang.IllegalArgumentException: 'other' has different root
// 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 +550,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(_) =>
}
}
}
10 changes: 5 additions & 5 deletions plugin/src/sbt-test/sbt-native-image/agent-test/build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
lazy val example = project
.settings(
scalaVersion := "2.12.12",
mainClass.in(Compile) := Some("example.Hello6"),
scalaVersion := "2.12.18",
Compile / mainClass := Some("example.Hello6"),
nativeImageTestOptions ++= Seq(
s"-H:ReflectionConfigurationFiles=${target.value / "native-image-configs" / "reflect-config.json"}",
"--initialize-at-build-time=scala.collection.immutable.VM",
),
mainClass.in(Test) := Some("org.scalatest.tools.Runner"),
nativeImageTestRunOptions ++= Seq("-o", "-R", classDirectory.in(Test).value.absolutePath),
Test / mainClass := Some("org.scalatest.tools.Runner"),
nativeImageTestRunOptions ++= Seq("-o", "-R", (Test / classDirectory).value.absolutePath),
nativeImageCommand := List(
sys.env.getOrElse(
"NATIVE_IMAGE_COMMAND",
Expand All @@ -16,6 +16,6 @@ lazy val example = project
"variable to point to the absolute path of this binary."
)
),
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.14" % "test"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.16" % Test
)
.enablePlugins(NativeImagePlugin)
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ class Hello6Spec extends AnyFlatSpec {
StandardOpenOption.APPEND
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.9.2
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("org.scalameta" % "sbt-native-image" % sys.props("plugin.version"))
addSbtPlugin("org.scalameta" % "sbt-native-image" % sys.props("plugin.version"))
4 changes: 2 additions & 2 deletions plugin/src/sbt-test/sbt-native-image/agent/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
lazy val example = project
.settings(
scalaVersion := "2.12.12",
mainClass.in(Compile) := Some("example.Hello3"),
scalaVersion := "2.12.18",
Compile / mainClass := Some("example.Hello3"),
nativeImageOptions ++= Seq(
"--no-fallback",
s"-H:ReflectionConfigurationFiles=${ target.value / "native-image-configs" / "reflect-config.json" }"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("org.scalameta" % "sbt-native-image" % sys.props("plugin.version"))
addSbtPlugin("org.scalameta" % "sbt-native-image" % sys.props("plugin.version"))
Loading