@@ -154,7 +154,7 @@ object DottyPlugin extends AutoPlugin {
154154 override val globalSettings : Seq [Def .Setting [_]] = Seq (
155155 onLoad in Global := onLoad.in(Global ).value.andThen { state =>
156156
157- val requiredVersion = " >=1.2.7 "
157+ val requiredVersion = " >=1.3.6 "
158158
159159 val sbtV = sbtVersion.value
160160 if (! VersionNumber (sbtV).matchesSemVer(SemanticSelector (requiredVersion)))
@@ -210,41 +210,42 @@ object DottyPlugin extends AutoPlugin {
210210 scalaBinaryVersion.value
211211 },
212212
213- // Ideally, we should have :
213+ // We want :
214214 //
215215 // 1. Nothing but the Java standard library on the _JVM_ bootclasspath
216216 // (starting with Java 9 we cannot inspect it so we don't have a choice)
217217 //
218- // 2. scala-library, dotty-library, dotty-compiler, dotty-doc on the _JVM_
219- // classpath, because we need all of those to actually run the compiler
220- // and the doc tool.
218+ // 2. scala-library, dotty-library, dotty-compiler and its dependencies on the _JVM_
219+ // classpath, because we need all of those to actually run the compiler.
221220 // NOTE: All of those should have the *same version* (equal to scalaVersion
222221 // for everything but scala-library).
222+ // (Complication: because dottydoc is a separate artifact with its own dependencies,
223+ // running it requires putting extra dependencies on the _JVM_ classpath)
223224 //
224- // 3. scala-library, dotty-library on the _compiler_ bootclasspath because
225- // user code should always have access to the symbols from these jars but
226- // should not be able to shadow them (the compiler bootclasspath has
227- // higher priority than the compiler classpath ).
225+ // 3. scala-library, dotty-library on the _compiler_ bootclasspath or
226+ // classpath (the only difference between them is that the compiler
227+ // bootclasspath has higher priority, but that should never
228+ // make a difference in a sane environment ).
228229 // NOTE: the versions of {scala,dotty}-library used here do not necessarily
229230 // match the one used in 2. because a dependency of the current project might
230- // require more recent versions, this is OK.
231+ // require a more recent standard library version, this is OK
232+ // TODO: ... but if macros are used we might be forced to use the same
233+ // versions in the JVM and compiler classpaths to avoid problems, this
234+ // needs to be investigated.
231235 //
232236 // 4. every other dependency of the user project on the _compiler_
233237 // classpath.
234238 //
235- // Unfortunately, zinc assumes that the compiler bootclasspath is only
236- // made of one jar (scala-library), so to make this work we'll need to
237- // either change sbt's bootclasspath handling or wait until the
238- // dotty-library jar and scala-library jars are merged into one jar.
239- // Furthermore, zinc will put on the compiler bootclasspath the
239+ // By default, zinc will put on the compiler bootclasspath the
240240 // scala-library used on the JVM classpath, even if the current project
241241 // transitively depends on a newer scala-library (this works because Scala
242242 // 2 guarantees forward- and backward- binary compatibility, but we don't
243243 // necessarily want to keep doing that in Scala 3).
244244 // So for the moment, let's just put nothing at all on the compiler
245- // bootclasspath, and instead have scala-library and dotty-library on the
246- // compiler classpath. This means that user code could shadow symbols
247- // from these jars but we can live with that for now.
245+ // bootclasspath, and instead let sbt dependency management choose which
246+ // scala-library and dotty-library to put on the compiler classpath.
247+ // Maybe eventually we should just remove the compiler bootclasspath since
248+ // it's a source of complication with only dubious benefits.
248249
249250 // sbt crazy scoping rules mean that when we override `classpathOptions`
250251 // below we also override `classpathOptions in console` which is normally
@@ -404,7 +405,7 @@ object DottyPlugin extends AutoPlugin {
404405
405406 /** Create a scalaInstance task that uses Dotty based on `moduleName`. */
406407 def dottyScalaInstanceTask (moduleName : String ): Initialize [Task [ScalaInstance ]] = Def .task {
407- val ivyConfig0 = mkIvyConfiguration.value
408+ val ivyConfig0 = Classpaths . mkIvyConfiguration.value
408409 // When compiling non-bootstrapped projects in the build of Dotty itself,
409410 // dependency resolution might pick a local project which is not what we
410411 // want. We avoid this by dropping the inter-project resolver.
@@ -436,37 +437,22 @@ object DottyPlugin extends AutoPlugin {
436437 )
437438 }
438439
439- // Copy-pasted from sbt until we upgrade to a version of sbt
440- // with https://github.com/sbt/sbt/pull/5271 in.
441- def mkIvyConfiguration : Initialize [Task [InlineIvyConfiguration ]] =
442- Def .task {
443- val (rs, other) = (fullResolvers.value.toVector, otherResolvers.value.toVector)
444- val s = streams.value
445- Classpaths .warnResolversConflict(rs ++: other, s.log)
446- InlineIvyConfiguration ()
447- .withPaths(ivyPaths.value)
448- .withResolvers(rs)
449- .withOtherResolvers(other)
450- .withModuleConfigurations(moduleConfigurations.value.toVector)
451- .withLock(Defaults .lock(appConfiguration.value))
452- .withChecksums((checksums in update).value.toVector)
453- .withResolutionCacheDir(crossTarget.value / " resolution-cache" )
454- .withUpdateOptions(updateOptions.value)
455- .withLog(s.log)
456- }
457-
440+ // Adapted from private mkScalaInstance in sbt
458441 def makeScalaInstance (
459442 state : State , dottyVersion : String , scalaLibrary : File , dottyLibrary : File , compiler : File , all : Seq [File ]
460443 ): ScalaInstance = {
461- val loader = state.classLoaderCache(all.toList)
462- val loaderLibraryOnly = state.classLoaderCache(List (dottyLibrary, scalaLibrary))
444+ val libraryLoader = state.classLoaderCache(List (dottyLibrary, scalaLibrary))
445+ class DottyLoader
446+ extends URLClassLoader (all.map(_.toURI.toURL).toArray, libraryLoader)
447+ val fullLoader = state.classLoaderCache.cachedCustomClassloader(
448+ all.toList,
449+ () => new DottyLoader
450+ )
463451 new ScalaInstance (
464452 dottyVersion,
465- loader,
466- loaderLibraryOnly,
467- scalaLibrary, // Should be a Seq also containing dottyLibrary but zinc
468- // doesn't support this, see comment above our redefinition
469- // of `classpathOption`
453+ fullLoader,
454+ libraryLoader,
455+ Array (dottyLibrary, scalaLibrary),
470456 compiler,
471457 all.toArray,
472458 None )
0 commit comments