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

Add buildTargets/jvmEnvironment endpoint #1214

Merged
merged 3 commits into from
Apr 2, 2020

Conversation

lukaszwawrzyk
Copy link
Contributor

Depends on build-server-protocol/build-server-protocol#113
Just implements the new endpoint, to currently be exactly the same as jvmTestEnvironment.
Fills in new optional parameters javaHome and javaVersion, currently based on the jvm that bloop is running on. In future we may allow to customize it through Config.Project

@@ -863,6 +864,13 @@ final class BloopBspServices(
private def toBuildTargetId(project: Project): bsp.BuildTargetIdentifier =
bsp.BuildTargetIdentifier(project.bspUri)

private def toJvmBuildTarget(project: Project): bsp.JvmBuildTarget = {
val javaHome = sys.props.get("java.home").map(s => bsp.Uri(Paths.get(s).toUri))
Copy link
Contributor

@olafurpg olafurpg Mar 27, 2020

Choose a reason for hiding this comment

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

nit: sys.props allocates a new immutable map containing all system properties on every method call so I personally use Option(System.getProperty(..)) instead

@jvican jvican added build server Any issue or pull request that has to do with hot compilers or BSP. enhancement upgrade labels Mar 28, 2020
Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

LGTM 👍 We can merge this once the BSP PR is released

@@ -863,6 +864,13 @@ final class BloopBspServices(
private def toBuildTargetId(project: Project): bsp.BuildTargetIdentifier =
bsp.BuildTargetIdentifier(project.bspUri)

private def toJvmBuildTarget(project: Project): bsp.JvmBuildTarget = {
val javaHome = Option(System.getProperty("java.home")).map(s => bsp.Uri(Paths.get(s).toUri))
Copy link
Contributor

Choose a reason for hiding this comment

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

I just learned from an offline discussion with @jvican that Bloop supports configuring custom Java home per-project. See .platform here

We should use JdkConfig.javaHome instead of the java.home system property.

build.sbt Outdated
@@ -27,6 +27,7 @@ val benchmarkBridge = project
lazy val bloopShared = (project in file("shared"))
.settings(
name := "bloop-shared",
resolvers += Resolver.sonatypeRepo("snapshots"),
Copy link
Contributor

Choose a reason for hiding this comment

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

We should cut a new stable BSP release so we don't use SNAPSHOTs

Copy link
Contributor

@jvican jvican left a comment

Choose a reason for hiding this comment

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

Hey @lukaszwawrzyk thanks for your work, overall LGTM 👍 I've just left some comments and suggestions.

@@ -863,6 +864,20 @@ final class BloopBspServices(
private def toBuildTargetId(project: Project): bsp.BuildTargetIdentifier =
bsp.BuildTargetIdentifier(project.bspUri)

private def toJvmBuildTarget(project: Project): bsp.JvmBuildTarget = {
Option(project.platform)
Copy link
Contributor

Choose a reason for hiding this comment

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

We have some of this logic already in a method called project.jdkConfig. What do you think about using that instead of this? We can also replace the values of java.home and the java version and use those that are available in JavaRuntime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I guess it is enough to use project.jdkConfig, anyway it sets the correct jvm default config if not provided, and if it returns none, JvmBuildTarget can be empty as it means native or js.

val javaHome = Option(System.getProperty("java.home")).map(s => bsp.Uri(Paths.get(s).toUri))
val javaVersion = Option(System.getProperty("java.vm.specification.version"))
bsp.JvmBuildTarget(javaHome, javaVersion)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this method returning a jvm build target always, regardless of the platform?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why return a JvmBuildTarget here for projects that are not JVM?

}
.getOrElse {
val javaHome = Option(System.getProperty("java.home")).map(s => bsp.Uri(Paths.get(s).toUri))
val javaVersion = Option(System.getProperty("java.vm.specification.version"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you really use you want java.vm.specification.version here instead of java.version?

Copy link
Contributor

@jvican jvican left a comment

Choose a reason for hiding this comment

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

What happened to the use of java.specification.vm.version?

val javaHome = Option(System.getProperty("java.home")).map(s => bsp.Uri(Paths.get(s).toUri))
val javaVersion = Option(System.getProperty("java.vm.specification.version"))
bsp.JvmBuildTarget(javaHome, javaVersion)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why return a JvmBuildTarget here for projects that are not JVM?

@@ -863,6 +864,17 @@ final class BloopBspServices(
private def toBuildTargetId(project: Project): bsp.BuildTargetIdentifier =
bsp.BuildTargetIdentifier(project.bspUri)

private def toJvmBuildTarget(project: Project): bsp.JvmBuildTarget = {
project.jdkConfig
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: could we make all of this as concise as possible by using pattern matching here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@lukaszwawrzyk
Copy link
Contributor Author

What happened to the use of java.specification.vm.version?

So I addressed the comment about not filling in JvmBuildTarget in case when target is not jvm.
If project.jdkConfig is None, it means it is Native or Js, so in such case I put JvmBuildTarget(None, None) rather than bloop runtime jvm. I actually never fill in javaVersion, as it is not available in project.platform, and I can't assume that sys.props("java.version") is valid for given project.jdkConfig.javaHome

@jvican
Copy link
Contributor

jvican commented Mar 31, 2020

@lukaszwawrzyk Great, thanks for the changes!

so in such case I put JvmBuildTarget(None, None) rather than bloop runtime jvm.

Why do we return JvmBuildTarget(None, None) instead of None? This looks like a limitation in the BSP design of JvmBuildTarget, we should not assume every ScalaBuildTarget has a JvmBuildTarget, it should accept Option[JvmBuildTarget] instead.

@olafurpg Any thoughts?

@olafurpg
Copy link
Contributor

Good catch! The ScalaBuildTarget.jvmBuildTarget field needs to be typed as Option[BuildTarget], otherwise new clients won't be able to parse ScalaBuildTarget from old servers.

@olafurpg
Copy link
Contributor

We will need to do the same change for bsp4j, this field is optional.

@lukaszwawrzyk lukaszwawrzyk force-pushed the bsp-jdk branch 2 times, most recently from ab49ffe to 3c0f7f1 Compare April 1, 2020 10:31
Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

CI is green now with the updated bsp4s dependency 👍

@olafurpg olafurpg requested a review from jvican April 1, 2020 14:09
@@ -2,6 +2,7 @@ package bloop.bsp

import java.io.InputStream
import java.net.URI
import java.nio.file.Paths
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused import

@jvican
Copy link
Contributor

jvican commented Apr 2, 2020

Spoke with @olafurpg offline and we agreed on merging this so that we don't need to wait for another review cycle to merge this 😄 We'll remove the unused import whenever we set up scalafix automatically in the bloop build.

@jvican jvican merged commit 1a13b52 into scalacenter:master Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build server Any issue or pull request that has to do with hot compilers or BSP. enhancement upgrade
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants