Skip to content

Commit 2b4cf3a

Browse files
committed
Avoid creating ScalaInstance when not used
1 parent f2cf44a commit 2b4cf3a

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import java.util.Optional
1313
import scala.util.Properties.isJavaAtLeast
1414

1515
object DottyPlugin extends AutoPlugin {
16+
val dottyScalaInstance = taskKey[ScalaInstance]("ScalaInstance for Dotty")
1617
object autoImport {
1718
val isDotty = settingKey[Boolean]("Is this project compiled with Dotty?")
1819

@@ -266,41 +267,38 @@ object DottyPlugin extends AutoPlugin {
266267
},
267268
// ... instead, we'll fetch the compiler and its dependencies ourselves.
268269
scalaInstance := Def.taskDyn {
269-
if (isDotty.value) Def.task {
270-
val updateReport =
271-
fetchArtifactsOf(
272-
dependencyResolution.value,
273-
scalaModuleInfo.value,
274-
updateConfiguration.value,
275-
(unresolvedWarningConfiguration in update).value,
276-
streams.value.log,
277-
scalaOrganization.value %% "dotty-doc" % scalaVersion.value)
278-
val scalaLibraryJar = getJar(updateReport,
279-
"org.scala-lang", "scala-library", revision = AllPassFilter)
280-
val dottyLibraryJar = getJar(updateReport,
281-
scalaOrganization.value, s"dotty-library_${scalaBinaryVersion.value}", scalaVersion.value)
282-
val compilerJar = getJar(updateReport,
283-
scalaOrganization.value, s"dotty-compiler_${scalaBinaryVersion.value}", scalaVersion.value)
284-
val allJars =
285-
getJars(updateReport, AllPassFilter, AllPassFilter, AllPassFilter)
286-
287-
makeScalaInstance(
288-
state.value,
289-
scalaVersion.value,
290-
scalaLibraryJar,
291-
dottyLibraryJar,
292-
compilerJar,
293-
allJars
294-
)
295-
}
296-
else Def.task {
297-
// This should really be `old` with `val old = scalaInstance.value`
298-
// above, except that this would force the original definition of the
299-
// `scalaInstance` task to be computed when `isDotty` is true, which
300-
// would fail because `managedScalaInstance` is false.
301-
Defaults.scalaInstanceTask.value
302-
}
270+
val isD = isDotty.value
271+
val si = scalaInstance.value
272+
if (isD) dottyScalaInstance
273+
else Def.task { si }
303274
}.value,
275+
dottyScalaInstance := {
276+
val updateReport =
277+
fetchArtifactsOf(
278+
dependencyResolution.value,
279+
scalaModuleInfo.value,
280+
updateConfiguration.value,
281+
(unresolvedWarningConfiguration in update).value,
282+
streams.value.log,
283+
scalaOrganization.value %% "dotty-doc" % scalaVersion.value)
284+
val scalaLibraryJar = getJar(updateReport,
285+
"org.scala-lang", "scala-library", revision = AllPassFilter)
286+
val dottyLibraryJar = getJar(updateReport,
287+
scalaOrganization.value, s"dotty-library_${scalaBinaryVersion.value}", scalaVersion.value)
288+
val compilerJar = getJar(updateReport,
289+
scalaOrganization.value, s"dotty-compiler_${scalaBinaryVersion.value}", scalaVersion.value)
290+
val allJars =
291+
getJars(updateReport, AllPassFilter, AllPassFilter, AllPassFilter)
292+
293+
makeScalaInstance(
294+
state.value,
295+
scalaVersion.value,
296+
scalaLibraryJar,
297+
dottyLibraryJar,
298+
compilerJar,
299+
allJars
300+
)
301+
},
304302

305303
// Because managedScalaInstance is false, sbt won't add the standard library to our dependencies for us
306304
libraryDependencies ++= {

0 commit comments

Comments
 (0)