Skip to content

Commit 1803802

Browse files
Create legacy Scala 2/3 stdlib TASTy (#18025)
This adds a temporary workaround (`stdlib-bootstrapped-legacy`) to be able to generate documentation for the full standard library. In the future, the documentation will be generated from `stdlib-bootstrapped` and `scala3-library-bootstrapped` combined. Fixes #17964 Fixes #17621 Partially reverts #17526
2 parents 76505f8 + 2faf77b commit 1803802

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
@@ -926,6 +926,59 @@ object Build {
926926
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value
927927
)
928928

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

19592020
def defaultSourceLinks(version: String = dottyNonBootstrappedVersion, refVersion: String = dottyVersion) = Def.task {
19602021
def stdLibVersion = stdlibVersion(NonBootstrapped)
1961-
def srcManaged(v: String, s: String) = s"out/bootstrap/stdlib-bootstrapped/scala-$v/src_managed/main/$s-library-src"
2022+
def srcManaged(v: String, s: String) = s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$v/src_managed/main/$s-library-src"
19622023
SourceLinks(
19632024
List(
19642025
scalaSrcLink(stdLibVersion, srcManaged(version, "scala") + "="),
@@ -2046,21 +2107,21 @@ object ScaladocConfigs {
20462107

20472108
lazy val Scala3 = Def.task {
20482109
val dottyJars: Seq[java.io.File] = Seq(
2049-
(`stdlib-bootstrapped`/Compile/products).value,
2110+
(`stdlib-bootstrapped-legacy`/Compile/products).value,
20502111
(`scala3-interfaces`/Compile/products).value,
20512112
(`tasty-core-bootstrapped`/Compile/products).value,
20522113
).flatten
20532114

20542115
val roots = dottyJars.map(_.getAbsolutePath)
20552116

20562117
val managedSources =
2057-
(`stdlib-bootstrapped`/Compile/sourceManaged).value / "scala-library-src"
2118+
(`stdlib-bootstrapped-legacy`/Compile/sourceManaged).value / "scala-library-src"
20582119
val projectRoot = (ThisBuild/baseDirectory).value.toPath
20592120
val stdLibRoot = projectRoot.relativize(managedSources.toPath.normalize())
20602121
val docRootFile = stdLibRoot.resolve("rootdoc.txt")
20612122

20622123
val dottyManagesSources =
2063-
(`stdlib-bootstrapped`/Compile/sourceManaged).value / "dotty-library-src"
2124+
(`stdlib-bootstrapped-legacy`/Compile/sourceManaged).value / "dotty-library-src"
20642125

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

@@ -2093,19 +2154,19 @@ object ScaladocConfigs {
20932154
.add(ProjectVersion(version))
20942155
.add(SnippetCompiler(
20952156
List(
2096-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src/scala/quoted=compile",
2097-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src/scala/compiletime=compile"
2157+
s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src/scala/quoted=compile",
2158+
s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src/scala/compiletime=compile"
20982159
)
20992160
))
21002161
.add(CommentSyntax(List(
2101-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src=markdown",
2102-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/scala-library-src=wiki",
2162+
s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src=markdown",
2163+
s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/scala-library-src=wiki",
21032164
"wiki"
21042165
)))
2105-
.add(DocRootContent(s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/scala-library-src/rootdoc.txt"))
2166+
.add(DocRootContent(s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/scala-library-src/rootdoc.txt"))
21062167
.withTargets(
21072168
Seq(
2108-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/classes",
2169+
s"out/bootstrap/stdlib-bootstrapped-legacy/scala-$version-bin-SNAPSHOT-nonbootstrapped/classes",
21092170
s"tmp/interfaces/target/classes",
21102171
s"out/bootstrap/tasty-core-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/classes"
21112172
)

0 commit comments

Comments
 (0)