@@ -154,7 +154,7 @@ object DottyPlugin extends AutoPlugin {
154
154
override val globalSettings : Seq [Def .Setting [_]] = Seq (
155
155
onLoad in Global := onLoad.in(Global ).value.andThen { state =>
156
156
157
- val requiredVersion = " >=1.2.7 "
157
+ val requiredVersion = " >=1.3.6 "
158
158
159
159
val sbtV = sbtVersion.value
160
160
if (! VersionNumber (sbtV).matchesSemVer(SemanticSelector (requiredVersion)))
@@ -210,41 +210,42 @@ object DottyPlugin extends AutoPlugin {
210
210
scalaBinaryVersion.value
211
211
},
212
212
213
- // Ideally, we should have :
213
+ // We want :
214
214
//
215
215
// 1. Nothing but the Java standard library on the _JVM_ bootclasspath
216
216
// (starting with Java 9 we cannot inspect it so we don't have a choice)
217
217
//
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.
221
220
// NOTE: All of those should have the *same version* (equal to scalaVersion
222
221
// 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)
223
224
//
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 ).
228
229
// NOTE: the versions of {scala,dotty}-library used here do not necessarily
229
230
// 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.
231
235
//
232
236
// 4. every other dependency of the user project on the _compiler_
233
237
// classpath.
234
238
//
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
240
240
// scala-library used on the JVM classpath, even if the current project
241
241
// transitively depends on a newer scala-library (this works because Scala
242
242
// 2 guarantees forward- and backward- binary compatibility, but we don't
243
243
// necessarily want to keep doing that in Scala 3).
244
244
// 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.
248
249
249
250
// sbt crazy scoping rules mean that when we override `classpathOptions`
250
251
// below we also override `classpathOptions in console` which is normally
@@ -404,7 +405,7 @@ object DottyPlugin extends AutoPlugin {
404
405
405
406
/** Create a scalaInstance task that uses Dotty based on `moduleName`. */
406
407
def dottyScalaInstanceTask (moduleName : String ): Initialize [Task [ScalaInstance ]] = Def .task {
407
- val ivyConfig0 = mkIvyConfiguration.value
408
+ val ivyConfig0 = Classpaths . mkIvyConfiguration.value
408
409
// When compiling non-bootstrapped projects in the build of Dotty itself,
409
410
// dependency resolution might pick a local project which is not what we
410
411
// want. We avoid this by dropping the inter-project resolver.
@@ -436,37 +437,22 @@ object DottyPlugin extends AutoPlugin {
436
437
)
437
438
}
438
439
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
458
441
def makeScalaInstance (
459
442
state : State , dottyVersion : String , scalaLibrary : File , dottyLibrary : File , compiler : File , all : Seq [File ]
460
443
): 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
+ )
463
451
new ScalaInstance (
464
452
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),
470
456
compiler,
471
457
all.toArray,
472
458
None )
0 commit comments