diff --git a/main/src/main/scala/sbt/Cross.scala b/main/src/main/scala/sbt/Cross.scala index 2bdde84dd..21902e4d4 100644 --- a/main/src/main/scala/sbt/Cross.scala +++ b/main/src/main/scala/sbt/Cross.scala @@ -54,12 +54,17 @@ object Cross { } } 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))) - (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 => Switch(v, verbose.isDefined, command) } + switch1 | switch2 } token(SwitchCommand ~> OptSpace) flatMap { sp => @@ -195,11 +200,11 @@ object Cross { commandsByVersion.flatMap { case (v, commands) => 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 multi if fullArgs.isEmpty => - Seq(s"$SwitchCommand $verbose $v! all ${multi.mkString(" ")}") - case multi => Seq(s"$SwitchCommand $verbose $v!") ++ multi + Seq(s"$SwitchCommand $verbose $v all ${multi.mkString(" ")}") + case multi => Seq(s"$SwitchCommand $verbose $v") ++ multi } } } @@ -242,15 +247,18 @@ object Cross { if (args.version.force) { // The Scala version was forced on the whole build, run as is args.command - } else { + } else args.command.map { rawCmd => - val (aggs, aggCommand) = parseSlashCommand(Project.extract(state))(rawCmd) - aggs - .intersect(affectedRefs) - .map({ case ProjectRef(_, proj) => s"$proj/$aggCommand" }) - .mkString("all ", " ", "") + // for now, treat `all` command specially + if (rawCmd.startsWith("all ")) rawCmd + else { + val (aggs, aggCommand) = parseSlashCommand(Project.extract(state))(rawCmd) + aggs + .intersect(affectedRefs) + .map({ case ProjectRef(_, proj) => s"$proj/$aggCommand" }) + .mkString("all ", " ", "") + } } - } strictCmd.toList ::: switchedState } diff --git a/sbt/src/sbt-test/actions/cross-advanced/build.sbt b/sbt/src/sbt-test/actions/cross-advanced/build.sbt new file mode 100644 index 000000000..ae2d20ef1 --- /dev/null +++ b/sbt/src/sbt-test/actions/cross-advanced/build.sbt @@ -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, + ) diff --git a/sbt/src/sbt-test/actions/cross-test-only/foo/src/test/scala/foo/FooSpec.scala b/sbt/src/sbt-test/actions/cross-advanced/foo/src/test/scala/foo/FooSpec.scala similarity index 100% rename from sbt/src/sbt-test/actions/cross-test-only/foo/src/test/scala/foo/FooSpec.scala rename to sbt/src/sbt-test/actions/cross-advanced/foo/src/test/scala/foo/FooSpec.scala diff --git a/sbt/src/sbt-test/actions/cross-advanced/test b/sbt/src/sbt-test/actions/cross-advanced/test new file mode 100644 index 000000000..96d9ad0f7 --- /dev/null +++ b/sbt/src/sbt-test/actions/cross-advanced/test @@ -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 diff --git a/sbt/src/sbt-test/actions/cross-test-only/build.sbt b/sbt/src/sbt-test/actions/cross-test-only/build.sbt deleted file mode 100644 index c6f6e6e89..000000000 --- a/sbt/src/sbt-test/actions/cross-test-only/build.sbt +++ /dev/null @@ -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"), - ) diff --git a/sbt/src/sbt-test/actions/cross-test-only/test b/sbt/src/sbt-test/actions/cross-test-only/test deleted file mode 100644 index fa3b4e0a4..000000000 --- a/sbt/src/sbt-test/actions/cross-test-only/test +++ /dev/null @@ -1,5 +0,0 @@ -> + clean - -> + foo / testOnly foo.FooSpec - -> + testOnly foo.FooSpec diff --git a/sbt/src/sbt-test/actions/cross/build.sbt b/sbt/src/sbt-test/actions/cross/build.sbt index 6d1b52a23..02bce3223 100644 --- a/sbt/src/sbt-test/actions/cross/build.sbt +++ b/sbt/src/sbt-test/actions/cross/build.sbt @@ -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 := { - scalaVersion.value match { - case "2.9.1" => "2.9.0-1" - case "2.8.2" => "2.8.1" - case x => x - } -} + update / scalaVersion := { + scalaVersion.value match { + case "2.12.11" => "2.12.10" + case "2.11.12" => "2.11.11" + case x => x + } + }, -InputKey[Unit]("check") := { - val args = Def.spaceDelimited().parsed - def check(label: String, i: Int, actual: String) = - 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) - check("scalaVersion in update", 2, scalaVersion in update value) -} + InputKey[Unit]("check") := { + val args = Def.spaceDelimited().parsed + def checkV(label: String, i: Int, actual: String) = + assert(args(i) == actual, s"Expected $label='${args(i)}' got '$actual'") + + checkV("ThisBuild / scalaVersion", 0, (ThisBuild / scalaVersion).value) + checkV("scalaVersion", 1, scalaVersion.value) + checkV("update / scalaVersion", 2, (update / scalaVersion).value) + } + ) diff --git a/sbt/src/sbt-test/actions/cross/test b/sbt/src/sbt-test/actions/cross/test index 0ea962b97..974f3fdc2 100644 --- a/sbt/src/sbt-test/actions/cross/test +++ b/sbt/src/sbt-test/actions/cross/test @@ -1,8 +1,11 @@ -> check 2.7.7 2.9.1 2.9.0-1 -> ++ 2.8.2! -> check 2.8.2 2.8.2 2.8.1 -> ++ 2.10.4! +> check 2.11.12 2.12.11 2.12.10 + +> ++ 2.11.12! +> check 2.11.12 2.11.12 2.11.11 + +> ++ 2.13.1! > 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 -> check 2.7.7 2.9.1 2.9.0-1 \ No newline at end of file +> check 2.11.12 2.12.11 2.12.10