diff --git a/main/src/main/scala/sbt/Cross.scala b/main/src/main/scala/sbt/Cross.scala index c6aafaa9d..6d426b95e 100644 --- a/main/src/main/scala/sbt/Cross.scala +++ b/main/src/main/scala/sbt/Cross.scala @@ -41,6 +41,12 @@ object Cross { case _ => ("", arg) } val home = IO.resolve(x.currentProject.base, new File(homePath)) + // Basic Algorithm. + // 1. First we figure out what the new scala instances should be, create settings for them. + // 2. Find any non-overridden scalaVersion setting in the whole build and force it to delegate + // to the new global settings. + // 3. Append these to the session, so that the session is up-to-date and + // things like set/session clear, etc. work. val (add, exclude) = if (home.exists) { val instance = ScalaInstance(home)(state.classLoaderCache.apply _) @@ -63,10 +69,18 @@ object Cross { ) (settings, excludeKeys(Set(scalaVersion.key, scalaHome.key))) } - val cleared = session.mergeSettings.filterNot(exclude) - val newStructure = Load.reapply(add ++ cleared, structure) - Project.setProject(session, newStructure, command :: state) + // TODO - Track delegates and avoid regenerating. + val delegates: Seq[Setting[_]] = session.mergeSettings collect { + case x if exclude(x) => delegateToGlobal(x.key) + } + val fixedSession = session.appendRaw(add ++ delegates) + BuiltinCommands.reapply(fixedSession, structure, state) } + + // Creates a delegate for a scoped key that pulls the setting from the global scope. + private[this] def delegateToGlobal[T](key: ScopedKey[T]): Setting[_] = + SettingKey[T](key.key) in key.scope := (SettingKey[T](key.key) in GlobalScope).value + @deprecated("No longer used.", "0.13.0") def crossExclude(s: Setting[_]): Boolean = excludeKeys(Set(scalaVersion.key, scalaHome.key))(s) diff --git a/notes/0.13.6.md b/notes/0.13.6.md index a35f51ff1..48fcf27aa 100644 --- a/notes/0.13.6.md +++ b/notes/0.13.6.md @@ -1,4 +1,5 @@ [413]: https://github.com/sbt/sbt/issues/413 + [856]: https://github.com/sbt/sbt/issues/856 [1036]: https://github.com/sbt/sbt/pull/1036 [1059]: https://github.com/sbt/sbt/issues/1059 [1194]: https://github.com/sbt/sbt/issues/1194 @@ -36,6 +37,8 @@ [1486]: https://github.com/sbt/sbt/pull/1486 [1487]: https://github.com/sbt/sbt/pull/1487 [1488]: https://github.com/sbt/sbt/pull/1488 + [1489]: https://github.com/sbt/sbt/pull/1489 + [@dansanduleac]: https://github.com/dansanduleac [@2m]: https://github.com/2m [@pvlugter]: https://github.com/pvlugter @@ -82,6 +85,7 @@ - Fixes sLog usage in tandem with the `set` comamnd [#1486][1486] [@jsuereth][@jsuereth] - Test suites with whitespace will have prettier filenames [#1487][1487] [@jsuereth][@jsuereth] - sbt no longer crashes when run in root directory [#1488][1488] by [@jsuereth][@jsuereth] +- set no longer removes any `++` scala version setting. [#856][856]/[#1489][1489] by [@jsuereth][@jsuereth] ### enablePlugins/disablePlugins diff --git a/sbt/src/sbt-test/actions/cross/test b/sbt/src/sbt-test/actions/cross/test index de92dc24c..ee74f0f8a 100644 --- a/sbt/src/sbt-test/actions/cross/test +++ b/sbt/src/sbt-test/actions/cross/test @@ -1,3 +1,8 @@ > 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 +> set resolvers ++= Nil +> check 2.10.4 2.10.4 2.10.4 +> session clear-all +> check 2.7.7 2.9.1 2.9.0-1 \ No newline at end of file