Redefine crossScalaVersions, because it's Def.derive..

Fixes #3495
This commit is contained in:
Dale Wijnand 2017-09-13 15:45:52 +01:00
parent 3cb281945e
commit 71ae211841
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
4 changed files with 55 additions and 21 deletions

View File

@ -94,7 +94,7 @@ object Cross {
(currentRef :: currentProject.aggregate.toList.flatMap(findAggregates)).distinct
}
private def crossVersions(extracted: Extracted, proj: ProjectRef): Seq[String] = {
private def crossVersions(extracted: Extracted, proj: ResolvedReference): Seq[String] = {
import extracted._
(crossScalaVersions in proj get structure.data) getOrElse {
// reading scalaVersion is a one-time deal
@ -274,12 +274,14 @@ object Cross {
excluded.foreach(logProject.tupled)
}
val projects: Seq[ResolvedReference] = {
val projects: Seq[(ResolvedReference, Seq[ScalaVersion])] = {
val projectScalaVersions =
structure.allProjectRefs.map(proj => proj -> crossVersions(extracted, proj))
if (switch.version.force) {
logSwitchInfo(projectScalaVersions, Nil)
structure.allProjectRefs ++ structure.units.keys.map(BuildRef.apply)
projectScalaVersions ++ structure.units.keys
.map(BuildRef.apply)
.map(proj => proj -> crossVersions(extracted, proj))
} else {
val binaryVersion = CrossVersion.binaryScalaVersion(version)
@ -288,7 +290,7 @@ object Cross {
scalaVersions.exists(v => CrossVersion.binaryScalaVersion(v) == binaryVersion)
}
logSwitchInfo(included, excluded)
included.map(_._1)
included
}
}
@ -298,36 +300,41 @@ object Cross {
private def setScalaVersionForProjects(
version: String,
instance: Option[(File, ScalaInstance)],
projects: Seq[Reference],
projects: Seq[(ResolvedReference, Seq[String])],
state: State,
extracted: Extracted
): State = {
import extracted._
val newSettings = projects.flatMap { project =>
val scope = Scope(Select(project), Zero, Zero, Zero)
val newSettings = projects.flatMap {
case (project, scalaVersions) =>
val scope = Scope(Select(project), Zero, Zero, Zero)
instance match {
case Some((home, inst)) =>
Seq(
scalaVersion in scope := version,
scalaHome in scope := Some(home),
scalaInstance in scope := inst
)
case None =>
Seq(
scalaVersion in scope := version,
scalaHome in scope := None
)
}
instance match {
case Some((home, inst)) =>
Seq(
scalaVersion in scope := version,
crossScalaVersions in scope := scalaVersions,
scalaHome in scope := Some(home),
scalaInstance in scope := inst
)
case None =>
Seq(
scalaVersion in scope := version,
crossScalaVersions in scope := scalaVersions,
scalaHome in scope := None
)
}
}
val filterKeys: Set[AttributeKey[_]] = Set(scalaVersion, scalaHome, scalaInstance).map(_.key)
val projectsContains: Reference => Boolean = projects.map(_._1).toSet.contains
// Filter out any old scala version settings that were added, this is just for hygiene.
val filteredRawAppend = session.rawAppend.filter(_.key match {
case ScopedKey(Scope(Select(ref), Zero, Zero, Zero), key)
if filterKeys.contains(key) && projects.contains(ref) =>
if filterKeys.contains(key) && projectsContains(ref) =>
false
case _ => true
})

View File

@ -0,0 +1,12 @@
[@dwijnand]: https://github.com/dwijnand
[#3495]: https://github.com/sbt/sbt/issues/3495
[#3526]: https://github.com/sbt/sbt/pull/3526
### Fixes with compatibility implications
### Improvements
### Bug fixes
- Fixes `++` so it don't change the value of `crossScalaVersion`. [#3495][]/[#3526][] by [@dwijnand][]

View File

@ -1,3 +1,6 @@
inThisBuild(List(
crossScalaVersions := Seq("2.12.1", "2.11.8")
))
lazy val rootProj = (project in file("."))
.aggregate(libProj, fooPlugin)
@ -20,4 +23,9 @@ lazy val fooPlugin = (project in file("sbt-foo"))
crossScalaVersions := Seq("2.12.1")
)
lazy val extrasProj = (project in file("extras"))
.settings(
name := "foo-extras",
)
addCommandAlias("build", "compile")

View File

@ -46,3 +46,10 @@ $ exists lib/target/scala-2.12
-$ exists lib/target/scala-2.11
$ exists sbt-foo/target/scala-2.12
-$ exists sbt-foo/target/scala-2.11
> clean
# Test ++ leaves crossScalaVersions unchanged
> ++2.12.1
> +extrasProj/compile
$ exists extras/target/scala-2.11
$ exists extras/target/scala-2.12