Skip to content

Commit e785630

Browse files
authored
Merge pull request #2508 from tgodzik/fix-system
bugfix: Don't try to always get system jvm first
2 parents 51f6cf9 + a19707a commit e785630

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

modules/core/src/main/scala/scala/build/internals/OsLibc.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,7 @@ object OsLibc {
7474
}
7575

7676
def defaultJvm(os: String): String = {
77-
val hasEmptyJavaHome = Option(System.getenv("JAVA_HOME")).exists(_.trim.isEmpty)
78-
val defaultJvm0 = baseDefaultJvm(os, defaultJvmVersion)
79-
if (hasEmptyJavaHome)
80-
// Not using the system JVM if JAVA_HOME is set to an empty string
81-
// (workaround for https://github.com/coursier/coursier/issues/2292)
82-
defaultJvm0
83-
else
84-
s"${JavaHome.systemId}|$defaultJvm0"
77+
baseDefaultJvm(os, defaultJvmVersion)
8578
}
8679

8780
def javaVersion(javaCmd: String): Int = {

modules/integration/src/test/scala/scala/cli/integration/StandaloneLauncherTests.scala

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,28 @@ import java.io.File
66

77
class StandaloneLauncherTests extends ScalaCliSuite {
88

9-
if (TestUtil.isJvmCli)
10-
test(s"Standalone launcher should run with java 8") {
11-
// It should download Java 17 and use it to run itself
12-
val message = "Hello World"
13-
val inputs = TestInputs(
14-
os.rel / "hello.sc" -> s"""println("$message")"""
9+
test(s"Standalone launcher should run with java 8") {
10+
// It should download Java 17 and use it to run itself
11+
val message = "Hello World"
12+
val inputs = TestInputs(
13+
os.rel / "hello.sc" -> s"""println("$message")"""
14+
)
15+
inputs.fromRoot { root =>
16+
val java8Home =
17+
os.Path(os.proc(TestUtil.cs, "java-home", "--jvm", "zulu:8").call().out.trim(), os.pwd)
18+
19+
val extraEnv = Map(
20+
"JAVA_HOME" -> java8Home.toString,
21+
"PATH" -> ((java8Home / "bin").toString + File.pathSeparator + System.getenv("PATH"))
1522
)
16-
inputs.fromRoot { root =>
17-
val java8Home =
18-
os.Path(os.proc(TestUtil.cs, "java-home", "--jvm", "zulu:8").call().out.trim(), os.pwd)
1923

20-
val extraEnv = Map(
21-
"JAVA_HOME" -> java8Home.toString,
22-
"PATH" -> ((java8Home / "bin").toString + File.pathSeparator + System.getenv("PATH"))
23-
)
24+
// we need to exit to check if the launcher is actually starting the right version of java
25+
os.proc(TestUtil.cli, "--power", "bloop", "exit").call(cwd = root, env = extraEnv).out.trim()
2426

25-
val output =
26-
os.proc(TestUtil.cli, ".").call(cwd = root, env = extraEnv).out.trim()
27+
val output =
28+
os.proc(TestUtil.cli, ".").call(cwd = root, env = extraEnv).out.trim()
2729

28-
expect(output == message)
29-
}
30+
expect(output == message)
3031
}
32+
}
3133
}

modules/options/src/main/scala/scala/build/options/BuildOptions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ object BuildOptions {
557557
def envUpdates(currentEnv: Map[String, String]): Map[String, String] = {
558558
// On Windows, AFAIK, env vars are "case-insensitive but case-preserving".
559559
// If PATH was defined as "Path", we need to update "Path", not "PATH".
560-
// Same for JAVA_HOME.
560+
// Same for JAVA_HOME
561561
def keyFor(name: String) =
562562
if (Properties.isWin)
563563
currentEnv.keys.find(_.equalsIgnoreCase(name)).getOrElse(name)

modules/options/src/main/scala/scala/build/options/JavaOptions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ final case class JavaOptions(
149149
}
150150

151151
private def findLocalDefaultJava(): Option[Positioned[os.Path]] =
152-
Option(System.getenv("JAVA_HOME")).map(p =>
152+
Option(System.getenv("JAVA_HOME")).filter(_.nonEmpty).map(p =>
153153
Positioned(Position.Custom("JAVA_HOME env"), os.Path(p, os.pwd))
154154
).orElse(
155155
sys.props.get("java.home").map(p =>

0 commit comments

Comments
 (0)