Skip to content

Commit

Permalink
implement cross JDK forking
Browse files Browse the repository at this point in the history
```
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
```
  • Loading branch information
eed3si9n committed May 5, 2018
1 parent c902091 commit 479a6f3
Show file tree
Hide file tree
Showing 11 changed files with 411 additions and 34 deletions.
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cache:
directories:
- $HOME/.ivy2/cache
- $HOME/.sbt/boot
- $HOME/.jabba

language: scala

Expand All @@ -15,6 +16,15 @@ jdk:
matrix:
fast_finish: true

matrix:
include:
- env: SBT_CMD="scripted java/*"
sudo: true
before_install:
- curl -sL https://raw.githubusercontent.com/shyiko/jabba/0.9.4/install.sh | bash && . ~/.jabba/jabba.sh
install:
- sudo /home/travis/.jabba/bin/jabba install [email protected]

env:
global:
- secure: d3bu2KNwsVHwfhbGgO+gmRfDKBJhfICdCJFGWKf2w3Gv86AJZX9nuTYRxz0KtdvEHO5Xw8WTBZLPb2thSJqhw9OCm4J8TBAVqCP0ruUj4+aqBUFy4bVexQ6WKE6nWHs4JPzPk8c6uC1LG3hMuzlC8RGETXtL/n81Ef1u7NjyXjs=
Expand All @@ -26,7 +36,7 @@ env:
- SBT_CMD="scripted dependency-management/*2of4"
- SBT_CMD="scripted dependency-management/*3of4"
- SBT_CMD="scripted dependency-management/*4of4"
- SBT_CMD="scripted java/* package/* reporter/* run/* project-load/*"
- SBT_CMD="scripted package/* reporter/* run/* project-load/*"
- SBT_CMD="scripted project/*1of2"
- SBT_CMD="scripted project/*2of2"
- SBT_CMD="scripted source-dependencies/*1of3"
Expand Down
28 changes: 14 additions & 14 deletions main/src/main/contraband-scala/sbt/JavaVersion.scala

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions main/src/main/contraband/main.contra
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ enum PluginTrigger {
}

type JavaVersion {
numbers: [Long]
vendor: String
version: String!
#xcompanion def apply(version: String): JavaVersion = new JavaVersion(None, version)

#x def numberStr: String = numbers.mkString(".")
#xtostring vendor.map(_ + "@").getOrElse("") + numberStr

#xcompanion def apply(version: String): JavaVersion = sbt.internal.CrossJava.parseJavaVersion(version)
}
24 changes: 14 additions & 10 deletions main/src/main/scala/sbt/Cross.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,23 @@ object Cross {
}

/**
* Parse the given command into either an aggregate command or a command for a project
* Parse the given command into a list of aggregate projects and command to issue.
*/
private def parseCommand(command: String): Either[String, (String, String)] = {
private[sbt] def parseSlashCommand(extracted: Extracted)(
command: String): (Seq[ProjectRef], String) = {
import extracted._
import DefaultParsers._
val parser = (OpOrID <~ charClass(_ == '/', "/")) ~ any.* map {
case project ~ cmd => (project, cmd.mkString)
case seg1 ~ cmd => (seg1, cmd.mkString)
}
Parser.parse(command, parser) match {
case Right((seg1, cmd)) =>
structure.allProjectRefs.find(_.project == seg1) match {
case Some(proj) => (Seq(proj), cmd)
case _ => (resolveAggregates(extracted), command)
}
case _ => (resolveAggregates(extracted), command)
}
Parser.parse(command, parser).left.map(_ => command)
}

def crossBuild: Command =
Expand All @@ -115,12 +124,7 @@ object Cross {
private def crossBuildCommandImpl(state: State, args: CrossArgs): State = {
val x = Project.extract(state)
import x._

val (aggs, aggCommand) = parseCommand(args.command) match {
case Right((project, cmd)) =>
(structure.allProjectRefs.filter(_.project == project), cmd)
case Left(cmd) => (resolveAggregates(x), cmd)
}
val (aggs, aggCommand) = parseSlashCommand(x)(args.command)

val projCrossVersions = aggs map { proj =>
proj -> crossVersions(x, proj)
Expand Down
3 changes: 2 additions & 1 deletion main/src/main/scala/sbt/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ object Keys {
val scalaCompilerBridgeSource = settingKey[ModuleID]("Configures the module ID of the sources of the compiler bridge.").withRank(CSetting)
val scalaArtifacts = settingKey[Seq[String]]("Configures the list of artifacts which should match the Scala binary version").withRank(CSetting)
val enableBinaryCompileAnalysis = settingKey[Boolean]("Writes the analysis file in binary format")
val crossJavaVersions = settingKey[Seq[JavaVersion]]("The java versions used during JDK cross testing").withRank(BPlusSetting)

val clean = taskKey[Unit]("Deletes files produced by the build, such as generated sources, compiled classes, and task caches.").withRank(APlusTask)
val console = taskKey[Unit]("Starts the Scala interpreter with the project classes on the classpath.").withRank(APlusTask)
Expand Down Expand Up @@ -273,7 +274,7 @@ object Keys {
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)
val fullJavaHomes = settingKey[Map[JavaVersion, File]]("Combines discoveredJavaHomes and custom javaHomes.").withRank(CTask)

val javaOptions = taskKey[Seq[String]]("Options passed to a new JVM when forking.").withRank(BPlusTask)
val envVars = taskKey[Map[String, String]]("Environment variables used when forking a new JVM").withRank(BTask)
Expand Down
3 changes: 3 additions & 0 deletions main/src/main/scala/sbt/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import sbt.internal.{
BuildUnit,
CommandExchange,
CommandStrings,
CrossJava,
DefaultBackgroundJobService,
EvaluateConfigurations,
Inspect,
Expand Down Expand Up @@ -189,6 +190,8 @@ object BuiltinCommands {
loadFailed,
Cross.crossBuild,
Cross.switchVersion,
CrossJava.switchJavaHome,
CrossJava.crossJavaHome,
PluginCross.pluginCross,
PluginCross.pluginSwitch,
Cross.crossRestoreSession,
Expand Down
25 changes: 25 additions & 0 deletions main/src/main/scala/sbt/internal/CommandStrings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,29 @@ $SwitchCommand [<scala-version>=]<scala-home>[!] [-v] [<command>]

See also `help $CrossCommand`
"""

val JavaCrossCommand = "java+"
val JavaSwitchCommand = "java++"

def javaCrossHelp: Help = Help.more(JavaCrossCommand, JavaCrossDetailed)
def javaSwitchHelp: Help = Help.more(JavaSwitchCommand, JavaSwitchDetailed)

def JavaCrossDetailed =
s"""$JavaCrossCommand <command>
Runs <command> for each JDK version specified for cross-JDK testing.
For each string in `crossJavaVersions` in the current project, this command sets the
`javaHome` of all projects to the corresponding Java home, reloads the build,
and executes <command>. When finished, it reloads the build with the original
`javaHome`.
Note that `Test / fork := true` is needed for `javaHome` to be effective.
See also `help $JavaSwitchCommand`
"""

def JavaSwitchDetailed =
s"""$JavaSwitchCommand <java-version>
Changes the JDK version and runs a command.
Sets the `javaHome` of all projects to <java-version> and
reloads the build. If <command> is provided, it is then executed.
See also `help $JavaSwitchCommand`
"""
}
Loading

0 comments on commit 479a6f3

Please sign in to comment.