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

Ensure that passing Java props into Scala CLI as launcher args would also pass it into BSP configuration #3169

Merged
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
5 changes: 5 additions & 0 deletions modules/cli/src/main/scala/scala/cli/ScalaCli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ object ScalaCli {
def getDefaultScalaVersion: String =
launcherOptions.scalaRunner.cliUserScalaVersion.getOrElse(Constants.defaultScalaVersion)

private var launcherJavaPropArgs: List[String] = List.empty

def getLauncherJavaPropArgs: List[String] = launcherJavaPropArgs

private def partitionArgs(args: Array[String]): (Array[String], Array[String]) = {
val systemProps = args.takeWhile(_.startsWith("-D"))
(systemProps, args.drop(systemProps.size))
Expand Down Expand Up @@ -294,6 +298,7 @@ object ScalaCli {
}
}
val (systemProps, scalaCliArgs) = partitionArgs(remainingArgs)
if systemProps.nonEmpty then launcherJavaPropArgs = systemProps.toList
setSystemProps(systemProps)

(new BouncycastleSignerMaker).maybeInit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ abstract class ScalaCommand[T <: HasGlobalOptions](implicit myParser: Parser[T],
private val globalOptionsAtomic: AtomicReference[GlobalOptions] =
new AtomicReference(GlobalOptions.default)

private def globalOptions: GlobalOptions = globalOptionsAtomic.get()
protected def launcherOptions: LauncherOptions = ScalaCli.launcherOptions
protected def defaultScalaVersion: String = ScalaCli.getDefaultScalaVersion
private def globalOptions: GlobalOptions = globalOptionsAtomic.get()
protected def launcherOptions: LauncherOptions = ScalaCli.launcherOptions
protected def defaultScalaVersion: String = ScalaCli.getDefaultScalaVersion
protected def launcherJavaPropArgs: List[String] = ScalaCli.getLauncherJavaPropArgs

def sharedOptions(t: T): Option[SharedOptions] = // hello borked unused warning
None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ object SetupIde extends ScalaCommand[SetupIdeOptions] {
val bspArgs =
List(launcher) ++
finalLauncherOptions.toCliArgs ++
launcherJavaPropArgs ++
List("bsp") ++
debugOpt ++
List("--json-options", scalaCliBspJsonDestination.toString) ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
) {
val scriptName = "cli-version.sc"
val inputs = TestInputs(
os.rel / scriptName -> s"""println("Hello from launcher v$cliVersion"""
os.rel / scriptName -> s"""println("Hello from launcher v$cliVersion")"""
)
inputs.fromRoot { root =>
val cliVersionArgs = List("--cli-version", cliVersion)
Expand All @@ -2202,4 +2202,17 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
expect(bspConfig.argv.indexOfSlice(cliVersionArgs) < bspConfig.argv.indexOf("bsp"))
}
}

test("setup-ide passes Java props to the BSP configuration correctly") {
val scriptName = "hello.sc"
TestInputs(os.rel / scriptName -> s"""println("Hello")""").fromRoot { root =>
val javaProps = List("-Dfoo=bar", "-Dbar=baz")
os.proc(TestUtil.cli, javaProps, "setup-ide", scriptName, extraOptions)
.call(cwd = root)
val bspConfig = readBspConfig(root)
expect(bspConfig.argv.head == TestUtil.cliPath)
expect(bspConfig.argv.containsSlice(javaProps))
expect(bspConfig.argv.indexOfSlice(javaProps) < bspConfig.argv.indexOf("bsp"))
}
}
}
Loading