Skip to content

Commit

Permalink
Make scaladoc a bootstrapped-only project
Browse files Browse the repository at this point in the history
Previously, we had both a non-bootstrapped and bootstrapped version of
that project as well as its dependencies (scala3-library-js,
scala3-tasty-inspector, scaladoc-testcases, scaladoc-js), the main
reason for this is that it allowed the non-boostrapped scaladoc to be
part of the `scalaInstance` of all bootstrapped projects, allowing us to
run `scala3-library-bootstrapped/doc` for example. But this also meant
that simply trying to run the compiler would compiler scaladoc as well
as its dependencies even if no documentation needed to be generated, and
since `scaladoc-js` runs the Scala.js optimizer this could be quite slow.

This commit fixes that by using a separate `scalaInstance` for the `doc`
task, which means the regular `scalaInstance` no longer needs to depend
on scaladoc and also allows us to remove all the non-bootstrapped
projects related to scaladoc (thus simplifying the build a lot) since we
can safely use the bootstrapped version in `doc / scalaInstance` without
running into a loop.
  • Loading branch information
smarter committed May 5, 2021
1 parent 83acd4b commit 96c3957
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 235 deletions.
5 changes: 0 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ val `scala3-interfaces` = Build.`scala3-interfaces`
val `scala3-compiler` = Build.`scala3-compiler`
val `scala3-compiler-bootstrapped` = Build.`scala3-compiler-bootstrapped`
val `scala3-library` = Build.`scala3-library`
val `scala3-library-js` = Build.`scala3-library-js`
val `scala3-library-bootstrapped` = Build.`scala3-library-bootstrapped`
val `scala3-library-bootstrappedJS` = Build.`scala3-library-bootstrappedJS`
val `scala3-sbt-bridge` = Build.`scala3-sbt-bridge`
val `scala3-sbt-bridge-tests` = Build.`scala3-sbt-bridge-tests`
val `scala3-staging` = Build.`scala3-staging`
val `scala3-tasty-inspector` = Build.`scala3-tasty-inspector`
val `scala3-tasty-inspector-nonbootstrapped` = Build.`scala3-tasty-inspector-nonbootstrapped`
val `scala3-language-server` = Build.`scala3-language-server`
val `scala3-bench` = Build.`scala3-bench`
val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped`
Expand All @@ -21,11 +19,8 @@ val `tasty-core` = Build.`tasty-core`
val `tasty-core-bootstrapped` = Build.`tasty-core-bootstrapped`
val `tasty-core-scala2` = Build.`tasty-core-scala2`
val scaladoc = Build.scaladoc
val `scaladoc-nonBootstrapped` = Build.`scaladoc-nonBootstrapped`
val `scaladoc-testcases` = Build.`scaladoc-testcases`
val `scaladoc-testcases-nonBootstrapped` = Build.`scaladoc-testcases-nonBootstrapped`
val `scaladoc-js` = Build.`scaladoc-js`
val `scaladoc-js-nonBootstrapped` = Build.`scaladoc-js-nonBootstrapped`
val `scala3-bench-run` = Build.`scala3-bench-run`
val dist = Build.dist
val `community-build` = Build.`community-build`
Expand Down
31 changes: 26 additions & 5 deletions project/Bootstrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,51 @@ import sbt.internal.inc.ScalaInstance

// This class needs to be in package sbt to access the ClassLoaderCache
object Bootstrap {
/** A ScalaInstance (without scaladoc). */
def makeScalaInstance(
state: State,
version: String,
libraryJars: Array[File],
compilerJars: Array[File],
docJars: Array[File],
topLoader: ClassLoader
): ScalaInstance = {
// `extendedClassLoaderCache` is package private in package sbt
val cache = state.extendedClassLoaderCache

val libraryLoader = cache(libraryJars.toList, topLoader)
val compilerLoader = cache(compilerJars.toList, libraryLoader)
val fullLoader = cache(docJars.toList, compilerLoader)

new ScalaInstance(
version = version,
loader = fullLoader,
loader = compilerLoader,
loaderCompilerOnly = compilerLoader,
loaderLibraryOnly = libraryLoader,
libraryJars = libraryJars,
compilerJars = compilerJars,
allJars = libraryJars ++ compilerJars ++ docJars,
allJars = libraryJars ++ compilerJars,
explicitActual = Some(version)
)
}
}

/** A ScalaInstance identical to `base` but with additional jars for scaladoc. */
def makeDocScalaInstance(
state: State,
base: ScalaInstance,
docJars: Array[File]
): ScalaInstance = {
val cache = state.extendedClassLoaderCache

val fullLoader = cache(docJars.toList, base.loaderCompilerOnly)

new ScalaInstance(
version = base.version,
loader = fullLoader,
loaderCompilerOnly = base.loaderCompilerOnly,
loaderLibraryOnly = base.loaderLibraryOnly,
libraryJars = base.libraryJars,
compilerJars = base.compilerJars,
allJars = base.allJars ++ docJars,
explicitActual = base.explicitActual
)
}
}
Loading

0 comments on commit 96c3957

Please sign in to comment.