Skip to content

Commit

Permalink
Merge pull request #3995 from ruippeixotog/cross-strict-aggregation
Browse files Browse the repository at this point in the history
Filter incompatible aggregates in cross switch commands
  • Loading branch information
dwijnand committed Mar 8, 2018
2 parents a85d760 + 251e5ab commit 80d342a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
26 changes: 22 additions & 4 deletions main/src/main/scala/sbt/Cross.scala
Expand Up @@ -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)

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 ", " ", "")
}
}
}

args.command.toList ::: switchedState
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._

Expand Down Expand Up @@ -291,7 +309,7 @@ object Cross {
}
}

setScalaVersionForProjects(version, instance, projects, state, extracted)
(setScalaVersionForProjects(version, instance, projects, state, extracted), projects.map(_._1))
}

private def setScalaVersionForProjects(
Expand Down
8 changes: 8 additions & 0 deletions notes/1.2.0/cross-strict-aggregation.md
@@ -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][]
13 changes: 13 additions & 0 deletions sbt/src/sbt-test/actions/cross-strict-aggregation/build.sbt
@@ -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"))
@@ -0,0 +1,5 @@
package foo

object Foo {

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

object FooModule {

}
5 changes: 5 additions & 0 deletions sbt/src/sbt-test/actions/cross-strict-aggregation/test
@@ -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

0 comments on commit 80d342a

Please sign in to comment.