-
Notifications
You must be signed in to change notification settings - Fork 949
Cross JDK forking #4139
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
Cross JDK forking #4139
Conversation
@@ -17,3 +17,9 @@ enum PluginTrigger { | |||
AllRequirements | |||
NoTrigger | |||
} | |||
|
|||
type JavaVersion { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added pseudo case class for JavaVersion, instead of using String.
main/src/main/scala/sbt/Keys.scala
Outdated
@@ -268,6 +268,10 @@ object Keys { | |||
val outputStrategy = settingKey[Option[sbt.OutputStrategy]]("Selects how to log output when running a main class.").withRank(DSetting) | |||
val connectInput = settingKey[Boolean]("If true, connects standard input when running a main class forked.").withRank(CSetting) | |||
val javaHome = settingKey[Option[File]]("Selects the Java installation used for compiling and forking. If None, uses the Java installation running the build.").withRank(ASetting) | |||
val discoveredJavaHomes = settingKey[Map[JavaVersion, File]]("Discovered Java home directories") | |||
val javaHomes = settingKey[Map[JavaVersion, File]]("The user-defined additional Java home directories") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Custom key is named javaHomes
.
main/src/main/scala/sbt/Keys.scala
Outdated
@@ -268,6 +268,10 @@ object Keys { | |||
val outputStrategy = settingKey[Option[sbt.OutputStrategy]]("Selects how to log output when running a main class.").withRank(DSetting) | |||
val connectInput = settingKey[Boolean]("If true, connects standard input when running a main class forked.").withRank(CSetting) | |||
val javaHome = settingKey[Option[File]]("Selects the Java installation used for compiling and forking. If None, uses the Java installation running the build.").withRank(ASetting) | |||
val discoveredJavaHomes = settingKey[Map[JavaVersion, File]]("Discovered Java home directories") | |||
val javaHomes = settingKey[Map[JavaVersion, File]]("The user-defined additional Java home directories") | |||
val fullJavaHomes = taskKey[Map[JavaVersion, File]]("Combines discoveredJavaHomes and custom javaHomes.").withRank(CTask) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fullJavaHomes
is a task if someone wants to side effect. (Credit to Dale)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to switch this back to a setting since carrying the state around aggregation is pain in the ass when implementing a command.
I've a yak to shave about Short-term solution: can we make it an Long-term solution: one idea that I was thinking was to experiment modelling "java version" using a sum type to give a selection like jenv, where when I added Oracle JDK 1.8.0.144 I got the following selection of identifiers to choose from:
So the usual pitfalls need to be avoids:
So perhaps a starting point would be to make |
I'm overthinking it. I'm designing for use cases I don't quite have clear. Which makes me realise: what are the motivating use cases we're looking to solve with this change? Can we explore that space before committing to a stable public API? /cc @2m who I assume can provide the Akka use cases |
Implemented |
@dwijnand We can iterate by changing the implementation of |
Can we remove its other companion object applies and methods from the public API too? |
I think what you're talking about can be achieved by making bunch of duplicate entries in discoveredJavaHomes like e6fa634 or jEnv without being too paranoid about JavaVersion. |
Can we discuss the use cases before committing to new public API? |
Or, let's just make |
We have a couple of use-cases in Akka:
|
Given the uses cases, the minor version and vendor handling of JDK variety should be considered out of scope of this PR. Also given that |
0478546
to
c165d6b
Compare
|
||
> java++ 10! | ||
> run | ||
> check 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cross JDK testing using jabba installed openjdk 10.
We don't need to keep bincompat if we declare the whole feature experimental, which is what I'm proposing. |
I was thinking how we would document this feature, and realized that we shouldn't expose
|
da4a6ca
to
fa74f85
Compare
1fed9d8
to
ef09829
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Looking good. The cross building functionality is getting more and more ripe for factoring out to a more general behaviour.
``` sbt:helloworld> java++ 10 [info] Reapplying settings... sbt:helloworld> run [info] Running (fork) Hello [info] 10.0.1 sbt:helloworld> java++ 8 [info] Reapplying settings... sbt:helloworld> run [info] Running (fork) Hello [info] 1.8.0_171 ```
Ref shyiko/jabba#190 Bumping to jabba 0.9.6 fixes sporaditc permission issues.
ef09829
to
9b7c224
Compare
object JavaDiscoverConfig { | ||
val linux = new JavaDiscoverConf { | ||
val base: File = file("/usr") / "lib" / "jvm" | ||
val JavaHomeDir = """java-([0-9]+)-.*""".r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this regex won't match on a default Fedora Open JDK install. See akka/akka#25298
This is a refactoring/continuation of #4136 by @2m reflecting review comments by @dwijnand
original description
This PR proposes a discovery for Java home directories implemented by scanning well known system directories for available java installations. Currently this PR only addresses Linux and MacOS. // @cunei
This PR is a first step towards cross building across different Java versions.
Discovering Java home directories is also useful when a project needs to locate
rt.jar
of a different java installation (for example when working around-release 8
limitaions in JDK9)