Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this for now. We actually have our own scalameta steward here which we can add this repo to once we get this merged in.

Copy link
Copy Markdown
Collaborator Author

@guizmaii guizmaii Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, I'd prefer to keep it as, usually, external Scala Steward instances are making PRs from a fork, which makes it harder (if not impossible) to commit on the branches made by Scala Steward (if we need to fix something on one of the update branches)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine to switch this. We do the same for all the rest of the scalameta projects. Since the PRs are not on the main branch of the fork, a maintainer of the repo is able to add another commit to it.

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
}
Comment on lines +12 to +14
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nit, but we are sort of mixing styles with how we have this setting defined and how we have the ones below defined. Can we change this to

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

Just to be consistent with how we do the DisableSyntax down below. We can do the same with Disable.ifSynthetic


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
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",
Comment thread
ckipp01 marked this conversation as resolved.
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),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed at all?

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
100 changes: 52 additions & 48 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 @@ -519,8 +524,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 +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)
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
10 changes: 5 additions & 5 deletions plugin/src/sbt-test/sbt-native-image/basic-test/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.Hello4"),
scalaVersion := "2.12.18",
Compile / mainClass := Some("example.Hello4"),
nativeImageCommand := List(
sys.env.getOrElse(
"NATIVE_IMAGE_COMMAND",
Expand All @@ -13,8 +13,8 @@ lazy val example = project
nativeImageTestOptions ++= Seq(
"--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),
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.14" % "test"
Test / mainClass := Some("org.scalatest.tools.Runner"),
nativeImageTestRunOptions ++= Seq("-o", "-R", (Test / classDirectory).value.absolutePath),
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.16" % Test
)
.enablePlugins(NativeImagePlugin)
4 changes: 2 additions & 2 deletions plugin/src/sbt-test/sbt-native-image/basic/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.Hello2"),
scalaVersion := "2.12.18",
Compile / mainClass := Some("example.Hello2"),
nativeImageCommand := List(
sys.env.getOrElse(
"NATIVE_IMAGE_COMMAND",
Expand Down
Loading