Skip to content

Commit d7090ab

Browse files
authored
Merge pull request #5835 from dotty-staging/sbt-dotty-0.3.0
sbt-dotty: Rework classpath and ScalaInstance handling, fix minimum sbt version check, release 0.3.0
2 parents fdde912 + 6e92463 commit d7090ab

File tree

2 files changed

+228
-160
lines changed

2 files changed

+228
-160
lines changed

project/Build.scala

Lines changed: 23 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import xerial.sbt.pack.PackPlugin
1616
import xerial.sbt.pack.PackPlugin.autoImport._
1717

1818
import dotty.tools.sbtplugin.DottyPlugin.autoImport._
19+
import dotty.tools.sbtplugin.DottyPlugin.makeScalaInstance
1920
import dotty.tools.sbtplugin.DottyIDEPlugin.{ installCodeExtension, prepareCommand, runProcess }
2021
import dotty.tools.sbtplugin.DottyIDEPlugin.autoImport._
2122

@@ -27,20 +28,11 @@ import sbtbuildinfo.BuildInfoPlugin.autoImport._
2728

2829
import scala.util.Properties.isJavaAtLeast
2930

30-
/* In sbt 0.13 the Build trait would expose all vals to the shell, where you
31-
* can use them in "set a := b" like expressions. This re-exposes them.
32-
*/
33-
object ExposedValues extends AutoPlugin {
34-
object autoImport {
35-
val bootstrapFromPublishedJars = Build.bootstrapFromPublishedJars
36-
}
37-
}
38-
3931
object Build {
4032
val scalacVersion = "2.12.8"
4133

4234
val baseVersion = "0.13.0"
43-
val baseSbtDottyVersion = "0.2.7"
35+
val baseSbtDottyVersion = "0.3.1"
4436

4537
// Versions used by the vscode extension to create a new project
4638
// This should be the latest published releases.
@@ -100,8 +92,6 @@ object Build {
10092
// Shorthand for compiling a docs site
10193
val dottydoc = inputKey[Unit]("run dottydoc")
10294

103-
val bootstrapFromPublishedJars = settingKey[Boolean]("If true, bootstrap dotty from published non-bootstrapped dotty")
104-
10595
// Only available in vscode-dotty
10696
val unpublish = taskKey[Unit]("Unpublish a package")
10797

@@ -129,9 +119,6 @@ object Build {
129119

130120
javacOptions in (Compile, compile) ++= Seq("-Xlint:unchecked", "-Xlint:deprecation"),
131121

132-
// Change this to true if you want to bootstrap using a published non-bootstrapped compiler
133-
bootstrapFromPublishedJars := false,
134-
135122
// Override `runCode` from sbt-dotty to use the language-server and
136123
// vscode extension from the source repository of dotty instead of a
137124
// published version.
@@ -220,20 +207,6 @@ object Build {
220207
// Use the same name as the non-bootstrapped projects for the artifacts
221208
moduleName ~= { _.stripSuffix("-bootstrapped") },
222209

223-
// Prevent sbt from setting the Scala bootclasspath, otherwise it will
224-
// contain `scalaInstance.value.libraryJar` which in our case is the
225-
// non-bootstrapped dotty-library that will then take priority over
226-
// the bootstrapped dotty-library on the classpath or sourcepath.
227-
classpathOptions ~= (_.withAutoBoot(false)),
228-
// ... but when running under Java 8, we still need a Scala bootclasspath that contains the JVM bootclasspath,
229-
// otherwise sbt incremental compilation breaks.
230-
scalacOptions ++= {
231-
if (isJavaAtLeast("9"))
232-
Seq()
233-
else
234-
Seq("-bootclasspath", sys.props("sun.boot.class.path"))
235-
},
236-
237210
// Enforce that the only Scala 2 classfiles we unpickle come from scala-library
238211
/*
239212
scalacOptions ++= {
@@ -251,64 +224,31 @@ object Build {
251224
// ...but scala-library is
252225
libraryDependencies += "org.scala-lang" % "scala-library" % scalacVersion,
253226

254-
ivyConfigurations ++= {
255-
if (bootstrapFromPublishedJars.value)
256-
Seq(Configurations.ScalaTool)
257-
else
258-
Seq()
259-
},
260-
libraryDependencies ++= {
261-
if (bootstrapFromPublishedJars.value)
262-
Seq(
263-
dottyOrganization %% "dotty-library" % dottyNonBootstrappedVersion % Configurations.ScalaTool.name,
264-
dottyOrganization %% "dotty-compiler" % dottyNonBootstrappedVersion % Configurations.ScalaTool.name
265-
).map(_.withDottyCompat(scalaVersion.value))
266-
else
267-
Seq()
268-
},
269-
270227
// Compile using the non-bootstrapped and non-published dotty
271228
managedScalaInstance := false,
272229
scalaInstance := {
273-
import sbt.internal.inc.ScalaInstance
274-
import sbt.internal.inc.classpath.ClasspathUtilities
275-
276-
val updateReport = update.value
277-
var libraryJar = packageBin.in(`dotty-library`, Compile).value
278-
var compilerJar = packageBin.in(`dotty-compiler`, Compile).value
279-
280-
if (bootstrapFromPublishedJars.value) {
281-
val jars = updateReport.select(
282-
configuration = configurationFilter(Configurations.ScalaTool.name),
283-
module = moduleFilter(),
284-
artifact = artifactFilter(extension = "jar")
285-
)
286-
libraryJar = jars.find(_.getName.startsWith("dotty-library_2.12")).get
287-
compilerJar = jars.find(_.getName.startsWith("dotty-compiler_2.12")).get
288-
}
289-
290-
// All dotty-doc's and compiler's dependencies except the library.
291-
// (we get the compiler's dependencies because dottydoc depends on the compiler)
292-
val otherDependencies = {
293-
val excluded = Set("dotty-library", "dotty-compiler")
294-
fullClasspath.in(`dotty-doc`, Compile).value
295-
.filterNot(_.get(artifact.key).exists(a => excluded.contains(a.name)))
296-
.map(_.data)
297-
}
298-
299-
val allJars = libraryJar :: compilerJar :: otherDependencies.toList
300-
val classLoader = state.value.classLoaderCache(allJars)
301-
new ScalaInstance(
230+
// TODO: Here we use the output class directories directly, this might impact
231+
// performance when running the compiler (especially on Windows where file
232+
// IO is slow). We should benchmark whether using jars is actually faster
233+
// in practice (especially on our CI), this could be done using
234+
// `exportJars := true`.
235+
val all = fullClasspath.in(`dotty-doc`, Compile).value
236+
def getArtifact(name: String): File =
237+
all.find(_.get(artifact.key).exists(_.name == name))
238+
.getOrElse(throw new MessageOnlyException(s"Artifact for $name not found in $all"))
239+
.data
240+
241+
val scalaLibrary = getArtifact("scala-library")
242+
val dottyLibrary = getArtifact("dotty-library")
243+
val compiler = getArtifact("dotty-compiler")
244+
245+
makeScalaInstance(
246+
state.value,
302247
scalaVersion.value,
303-
classLoader,
304-
ClasspathUtilities.rootLoader, // FIXME: Should be a class loader which only includes the dotty-lib
305-
// See: https://github.com/sbt/zinc/commit/9397b6aaf94ac3cfab386e3abd11c0ef9c2ceaff#diff-ea135f2f26f43e40ff045089da221e1e
306-
// Should not matter, as it addresses an issue with `sbt run` that
307-
// only occur when `(fork in run) := false`
308-
libraryJar,
309-
compilerJar,
310-
allJars.toArray,
311-
None
248+
scalaLibrary,
249+
dottyLibrary,
250+
compiler,
251+
all.map(_.data)
312252
)
313253
}
314254
)
@@ -334,11 +274,6 @@ object Build {
334274

335275
/** Projects -------------------------------------------------------------- */
336276

337-
// Needed because the dotty project aggregates dotty-sbt-bridge but dotty-sbt-bridge
338-
// currently refers to dotty in its scripted task and "aggregate" does not take by-name
339-
// parameters: https://github.com/sbt/sbt/issues/2200
340-
lazy val dottySbtBridgeRef = LocalProject("dotty-sbt-bridge")
341-
342277
// The root project:
343278
// - aggregates other projects so that "compile", "test", etc are run on all projects at once.
344279
// - publishes its own empty artifact "dotty" that depends on "dotty-library" and "dotty-compiler",

0 commit comments

Comments
 (0)