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" )
@@ -288,39 +290,7 @@ object DottyPlugin extends AutoPlugin {
288
290
old
289
291
},
290
292
// ... instead, we'll fetch the compiler and its dependencies ourselves.
291
- 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
- }
319
- 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
- Def .valueStrict { scalaInstance.taskValue }
323
- }.value,
293
+ scalaInstance := scalaInstanceTask(" dotty-compiler" ).value,
324
294
325
295
// Because managedScalaInstance is false, sbt won't add the standard library to our dependencies for us
326
296
libraryDependencies ++= {
@@ -344,6 +314,11 @@ object DottyPlugin extends AutoPlugin {
344
314
}
345
315
346
316
private val docSettings = inTask(doc)(Seq (
317
+ // Like scalaInstance in `projectSettings`, but with "dotty-compiler"
318
+ // replaced by "dotty-doc" because we need more stuff on the classpath to
319
+ // run the `doc` task.
320
+ scalaInstance := scalaInstanceTask(" dotty-doc" ).value,
321
+
347
322
sources := Def .taskDyn {
348
323
val old = sources.value
349
324
@@ -355,6 +330,7 @@ object DottyPlugin extends AutoPlugin {
355
330
old
356
331
}
357
332
}.value,
333
+
358
334
scalacOptions ++= {
359
335
if (isDotty.value) {
360
336
val projectName =
@@ -369,17 +345,17 @@ object DottyPlugin extends AutoPlugin {
369
345
}
370
346
else
371
347
Seq ()
372
- }
348
+ },
373
349
))
374
350
375
351
/** Fetch artifacts for moduleID */
376
352
def fetchArtifactsOf (
353
+ moduleID : ModuleID ,
377
354
dependencyRes : DependencyResolution ,
378
355
scalaInfo : Option [ScalaModuleInfo ],
379
356
updateConfig : UpdateConfiguration ,
380
357
warningConfig : UnresolvedWarningConfiguration ,
381
- log : Logger ,
382
- moduleID : ModuleID ): UpdateReport = {
358
+ log : Logger ): UpdateReport = {
383
359
val descriptor = dependencyRes.wrapDependencyInModule(moduleID, scalaInfo)
384
360
385
361
dependencyRes.update(descriptor, updateConfig, warningConfig, log) match {
@@ -401,13 +377,53 @@ object DottyPlugin extends AutoPlugin {
401
377
}
402
378
403
379
/** 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. */
380
+ * If zero or more than one jar match, an exception will be thrown.
381
+ */
405
382
def getJar (updateReport : UpdateReport , organization : NameFilter , name : NameFilter , revision : NameFilter ): File = {
406
383
val jars = getJars(updateReport, organization, name, revision)
407
384
assert(jars.size == 1 , s " There should only be one $name jar but found: $jars" )
408
385
jars.head
409
386
}
410
387
388
+ /** If `isDotty` is true, create a scalaInstance task that uses Dotty based on
389
+ * `moduleName`, otherwise return the default scalaInstance.
390
+ */
391
+ def scalaInstanceTask (moduleName : String ): Initialize [Task [ScalaInstance ]] = Def .taskDyn {
392
+ if (isDotty.value)
393
+ dottyScalaInstanceTask(scalaOrganization.value %% moduleName % scalaVersion.value)
394
+ else
395
+ Def .valueStrict { scalaInstance.taskValue }
396
+ }
397
+
398
+ /** Create a scalaInstance task that uses Dotty based on `moduleID`. */
399
+ def dottyScalaInstanceTask (moduleID : ModuleID ): Initialize [Task [ScalaInstance ]] = Def .task {
400
+ val updateReport =
401
+ fetchArtifactsOf(
402
+ moduleID,
403
+ dependencyResolution.value,
404
+ scalaModuleInfo.value,
405
+ updateConfiguration.value,
406
+ (unresolvedWarningConfiguration in update).value,
407
+ streams.value.log)
408
+ val scalaLibraryJar = getJar(updateReport,
409
+ " org.scala-lang" , " scala-library" , revision = AllPassFilter )
410
+ val dottyLibraryJar = getJar(updateReport,
411
+ scalaOrganization.value, s " dotty-library_ ${scalaBinaryVersion.value}" , scalaVersion.value)
412
+ val compilerJar = getJar(updateReport,
413
+ scalaOrganization.value, s " dotty-compiler_ ${scalaBinaryVersion.value}" , scalaVersion.value)
414
+ val allJars =
415
+ getJars(updateReport, AllPassFilter , AllPassFilter , AllPassFilter )
416
+
417
+ makeScalaInstance(
418
+ state.value,
419
+ scalaVersion.value,
420
+ scalaLibraryJar,
421
+ dottyLibraryJar,
422
+ compilerJar,
423
+ allJars
424
+ )
425
+ }
426
+
411
427
def makeScalaInstance (
412
428
state : State , dottyVersion : String , scalaLibrary : File , dottyLibrary : File , compiler : File , all : Seq [File ]
413
429
): ScalaInstance = {
0 commit comments