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/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