Skip to content

Commit 7e120a0

Browse files
committed
Avoid creating ScalaInstance when not used
1 parent f2cf44a commit 7e120a0

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

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

Lines changed: 35 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

@@ -142,6 +143,8 @@ object DottyPlugin extends AutoPlugin {
142143
}
143144
)
144145

146+
// https://github.com/sbt/sbt/issues/3110
147+
val Def = sbt.Def
145148
override def projectSettings: Seq[Setting[_]] = {
146149
Seq(
147150
isDotty := scalaVersion.value.startsWith("0."),
@@ -266,41 +269,39 @@ object DottyPlugin extends AutoPlugin {
266269
},
267270
// ... instead, we'll fetch the compiler and its dependencies ourselves.
268271
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-
}
272+
val isD = isDotty.value
273+
val si = scalaInstance.taskValue
274+
val siTaskInitialize = Def.valueStrict { si }
275+
if (isD) dottyScalaInstance
276+
else siTaskInitialize
303277
}.value,
278+
dottyScalaInstance := {
279+
val updateReport =
280+
fetchArtifactsOf(
281+
dependencyResolution.value,
282+
scalaModuleInfo.value,
283+
updateConfiguration.value,
284+
(unresolvedWarningConfiguration in update).value,
285+
streams.value.log,
286+
scalaOrganization.value %% "dotty-doc" % scalaVersion.value)
287+
val scalaLibraryJar = getJar(updateReport,
288+
"org.scala-lang", "scala-library", revision = AllPassFilter)
289+
val dottyLibraryJar = getJar(updateReport,
290+
scalaOrganization.value, s"dotty-library_${scalaBinaryVersion.value}", scalaVersion.value)
291+
val compilerJar = getJar(updateReport,
292+
scalaOrganization.value, s"dotty-compiler_${scalaBinaryVersion.value}", scalaVersion.value)
293+
val allJars =
294+
getJars(updateReport, AllPassFilter, AllPassFilter, AllPassFilter)
295+
296+
makeScalaInstance(
297+
state.value,
298+
scalaVersion.value,
299+
scalaLibraryJar,
300+
dottyLibraryJar,
301+
compilerJar,
302+
allJars
303+
)
304+
},
304305

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

0 commit comments

Comments
 (0)