Skip to content

Commit dde0482

Browse files
committed
Split stdlib-bootstrapped into stdlib-full-bootstrapped and stdlib-bootstrapped
The first only contains the files form the Scala 2 stdlib, the second also contains the files from the Scala 3 stdlib.
1 parent 2631e59 commit dde0482

File tree

5 files changed

+128
-79
lines changed

5 files changed

+128
-79
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134

135135
- name: Cmd Tests
136136
run: |
137-
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
137+
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-full-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
138138
./project/scripts/cmdTests
139139
./project/scripts/bootstrappedOnlyCmdTests
140140
@@ -253,7 +253,7 @@ jobs:
253253

254254
- name: MiMa
255255
run: |
256-
./project/scripts/sbt ";scala3-interfaces/mimaReportBinaryIssues ;scala3-library-bootstrapped/mimaReportBinaryIssues ;scala3-library-bootstrappedJS/mimaReportBinaryIssues; tasty-core-bootstrapped/mimaReportBinaryIssues; stdlib-bootstrapped/mimaReportBinaryIssues"
256+
./project/scripts/sbt ";scala3-interfaces/mimaReportBinaryIssues ;scala3-library-bootstrapped/mimaReportBinaryIssues ;scala3-library-bootstrappedJS/mimaReportBinaryIssues; tasty-core-bootstrapped/mimaReportBinaryIssues; stdlib-bootstrapped/mimaReportBinaryIssues; stdlib-full-bootstrapped/mimaReportBinaryIssues"
257257
258258
community_build_a:
259259
runs-on: [self-hosted, Linux]

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ val `scala3-bench` = Build.`scala3-bench`
1515
val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped`
1616
val `scala3-bench-micro` = Build.`scala3-bench-micro`
1717
val `stdlib-bootstrapped` = Build.`stdlib-bootstrapped`
18+
val `stdlib-full-bootstrapped` = Build.`stdlib-full-bootstrapped`
1819
val `stdlib-bootstrapped-tasty-tests` = Build.`stdlib-bootstrapped-tasty-tests`
1920
val `tasty-core` = Build.`tasty-core`
2021
val `tasty-core-bootstrapped` = Build.`tasty-core-bootstrapped`

project/Build.scala

Lines changed: 100 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -926,51 +926,78 @@ object Build {
926926
lazy val `stdlib-bootstrapped` = project.in(file("stdlib-bootstrapped")).
927927
withCommonSettings(Bootstrapped).
928928
dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
929-
dependsOn(`scala3-tasty-inspector` % "test->test").
930-
settings(commonBootstrappedSettings).
929+
settings(stdliBootstrappedCommonSettings).
931930
settings(
932-
moduleName := "scala-library",
933-
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
934931
Compile/scalacOptions ++= {
935932
Seq(
936933
"-sourcepath",
937934
Seq(
938935
baseDirectory.value / "stdlib-bootstrapped" / "src",
939936
(Compile/sourceManaged).value / "scala-library-src",
940-
(Compile/sourceManaged).value / "dotty-library-src",
941937
).mkString(File.pathSeparator),
942938
)
943939
},
944-
Compile / doc / scalacOptions += "-Ydocument-synthetic-types",
945-
scalacOptions -= "-Xfatal-warnings",
946-
ivyConfigurations += SourceDeps.hide,
947-
transitiveClassifiers := Seq("sources"),
948-
libraryDependencies +=
949-
("org.scala-lang" % "scala-library" % stdlibVersion(Bootstrapped) % "sourcedeps"),
950-
(Compile / sourceGenerators) += Def.task {
951-
val s = streams.value
952-
val cacheDir = s.cacheDirectory
953-
val trgDir = (Compile / sourceManaged).value / "scala-library-src"
954-
955-
val report = updateClassifiers.value
956-
val scalaLibrarySourcesJar = report.select(
957-
configuration = configurationFilter("sourcedeps"),
958-
module = (_: ModuleID).name == "scala-library",
959-
artifact = artifactFilter(`type` = "src")).headOption.getOrElse {
960-
sys.error(s"Could not fetch scala-library sources")
940+
run := {
941+
val args: Seq[String] = spaceDelimited("<arg>").parsed
942+
val reference = (Compile/sourceManaged).value / "scala-library-src"
943+
args match {
944+
case Seq("list") =>
945+
println(s"List of non-overriden files in $reference")
946+
reference.allPaths.get()
947+
.flatMap(_.relativeTo(reference))
948+
.filter(_.ext == "scala")
949+
.sorted
950+
.foreach(println)
951+
case Seq(cmd @ ("clone" | "overwrite"), files*) =>
952+
println("Cloning scala-library sources: " + files.mkString(", "))
953+
for (file <- files) {
954+
val referenceStdlibPaths = reference / file
955+
val destination = baseDirectory.value / "src" / file
956+
if (!referenceStdlibPaths.exists) {
957+
println("Not found " + referenceStdlibPaths)
958+
} else if (destination.exists && cmd == "clone") {
959+
println(s"Already exists $file. (use `overwrite` command to overwrite)")
960+
} else {
961+
val action = if (cmd == "clone") "Cloning" else "Overwriting"
962+
println(s"$action $file")
963+
IO.copyFile(referenceStdlibPaths, destination)
964+
}
965+
}
966+
case _ =>
967+
println(
968+
"""Usage:
969+
|> stdlib-bootstrapped/run list
970+
| -- lists all files that are not overriden in stdlib-bootstrapped/src
971+
|
972+
|> stdlib-bootstrapped/run clone <sources>*
973+
| -- clones the specified sources from the stdlib-bootstrapped/src
974+
| -- example: stdlib-bootstrapped/run clone scala/Option.scala
975+
|
976+
|> stdlib-bootstrapped/run overwrite <sources>*
977+
| -- (danger) overwrites the specified sources from the stdlib-bootstrapped/src
978+
|""".stripMargin)
961979
}
980+
}
981+
)
962982

963-
FileFunction.cached(cacheDir / s"fetchScalaLibrarySrc",
964-
FilesInfo.lastModified, FilesInfo.exists) { dependencies =>
965-
s.log.info(s"Unpacking scala-library sources to $trgDir...")
966-
if (trgDir.exists)
967-
IO.delete(trgDir)
968-
IO.createDirectory(trgDir)
969-
IO.unzip(scalaLibrarySourcesJar, trgDir)
970-
971-
((trgDir ** "*.scala") +++ (trgDir ** "*.java")).get.toSet
972-
} (Set(scalaLibrarySourcesJar)).toSeq
973-
}.taskValue,
983+
/** Scala library compiled by dotty using the latest published sources of the library
984+
* and the current Scala 3 livrary sources
985+
*/
986+
lazy val `stdlib-full-bootstrapped` = project.in(file("stdlib-full-bootstrapped")).
987+
withCommonSettings(Bootstrapped).
988+
dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
989+
settings(stdliBootstrappedCommonSettings).
990+
settings(
991+
Compile/scalacOptions ++= {
992+
Seq(
993+
"-sourcepath",
994+
Seq(
995+
baseDirectory.value / "stdlib-bootstrapped" / "src",
996+
(Compile/sourceManaged).value / "scala-library-src",
997+
(Compile/sourceManaged).value / "dotty-library-src",
998+
).mkString(File.pathSeparator),
999+
)
1000+
},
9741001
(Compile / sourceGenerators) += Def.task {
9751002
val s = streams.value
9761003
val cacheDir = s.cacheDirectory
@@ -1001,6 +1028,43 @@ object Build {
10011028

10021029
cachedFun(dottyLibSources.get.toSet).toSeq
10031030
}.taskValue,
1031+
)
1032+
1033+
lazy val stdliBootstrappedCommonSettings =
1034+
commonBootstrappedSettings ++
1035+
Seq(
1036+
moduleName := "scala-library",
1037+
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
1038+
Compile / doc / scalacOptions += "-Ydocument-synthetic-types",
1039+
scalacOptions -= "-Xfatal-warnings",
1040+
ivyConfigurations += SourceDeps.hide,
1041+
transitiveClassifiers := Seq("sources"),
1042+
libraryDependencies +=
1043+
("org.scala-lang" % "scala-library" % stdlibVersion(Bootstrapped) % "sourcedeps"),
1044+
(Compile / sourceGenerators) += Def.task {
1045+
val s = streams.value
1046+
val cacheDir = s.cacheDirectory
1047+
val trgDir = (Compile / sourceManaged).value / "scala-library-src"
1048+
1049+
val report = updateClassifiers.value
1050+
val scalaLibrarySourcesJar = report.select(
1051+
configuration = configurationFilter("sourcedeps"),
1052+
module = (_: ModuleID).name == "scala-library",
1053+
artifact = artifactFilter(`type` = "src")).headOption.getOrElse {
1054+
sys.error(s"Could not fetch scala-library sources")
1055+
}
1056+
1057+
FileFunction.cached(cacheDir / s"fetchScalaLibrarySrc",
1058+
FilesInfo.lastModified, FilesInfo.exists) { dependencies =>
1059+
s.log.info(s"Unpacking scala-library sources to $trgDir...")
1060+
if (trgDir.exists)
1061+
IO.delete(trgDir)
1062+
IO.createDirectory(trgDir)
1063+
IO.unzip(scalaLibrarySourcesJar, trgDir)
1064+
1065+
((trgDir ** "*.scala") +++ (trgDir ** "*.java")).get.toSet
1066+
} (Set(scalaLibrarySourcesJar)).toSeq
1067+
}.taskValue,
10041068
(Compile / sources) ~= (_.filterNot(file =>
10051069
// sources from https://github.com/scala/scala/tree/2.13.x/src/library-aux
10061070
file.getPath.endsWith("scala-library-src/scala/Any.scala") ||
@@ -1021,56 +1085,15 @@ object Build {
10211085
(Test / managedClasspath) ~= {
10221086
_.filterNot(file => file.data.getName == s"scala-library-${stdlibVersion(Bootstrapped)}.jar")
10231087
},
1088+
mimaCheckDirection := "backward",
10241089
mimaPreviousArtifacts +=
10251090
("org.scala-lang" % "scala-library" % stdlibVersion(Bootstrapped)),
1026-
mimaCheckDirection := "backward",
10271091
mimaExcludeAnnotations ++= Seq(
10281092
"scala.annotation.experimental",
10291093
"scala.annotation.specialized",
10301094
"scala.annotation.unspecialized",
1031-
),
1095+
),
10321096
mimaBinaryIssueFilters ++= MiMaFilters.LibraryBootstrapped,
1033-
run := {
1034-
val args: Seq[String] = spaceDelimited("<arg>").parsed
1035-
val reference = (Compile/sourceManaged).value / "scala-library-src"
1036-
args match {
1037-
case Seq("list") =>
1038-
println(s"List of non-overriden files in $reference")
1039-
reference.allPaths.get()
1040-
.flatMap(_.relativeTo(reference))
1041-
.filter(_.ext == "scala")
1042-
.sorted
1043-
.foreach(println)
1044-
case Seq(cmd @ ("clone" | "overwrite"), files*) =>
1045-
println("Cloning scala-library sources: " + files.mkString(", "))
1046-
for (file <- files) {
1047-
val referenceStdlibPaths = reference / file
1048-
val destination = baseDirectory.value / "src" / file
1049-
if (!referenceStdlibPaths.exists) {
1050-
println("Not found " + referenceStdlibPaths)
1051-
} else if (destination.exists && cmd == "clone") {
1052-
println(s"Already exists $file. (use `overwrite` command to overwrite)")
1053-
} else {
1054-
val action = if (cmd == "clone") "Cloning" else "Overwriting"
1055-
println(s"$action $file")
1056-
IO.copyFile(referenceStdlibPaths, destination)
1057-
}
1058-
}
1059-
case _ =>
1060-
println(
1061-
"""Usage:
1062-
|> stdlib-bootstrapped/run list
1063-
| -- lists all files that are not overriden in stdlib-bootstrapped/src
1064-
|
1065-
|> stdlib-bootstrapped/run clone <sources>*
1066-
| -- clones the specified sources from the stdlib-bootstrapped/src
1067-
| -- example: stdlib-bootstrapped/run clone scala/Option.scala
1068-
|
1069-
|> stdlib-bootstrapped/run overwrite <sources>*
1070-
| -- (danger) overwrites the specified sources from the stdlib-bootstrapped/src
1071-
|""".stripMargin)
1072-
}
1073-
}
10741097
)
10751098

10761099
/** Test the tasty generated by `stdlib-bootstrapped`
@@ -1088,7 +1111,7 @@ object Build {
10881111
settings(commonBootstrappedSettings).
10891112
settings(
10901113
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
1091-
javaOptions += "-Ddotty.scala.library=" + (`stdlib-bootstrapped` / Compile / packageBin).value.getAbsolutePath
1114+
javaOptions += "-Ddotty.scala.library=" + (`stdlib-full-bootstrapped` / Compile / packageBin).value.getAbsolutePath
10921115
)
10931116

10941117
lazy val `scala3-sbt-bridge` = project.in(file("sbt-bridge/src")).

stdlib-full-bootstrapped/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## stdlib-full-bootstrapped
2+
3+
This project compiles the Scala standard library using the Scala 3 compiler.
4+
It uses the sources Scala (2/3) standard library sources from `stdlib-bootstrapped/src`
5+
and the Scala 3 library form `library/src`. It fetches any missing Scala (2/3) sources
6+
from `org.scala-lang" % "scala-library" % stdlibVersion(Bootstrapped) % "sourcedeps`.
7+
This implies that files in `stdlib-bootstrapped/src` override files override the Scala (2/3)
8+
sources. Currently we can not override files from `library/src`.
9+
10+
To clone or list non-overridden sources execute `stdlib-bootstrapped/run`.
11+
12+
This project generates a version of the Scala 3 library that contains the full library with
13+
TASTy files. The compiled library is located in `out/bootstrap/stdlib-full-bootstrapped/`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package hello
2+
3+
enum Color:
4+
case Red, Green, Blue
5+
6+
object HelloWorld:
7+
def main(args: Array[String]): Unit = {
8+
println("hello dotty.superbootstrapped!")
9+
println(Color.Red)
10+
println(Color.Green)
11+
println(Color.Blue)
12+
}

0 commit comments

Comments
 (0)