1
1
package dotty .tools .sbtplugin
2
2
3
3
import sbt ._
4
+ import sbt .Def .Initialize
4
5
import sbt .Keys ._
5
6
import sbt .librarymanagement .{
6
7
ivy , DependencyResolution , ScalaModuleInfo , SemanticSelector , UpdateConfiguration , UnresolvedWarningConfiguration ,
@@ -172,12 +173,13 @@ object DottyPlugin extends AutoPlugin {
172
173
scalaCompilerBridgeBinaryJar := Def .settingDyn {
173
174
if (isDotty.value) Def .task {
174
175
val dottyBridgeArtifacts = fetchArtifactsOf(
176
+ scalaOrganization.value % " dotty-sbt-bridge" % scalaVersion.value,
175
177
dependencyResolution.value,
176
178
scalaModuleInfo.value,
177
179
updateConfiguration.value,
178
180
(unresolvedWarningConfiguration in update).value,
179
181
streams.value.log,
180
- scalaOrganization.value % " dotty-sbt-bridge " % scalaVersion.value ).allFiles
182
+ ).allFiles
181
183
val jars = dottyBridgeArtifacts.filter(art => art.getName.startsWith(" dotty-sbt-bridge" ) && art.getName.endsWith(" .jar" )).toArray
182
184
if (jars.size == 0 )
183
185
throw new MessageOnlyException (" No jar found for dotty-sbt-bridge" )
@@ -289,39 +291,20 @@ object DottyPlugin extends AutoPlugin {
289
291
},
290
292
// ... instead, we'll fetch the compiler and its dependencies ourselves.
291
293
scalaInstance := Def .taskDyn {
292
- if (isDotty.value) Def .task {
293
- val updateReport =
294
- fetchArtifactsOf(
295
- dependencyResolution.value,
296
- scalaModuleInfo.value,
297
- updateConfiguration.value,
298
- (unresolvedWarningConfiguration in update).value,
299
- streams.value.log,
300
- scalaOrganization.value %% " dotty-doc" % scalaVersion.value)
301
- val scalaLibraryJar = getJar(updateReport,
302
- " org.scala-lang" , " scala-library" , revision = AllPassFilter )
303
- val dottyLibraryJar = getJar(updateReport,
304
- scalaOrganization.value, s " dotty-library_ ${scalaBinaryVersion.value}" , scalaVersion.value)
305
- val compilerJar = getJar(updateReport,
306
- scalaOrganization.value, s " dotty-compiler_ ${scalaBinaryVersion.value}" , scalaVersion.value)
307
- val allJars =
308
- getJars(updateReport, AllPassFilter , AllPassFilter , AllPassFilter )
309
-
310
- makeScalaInstance(
311
- state.value,
312
- scalaVersion.value,
313
- scalaLibraryJar,
314
- dottyLibraryJar,
315
- compilerJar,
316
- allJars
317
- )
318
- }
294
+ if (isDotty.value)
295
+ dottyScalaInstanceTask(" dotty-compiler" )
319
296
else
320
- // This dereferences the Initialize graph, but keeps the Task unevaluated,
321
- // so its effect gets fired only when isDotty.value evaluates to false. yay monad.
322
297
Def .valueStrict { scalaInstance.taskValue }
323
298
}.value,
324
299
300
+ // We need more stuff on the classpath to run the `doc` task.
301
+ scalaInstance in doc := Def .taskDyn {
302
+ if (isDotty.value)
303
+ dottyScalaInstanceTask(" dotty-doc" )
304
+ else
305
+ Def .valueStrict { (scalaInstance in doc).taskValue }
306
+ }.value,
307
+
325
308
// Because managedScalaInstance is false, sbt won't add the standard library to our dependencies for us
326
309
libraryDependencies ++= {
327
310
if (isDotty.value && autoScalaLibrary.value)
@@ -355,6 +338,7 @@ object DottyPlugin extends AutoPlugin {
355
338
old
356
339
}
357
340
}.value,
341
+
358
342
scalacOptions ++= {
359
343
if (isDotty.value) {
360
344
val projectName =
@@ -369,17 +353,17 @@ object DottyPlugin extends AutoPlugin {
369
353
}
370
354
else
371
355
Seq ()
372
- }
356
+ },
373
357
))
374
358
375
359
/** Fetch artifacts for moduleID */
376
360
def fetchArtifactsOf (
361
+ moduleID : ModuleID ,
377
362
dependencyRes : DependencyResolution ,
378
363
scalaInfo : Option [ScalaModuleInfo ],
379
364
updateConfig : UpdateConfiguration ,
380
365
warningConfig : UnresolvedWarningConfiguration ,
381
- log : Logger ,
382
- moduleID : ModuleID ): UpdateReport = {
366
+ log : Logger ): UpdateReport = {
383
367
val descriptor = dependencyRes.wrapDependencyInModule(moduleID, scalaInfo)
384
368
385
369
dependencyRes.update(descriptor, updateConfig, warningConfig, log) match {
@@ -401,13 +385,43 @@ object DottyPlugin extends AutoPlugin {
401
385
}
402
386
403
387
/** Get the single jar in updateReport that match the given filter.
404
- * If zero or more than one jar match, an exception will be thrown. */
388
+ * If zero or more than one jar match, an exception will be thrown.
389
+ */
405
390
def getJar (updateReport : UpdateReport , organization : NameFilter , name : NameFilter , revision : NameFilter ): File = {
406
391
val jars = getJars(updateReport, organization, name, revision)
407
392
assert(jars.size == 1 , s " There should only be one $name jar but found: $jars" )
408
393
jars.head
409
394
}
410
395
396
+ /** Create a scalaInstance task that uses Dotty based on `moduleName`. */
397
+ def dottyScalaInstanceTask (moduleName : String ): Initialize [Task [ScalaInstance ]] = Def .task {
398
+ val updateReport =
399
+ fetchArtifactsOf(
400
+ scalaOrganization.value %% moduleName % scalaVersion.value,
401
+ dependencyResolution.value,
402
+ scalaModuleInfo.value,
403
+ updateConfiguration.value,
404
+ (unresolvedWarningConfiguration in update).value,
405
+ streams.value.log)
406
+ val scalaLibraryJar = getJar(updateReport,
407
+ " org.scala-lang" , " scala-library" , revision = AllPassFilter )
408
+ val dottyLibraryJar = getJar(updateReport,
409
+ scalaOrganization.value, s " dotty-library_ ${scalaBinaryVersion.value}" , scalaVersion.value)
410
+ val compilerJar = getJar(updateReport,
411
+ scalaOrganization.value, s " dotty-compiler_ ${scalaBinaryVersion.value}" , scalaVersion.value)
412
+ val allJars =
413
+ getJars(updateReport, AllPassFilter , AllPassFilter , AllPassFilter )
414
+
415
+ makeScalaInstance(
416
+ state.value,
417
+ scalaVersion.value,
418
+ scalaLibraryJar,
419
+ dottyLibraryJar,
420
+ compilerJar,
421
+ allJars
422
+ )
423
+ }
424
+
411
425
def makeScalaInstance (
412
426
state : State , dottyVersion : String , scalaLibrary : File , dottyLibrary : File , compiler : File , all : Seq [File ]
413
427
): ScalaInstance = {
0 commit comments