Skip to content

Commit 2faf77b

Browse files
committed
Create legacy Scala 2/3 stdlib TASTy
This adds a temporary workaround (`stdlib-bootsrapped-legacy`) to be able to generate documentation for the full standard library. In the future, the documentation will be generated from `stdlib-bootsrapped` and `scala3-library-bootsrapped` combined. Fixes #17964
1 parent a68568c commit 2faf77b

File tree

2 files changed

+72
-10
lines changed

2 files changed

+72
-10
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ val `scala3-language-server` = Build.`scala3-language-server`
1414
val `scala3-bench` = Build.`scala3-bench`
1515
val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped`
1616
val `scala3-bench-micro` = Build.`scala3-bench-micro`
17+
val `stdlib-bootstrapped-legacy` = Build.`stdlib-bootstrapped-legacy`
1718
val `stdlib-bootstrapped` = Build.`stdlib-bootstrapped`
1819
val `stdlib-bootstrapped-tasty-tests` = Build.`stdlib-bootstrapped-tasty-tests`
1920
val `tasty-core` = Build.`tasty-core`

project/Build.scala

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,59 @@ object Build {
924924
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value
925925
)
926926

927+
/** Version of stdlib-bootstrapped that compiles both Scala 2 and Scala 3 libraries
928+
* This is only used as a temporary solution until the docs can be generated using
929+
* stdlib-bootstrapped and scala3-library-bootstrapped.
930+
*/
931+
lazy val `stdlib-bootstrapped-legacy` = project.in(file("stdlib-bootstrapped-legacy")).
932+
withCommonSettings(Bootstrapped).
933+
dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
934+
settings(commonBootstrappedSettings).
935+
settings(stdlibBootstrappedCommonSettings).
936+
settings(
937+
scalacOptions -= "-Yscala2-stdlib",
938+
Compile/scalacOptions ++= {
939+
Seq(
940+
"-sourcepath",
941+
Seq(
942+
(Compile/sourceManaged).value / "scala-library-src",
943+
(Compile/sourceManaged).value / "dotty-library-src",
944+
).mkString(File.pathSeparator),
945+
)
946+
},
947+
(Compile / sourceGenerators) += Def.task {
948+
val s = streams.value
949+
val cacheDir = s.cacheDirectory
950+
val trgDir = (Compile / sourceManaged).value / "dotty-library-src"
951+
952+
// NOTE `sourceDirectory` is used for actual copying,
953+
// but `sources` are used as cache keys
954+
val dottyLibSourceDirs = (`scala3-library-bootstrapped`/Compile/unmanagedSourceDirectories).value
955+
def dottyLibSources = dottyLibSourceDirs.foldLeft(PathFinder.empty) { (pf, dir) =>
956+
if (!dir.exists) pf else pf +++ (dir ** "*.scala") +++ (dir ** "*.java")
957+
}
958+
959+
val cachedFun = FileFunction.cached(
960+
cacheDir / s"copyDottyLibrarySrc",
961+
FilesInfo.lastModified,
962+
FilesInfo.exists,
963+
) { _ =>
964+
if (trgDir.exists) IO.delete(trgDir)
965+
dottyLibSourceDirs.foreach { dir =>
966+
if (dir.exists) {
967+
s.log.info(s"Copying scala3-library sources from $dir to $trgDir...")
968+
IO.copyDirectory(dir, trgDir)
969+
}
970+
}
971+
972+
((trgDir ** "*.scala") +++ (trgDir ** "*.java")).get.toSet
973+
}
974+
975+
cachedFun(dottyLibSources.get.toSet).toSeq
976+
}.taskValue,
977+
mimaCheckDirection := "none",
978+
)
979+
927980
/** Scala 2 library compiled by dotty using the latest published sources of the library.
928981
*
929982
* This version of the library is not (yet) TASTy/binary compatible with the Scala 2 compiled library.
@@ -932,7 +985,15 @@ object Build {
932985
withCommonSettings(Bootstrapped).
933986
dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
934987
settings(commonBootstrappedSettings).
988+
settings(stdlibBootstrappedCommonSettings).
935989
settings(
990+
Compile / scalacOptions ++= {
991+
Seq("-sourcepath", ((Compile/sourceManaged).value / "scala-library-src").toString)
992+
},
993+
)
994+
995+
lazy val stdlibBootstrappedCommonSettings =
996+
Seq(
936997
moduleName := "scala-library",
937998
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
938999
Compile / scalacOptions ++= {
@@ -1952,7 +2013,7 @@ object ScaladocConfigs {
19522013

19532014
def defaultSourceLinks(version: String = dottyNonBootstrappedVersion, refVersion: String = dottyVersion) = Def.task {
19542015
def stdLibVersion = stdlibVersion(NonBootstrapped)
1955-
def srcManaged(v: String, s: String) = s"out/bootstrap/stdlib-bootstrapped/scala-$v/src_managed/main/$s-library-src"
2016+
def srcManaged(v: String, s: String) = s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$v/src_managed/main/$s-library-src"
19562017
SourceLinks(
19572018
List(
19582019
scalaSrcLink(stdLibVersion, srcManaged(version, "scala") + "="),
@@ -2038,21 +2099,21 @@ object ScaladocConfigs {
20382099

20392100
lazy val Scala3 = Def.task {
20402101
val dottyJars: Seq[java.io.File] = Seq(
2041-
(`stdlib-bootstrapped`/Compile/products).value,
2102+
(`stdlib-bootstrapped-legacy`/Compile/products).value,
20422103
(`scala3-interfaces`/Compile/products).value,
20432104
(`tasty-core-bootstrapped`/Compile/products).value,
20442105
).flatten
20452106

20462107
val roots = dottyJars.map(_.getAbsolutePath)
20472108

20482109
val managedSources =
2049-
(`stdlib-bootstrapped`/Compile/sourceManaged).value / "scala-library-src"
2110+
(`stdlib-bootstrapped-legacy`/Compile/sourceManaged).value / "scala-library-src"
20502111
val projectRoot = (ThisBuild/baseDirectory).value.toPath
20512112
val stdLibRoot = projectRoot.relativize(managedSources.toPath.normalize())
20522113
val docRootFile = stdLibRoot.resolve("rootdoc.txt")
20532114

20542115
val dottyManagesSources =
2055-
(`stdlib-bootstrapped`/Compile/sourceManaged).value / "dotty-library-src"
2116+
(`stdlib-bootstrapped-legacy`/Compile/sourceManaged).value / "dotty-library-src"
20562117

20572118
val tastyCoreSources = projectRoot.relativize((`tasty-core-bootstrapped`/Compile/scalaSource).value.toPath().normalize())
20582119

@@ -2085,19 +2146,19 @@ object ScaladocConfigs {
20852146
.add(ProjectVersion(version))
20862147
.add(SnippetCompiler(
20872148
List(
2088-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src/scala/quoted=compile",
2089-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src/scala/compiletime=compile"
2149+
s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src/scala/quoted=compile",
2150+
s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src/scala/compiletime=compile"
20902151
)
20912152
))
20922153
.add(CommentSyntax(List(
2093-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src=markdown",
2094-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/scala-library-src=wiki",
2154+
s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src=markdown",
2155+
s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/scala-library-src=wiki",
20952156
"wiki"
20962157
)))
2097-
.add(DocRootContent(s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/scala-library-src/rootdoc.txt"))
2158+
.add(DocRootContent(s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/scala-library-src/rootdoc.txt"))
20982159
.withTargets(
20992160
Seq(
2100-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/classes",
2161+
s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$version-bin-SNAPSHOT-nonbootstrapped/classes",
21012162
s"tmp/interfaces/target/classes",
21022163
s"out/bootstrap/tasty-core-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/classes"
21032164
)

0 commit comments

Comments
 (0)