Merge pull request #3995 from ruippeixotog/cross-strict-aggregation

Filter incompatible aggregates in cross switch commands
This commit is contained in:
Dale Wijnand 2018-03-08 11:27:55 +00:00 committed by GitHub
commit 80d342a811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 4 deletions

View File

@ -216,12 +216,30 @@ object Cross {
Command.arb(requireSession(switchParser), switchHelp)(switchCommandImpl)
private def switchCommandImpl(state: State, args: Switch): State = {
val switchedState = switchScalaVersion(args, state)
val x = Project.extract(state)
val (switchedState, affectedRefs) = switchScalaVersion(args, state)
args.command.toList ::: switchedState
val strictCmd =
if (args.version.force) {
// The Scala version was forced on the whole build, run as is
args.command
} else {
args.command.map { rawCmd =>
parseCommand(rawCmd) match {
case Right(_) => rawCmd // A project is specified, run as is
case Left(cmd) =>
resolveAggregates(x)
.intersect(affectedRefs)
.collect { case ProjectRef(_, proj) => s"$proj/$cmd" }
.mkString("all ", " ", "")
}
}
}
strictCmd.toList ::: switchedState
}
private def switchScalaVersion(switch: Switch, state: State): State = {
private def switchScalaVersion(switch: Switch, state: State): (State, Seq[ResolvedReference]) = {
val extracted = Project.extract(state)
import extracted._
@ -291,7 +309,7 @@ object Cross {
}
}
setScalaVersionForProjects(version, instance, projects, state, extracted)
(setScalaVersionForProjects(version, instance, projects, state, extracted), projects.map(_._1))
}
private def setScalaVersionForProjects(

View File

@ -0,0 +1,8 @@
[@ruippeixotog]: https://github.com/ruippeixotog
[#3698]: https://github.com/sbt/sbt/issues/3698
[#3995]: https://github.com/sbt/sbt/pull/3995
### Improvements
- Make `++ <scala-version> <command>` run `<command>` only on compatible subprojects. [#3698][]/[#3995][] by [@ruippeixotog][]

View File

@ -0,0 +1,13 @@
lazy val root = (project in file("."))
.aggregate(core, module)
lazy val core = (project in file("core"))
.settings(
scalaVersion := "2.12.4",
crossScalaVersions := Seq("2.11.11", "2.12.4"))
lazy val module = (project in file("module"))
.dependsOn(core)
.settings(
scalaVersion := "2.12.4",
crossScalaVersions := Seq("2.12.4"))

View File

@ -0,0 +1,5 @@
package foo
object Foo {
}

View File

@ -0,0 +1,5 @@
package foo.module
object FooModule {
}

View File

@ -0,0 +1,5 @@
> ++2.11.11 compile
$ exists core/target/scala-2.11
-$ exists module/target/scala-2.11
-$ exists module/target/scala-2.12