From 71ae21184125320783a5b493e2ebcf518259e5a8 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 13 Sep 2017 15:45:52 +0100 Subject: [PATCH] Redefine crossScalaVersions, because it's Def.derive.. Fixes #3495 --- main/src/main/scala/sbt/Cross.scala | 49 +++++++++++-------- ...lusplus-not-changing-crossScalaVersions.md | 12 +++++ .../actions/cross-multiproject/build.sbt | 8 +++ .../sbt-test/actions/cross-multiproject/test | 7 +++ 4 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 notes/1.0.2/plusplus-not-changing-crossScalaVersions.md diff --git a/main/src/main/scala/sbt/Cross.scala b/main/src/main/scala/sbt/Cross.scala index c89c32db0..02ff187ee 100644 --- a/main/src/main/scala/sbt/Cross.scala +++ b/main/src/main/scala/sbt/Cross.scala @@ -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 }) diff --git a/notes/1.0.2/plusplus-not-changing-crossScalaVersions.md b/notes/1.0.2/plusplus-not-changing-crossScalaVersions.md new file mode 100644 index 000000000..58e368794 --- /dev/null +++ b/notes/1.0.2/plusplus-not-changing-crossScalaVersions.md @@ -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][] diff --git a/sbt/src/sbt-test/actions/cross-multiproject/build.sbt b/sbt/src/sbt-test/actions/cross-multiproject/build.sbt index 23b73cbe5..d0eff709c 100644 --- a/sbt/src/sbt-test/actions/cross-multiproject/build.sbt +++ b/sbt/src/sbt-test/actions/cross-multiproject/build.sbt @@ -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") diff --git a/sbt/src/sbt-test/actions/cross-multiproject/test b/sbt/src/sbt-test/actions/cross-multiproject/test index 154e71c2c..5458dcaf6 100644 --- a/sbt/src/sbt-test/actions/cross-multiproject/test +++ b/sbt/src/sbt-test/actions/cross-multiproject/test @@ -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