mirror of https://github.com/sbt/sbt.git
Merge pull request #5512 from eed3si9n/wip/cross-fix
cross building tests and fixes
This commit is contained in:
commit
e65224c834
|
|
@ -54,12 +54,17 @@ object Cross {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val spacedVersion = if (spacePresent) version else version & spacedFirst(SwitchCommand)
|
val spacedVersion = if (spacePresent) version else version & spacedFirst(SwitchCommand)
|
||||||
val verbose = Parser.opt(token(Space ~> "-v"))
|
val verboseOpt = Parser.opt(token(Space ~> "-v"))
|
||||||
val optionalCommand = Parser.opt(token(Space ~> matched(state.combinedParser)))
|
val optionalCommand = Parser.opt(token(Space ~> matched(state.combinedParser)))
|
||||||
(spacedVersion ~ verbose ~ optionalCommand).map {
|
val switch1 = (token(Space ~> "-v") ~> (Space ~> version) ~ optionalCommand) map {
|
||||||
|
case v ~ command =>
|
||||||
|
Switch(v, true, command)
|
||||||
|
}
|
||||||
|
val switch2 = (spacedVersion ~ verboseOpt ~ optionalCommand) map {
|
||||||
case v ~ verbose ~ command =>
|
case v ~ verbose ~ command =>
|
||||||
Switch(v, verbose.isDefined, command)
|
Switch(v, verbose.isDefined, command)
|
||||||
}
|
}
|
||||||
|
switch1 | switch2
|
||||||
}
|
}
|
||||||
|
|
||||||
token(SwitchCommand ~> OptSpace) flatMap { sp =>
|
token(SwitchCommand ~> OptSpace) flatMap { sp =>
|
||||||
|
|
@ -195,11 +200,11 @@ object Cross {
|
||||||
commandsByVersion.flatMap {
|
commandsByVersion.flatMap {
|
||||||
case (v, commands) =>
|
case (v, commands) =>
|
||||||
commands match {
|
commands match {
|
||||||
case Seq(c) => Seq(s"$SwitchCommand $verbose $v! $c")
|
case Seq(c) => Seq(s"$SwitchCommand $verbose $v $c")
|
||||||
case Seq() => Nil // should be unreachable
|
case Seq() => Nil // should be unreachable
|
||||||
case multi if fullArgs.isEmpty =>
|
case multi if fullArgs.isEmpty =>
|
||||||
Seq(s"$SwitchCommand $verbose $v! all ${multi.mkString(" ")}")
|
Seq(s"$SwitchCommand $verbose $v all ${multi.mkString(" ")}")
|
||||||
case multi => Seq(s"$SwitchCommand $verbose $v!") ++ multi
|
case multi => Seq(s"$SwitchCommand $verbose $v") ++ multi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -242,15 +247,18 @@ object Cross {
|
||||||
if (args.version.force) {
|
if (args.version.force) {
|
||||||
// The Scala version was forced on the whole build, run as is
|
// The Scala version was forced on the whole build, run as is
|
||||||
args.command
|
args.command
|
||||||
} else {
|
} else
|
||||||
args.command.map { rawCmd =>
|
args.command.map { rawCmd =>
|
||||||
val (aggs, aggCommand) = parseSlashCommand(Project.extract(state))(rawCmd)
|
// for now, treat `all` command specially
|
||||||
aggs
|
if (rawCmd.startsWith("all ")) rawCmd
|
||||||
.intersect(affectedRefs)
|
else {
|
||||||
.map({ case ProjectRef(_, proj) => s"$proj/$aggCommand" })
|
val (aggs, aggCommand) = parseSlashCommand(Project.extract(state))(rawCmd)
|
||||||
.mkString("all ", " ", "")
|
aggs
|
||||||
|
.intersect(affectedRefs)
|
||||||
|
.map({ case ProjectRef(_, proj) => s"$proj/$aggCommand" })
|
||||||
|
.mkString("all ", " ", "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
strictCmd.toList ::: switchedState
|
strictCmd.toList ::: switchedState
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
lazy val check = taskKey[Unit]("")
|
||||||
|
lazy val compile2 = taskKey[Unit]("")
|
||||||
|
|
||||||
|
lazy val root = (project in file("."))
|
||||||
|
.aggregate(foo, bar, client)
|
||||||
|
.settings(
|
||||||
|
crossScalaVersions := Nil,
|
||||||
|
addCommandAlias("build", "compile2"),
|
||||||
|
)
|
||||||
|
|
||||||
|
lazy val foo = project
|
||||||
|
.settings(
|
||||||
|
crossScalaVersions := Seq("2.12.11", "2.13.1"),
|
||||||
|
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.0",
|
||||||
|
|
||||||
|
check := {
|
||||||
|
// This tests that +check will respect bar's crossScalaVersions and not switch
|
||||||
|
val x = (LocalProject("bar") / scalaVersion).value
|
||||||
|
assert(x == "2.12.11", s"$x == 2.12.11")
|
||||||
|
(Compile / compile).value
|
||||||
|
},
|
||||||
|
(Test / testOnly) := {
|
||||||
|
// This tests that +testOnly will respect bar's crossScalaVersions and not switch
|
||||||
|
val x = (LocalProject("bar") / scalaVersion).value
|
||||||
|
assert(x == "2.12.11", s"$x == 2.12.11")
|
||||||
|
val _ = (Test / testOnly).evaluated
|
||||||
|
},
|
||||||
|
compile2 := {
|
||||||
|
// This tests that +build will ignore bar's crossScalaVersions and use root's like sbt 0.13
|
||||||
|
val x = (LocalProject("bar") / scalaVersion).value
|
||||||
|
assert(x == scalaVersion.value, s"$x == ${scalaVersion.value}")
|
||||||
|
(Compile / compile).value
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
lazy val bar = project
|
||||||
|
.settings(
|
||||||
|
crossScalaVersions := Seq("2.12.11"),
|
||||||
|
check := (Compile / compile).value,
|
||||||
|
compile2 := (Compile / compile).value,
|
||||||
|
)
|
||||||
|
|
||||||
|
lazy val baz = project
|
||||||
|
.settings(
|
||||||
|
crossScalaVersions := Seq("2.13.1"),
|
||||||
|
check := {
|
||||||
|
// This tests that +baz/check will respect bar's crossScalaVersions and not switch
|
||||||
|
val x = (LocalProject("bar") / scalaVersion).value
|
||||||
|
assert(x == "2.12.11", s"$x == 2.12.11")
|
||||||
|
(Compile / compile).value
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
lazy val client = project
|
||||||
|
.settings(
|
||||||
|
crossScalaVersions := Seq("2.12.11", "2.13.1"),
|
||||||
|
check := (Compile / compile).value,
|
||||||
|
compile2 := (Compile / compile).value,
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
> + clean
|
||||||
|
|
||||||
|
## verbose
|
||||||
|
> + -v compile
|
||||||
|
|
||||||
|
## test scoped task
|
||||||
|
## this should not force any Scala version changes to other subprojects
|
||||||
|
> + baz/check
|
||||||
|
|
||||||
|
## test input task
|
||||||
|
> + foo / testOnly foo.FooSpec
|
||||||
|
> + testOnly foo.FooSpec
|
||||||
|
|
||||||
|
## test + with task in multi-project with different Scala versions
|
||||||
|
> + check
|
||||||
|
|
||||||
|
## test + with command or alias
|
||||||
|
> clean
|
||||||
|
## for command cross building you do need crossScalaVerions on root
|
||||||
|
> set root/crossScalaVersions := Seq("2.12.11", "2.13.1")
|
||||||
|
> + build
|
||||||
|
$ exists foo/target/scala-2.12
|
||||||
|
$ exists foo/target/scala-2.13
|
||||||
|
$ exists bar/target/scala-2.12
|
||||||
|
$ exists bar/target/scala-2.13
|
||||||
|
$ exists client/target/scala-2.12
|
||||||
|
$ exists client/target/scala-2.13
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
lazy val root = (project in file("."))
|
|
||||||
.aggregate(foo, client)
|
|
||||||
.settings(
|
|
||||||
crossScalaVersions := Nil
|
|
||||||
)
|
|
||||||
|
|
||||||
lazy val foo = project
|
|
||||||
.settings(
|
|
||||||
crossScalaVersions := Seq("2.12.11", "2.13.1"),
|
|
||||||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.0",
|
|
||||||
)
|
|
||||||
|
|
||||||
lazy val client = project
|
|
||||||
.settings(
|
|
||||||
crossScalaVersions := Seq("2.12.11", "2.13.1"),
|
|
||||||
)
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
> + clean
|
|
||||||
|
|
||||||
> + foo / testOnly foo.FooSpec
|
|
||||||
|
|
||||||
> + testOnly foo.FooSpec
|
|
||||||
|
|
@ -1,20 +1,24 @@
|
||||||
scalaVersion in ThisBuild := "2.7.7"
|
ThisBuild / scalaVersion := "2.11.12"
|
||||||
|
|
||||||
scalaVersion := "2.9.1"
|
lazy val root = (project in file("."))
|
||||||
|
.settings(
|
||||||
|
scalaVersion := "2.12.11",
|
||||||
|
|
||||||
scalaVersion in update := {
|
update / scalaVersion := {
|
||||||
scalaVersion.value match {
|
scalaVersion.value match {
|
||||||
case "2.9.1" => "2.9.0-1"
|
case "2.12.11" => "2.12.10"
|
||||||
case "2.8.2" => "2.8.1"
|
case "2.11.12" => "2.11.11"
|
||||||
case x => x
|
case x => x
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
InputKey[Unit]("check") := {
|
InputKey[Unit]("check") := {
|
||||||
val args = Def.spaceDelimited().parsed
|
val args = Def.spaceDelimited().parsed
|
||||||
def check(label: String, i: Int, actual: String) =
|
def checkV(label: String, i: Int, actual: String) =
|
||||||
assert(args(i) == actual, s"Expected $label='${args(i)}' got '$actual'")
|
assert(args(i) == actual, s"Expected $label='${args(i)}' got '$actual'")
|
||||||
check("scalaVersion in ThisBuild", 0, scalaVersion in ThisBuild value)
|
|
||||||
check("scalaVersion", 1, scalaVersion.value)
|
checkV("ThisBuild / scalaVersion", 0, (ThisBuild / scalaVersion).value)
|
||||||
check("scalaVersion in update", 2, scalaVersion in update value)
|
checkV("scalaVersion", 1, scalaVersion.value)
|
||||||
}
|
checkV("update / scalaVersion", 2, (update / scalaVersion).value)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
> check 2.7.7 2.9.1 2.9.0-1
|
> check 2.11.12 2.12.11 2.12.10
|
||||||
> ++ 2.8.2!
|
|
||||||
> check 2.8.2 2.8.2 2.8.1
|
> ++ 2.11.12!
|
||||||
> ++ 2.10.4!
|
> check 2.11.12 2.11.12 2.11.11
|
||||||
|
|
||||||
|
> ++ 2.13.1!
|
||||||
> set resolvers ++= Nil
|
> set resolvers ++= Nil
|
||||||
> check 2.10.4 2.10.4 2.10.4
|
> check 2.13.1 2.13.1 2.13.1
|
||||||
|
|
||||||
> session clear-all
|
> session clear-all
|
||||||
> check 2.7.7 2.9.1 2.9.0-1
|
> check 2.11.12 2.12.11 2.12.10
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue