Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sbt graalVMVersionCheck does not fail during reload #9396

Merged
merged 1 commit into from
Mar 13, 2024
Merged
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
11 changes: 3 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,15 @@ val currentEdition = sys.env.getOrElse(
val stdLibVersion = defaultDevEnsoVersion
val targetStdlibVersion = ensoVersion

lazy val graalVMVersionCheck = taskKey[Unit]("Check GraalVM and Java versions")
graalVMVersionCheck := {
// Inspired by https://www.scala-sbt.org/1.x/docs/Howto-Startup.html#How+to+take+an+action+on+startup
lazy val startupStateTransition: State => State = { s: State =>
GraalVM.versionCheck(
graalVersion,
graalMavenPackagesVersion,
javaVersion,
state.value.log
s
)
}

// Inspired by https://www.scala-sbt.org/1.x/docs/Howto-Startup.html#How+to+take+an+action+on+startup
lazy val startupStateTransition: State => State = { s: State =>
"graalVMVersionCheck" :: s
}
Global / onLoad := {
val old = (Global / onLoad).value
startupStateTransition compose old
Expand Down
15 changes: 9 additions & 6 deletions project/GraalVM.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ object GraalVM {
graalVersion: String,
graalPackagesVersion: String,
javaVersion: String,
log: ManagedLogger
): Unit = {
oldState: State
): State = {
val log = oldState.log
if (graalPackagesVersion != version) {
log.error(
s"Expected GraalVM packages version $version, but got $graalPackagesVersion. " +
s"Version specified in build.sbt and GraalVM.scala must be in sync"
)
throw new IllegalStateException("GraalVM version check failed")
return oldState.fail
}
val javaVendor = System.getProperty("java.vendor")
if (!allowedJavaVendors.contains(javaVendor)) {
Expand All @@ -143,7 +144,7 @@ object GraalVM {
s"Running on Java version $javaSpecVersion. " +
s"Expected Java version $javaVersion."
)
throw new IllegalStateException("java.specification.vendor check failed")
return oldState.fail
}

val vmVersion = System.getProperty("java.vm.version")
Expand All @@ -154,13 +155,15 @@ object GraalVM {
s"Running on GraalVM version $version. " +
s"Expected GraalVM version $graalVersion."
)
throw new IllegalStateException("java.vm.version check failed")
oldState.fail
} else {
oldState
}
case None =>
log.error(
s"Could not parse GraalVM version from java.vm.version: $vmVersion."
)
throw new IllegalStateException("java.vm.version check failed")
oldState.fail
}
}

Expand Down
Loading