Skip to content

Commit eaa372d

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 92cc57f commit eaa372d

File tree

5 files changed

+128
-78
lines changed

5 files changed

+128
-78
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 & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -926,50 +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-
settings(commonBootstrappedSettings).
929+
settings(stdliBootstrappedCommonSettings).
930930
settings(
931-
moduleName := "scala-library",
932-
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
933931
Compile/scalacOptions ++= {
934932
Seq(
935933
"-sourcepath",
936934
Seq(
937935
baseDirectory.value / "stdlib-bootstrapped" / "src",
938936
(Compile/sourceManaged).value / "scala-library-src",
939-
(Compile/sourceManaged).value / "dotty-library-src",
940937
).mkString(File.pathSeparator),
941938
)
942939
},
943-
Compile / doc / scalacOptions += "-Ydocument-synthetic-types",
944-
scalacOptions -= "-Xfatal-warnings",
945-
ivyConfigurations += SourceDeps.hide,
946-
transitiveClassifiers := Seq("sources"),
947-
libraryDependencies +=
948-
("org.scala-lang" % "scala-library" % stdlibVersion(Bootstrapped) % "sourcedeps"),
949-
(Compile / sourceGenerators) += Def.task {
950-
val s = streams.value
951-
val cacheDir = s.cacheDirectory
952-
val trgDir = (Compile / sourceManaged).value / "scala-library-src"
953-
954-
val report = updateClassifiers.value
955-
val scalaLibrarySourcesJar = report.select(
956-
configuration = configurationFilter("sourcedeps"),
957-
module = (_: ModuleID).name == "scala-library",
958-
artifact = artifactFilter(`type` = "src")).headOption.getOrElse {
959-
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)
960979
}
980+
}
981+
)
961982

962-
FileFunction.cached(cacheDir / s"fetchScalaLibrarySrc",
963-
FilesInfo.lastModified, FilesInfo.exists) { dependencies =>
964-
s.log.info(s"Unpacking scala-library sources to $trgDir...")
965-
if (trgDir.exists)
966-
IO.delete(trgDir)
967-
IO.createDirectory(trgDir)
968-
IO.unzip(scalaLibrarySourcesJar, trgDir)
969-
970-
((trgDir ** "*.scala") +++ (trgDir ** "*.java")).get.toSet
971-
} (Set(scalaLibrarySourcesJar)).toSeq
972-
}.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+
},
9731001
(Compile / sourceGenerators) += Def.task {
9741002
val s = streams.value
9751003
val cacheDir = s.cacheDirectory
@@ -1000,6 +1028,43 @@ object Build {
10001028

10011029
cachedFun(dottyLibSources.get.toSet).toSeq
10021030
}.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,
10031068
(Compile / sources) ~= (_.filterNot(file =>
10041069
// sources from https://github.com/scala/scala/tree/2.13.x/src/library-aux
10051070
file.getPath.endsWith("scala-library-src/scala/Any.scala") ||
@@ -1020,56 +1085,15 @@ object Build {
10201085
(Test / managedClasspath) ~= {
10211086
_.filterNot(file => file.data.getName == s"scala-library-${stdlibVersion(Bootstrapped)}.jar")
10221087
},
1088+
mimaCheckDirection := "backward",
10231089
mimaPreviousArtifacts +=
10241090
("org.scala-lang" % "scala-library" % stdlibVersion(Bootstrapped)),
1025-
mimaCheckDirection := "backward",
10261091
mimaExcludeAnnotations ++= Seq(
10271092
"scala.annotation.experimental",
10281093
"scala.annotation.specialized",
10291094
"scala.annotation.unspecialized",
1030-
),
1095+
),
10311096
mimaBinaryIssueFilters ++= MiMaFilters.LibraryBootstrapped,
1032-
run := {
1033-
val args: Seq[String] = spaceDelimited("<arg>").parsed
1034-
val reference = (Compile/sourceManaged).value / "scala-library-src"
1035-
args match {
1036-
case Seq("list") =>
1037-
println(s"List of non-overriden files in $reference")
1038-
reference.allPaths.get()
1039-
.flatMap(_.relativeTo(reference))
1040-
.filter(_.ext == "scala")
1041-
.sorted
1042-
.foreach(println)
1043-
case Seq(cmd @ ("clone" | "overwrite"), files*) =>
1044-
println("Cloning scala-library sources: " + files.mkString(", "))
1045-
for (file <- files) {
1046-
val referenceStdlibPaths = reference / file
1047-
val destination = baseDirectory.value / "src" / file
1048-
if (!referenceStdlibPaths.exists) {
1049-
println("Not found " + referenceStdlibPaths)
1050-
} else if (destination.exists && cmd == "clone") {
1051-
println(s"Already exists $file. (use `overwrite` command to overwrite)")
1052-
} else {
1053-
val action = if (cmd == "clone") "Cloning" else "Overwriting"
1054-
println(s"$action $file")
1055-
IO.copyFile(referenceStdlibPaths, destination)
1056-
}
1057-
}
1058-
case _ =>
1059-
println(
1060-
"""Usage:
1061-
|> stdlib-bootstrapped/run list
1062-
| -- lists all files that are not overriden in stdlib-bootstrapped/src
1063-
|
1064-
|> stdlib-bootstrapped/run clone <sources>*
1065-
| -- clones the specified sources from the stdlib-bootstrapped/src
1066-
| -- example: stdlib-bootstrapped/run clone scala/Option.scala
1067-
|
1068-
|> stdlib-bootstrapped/run overwrite <sources>*
1069-
| -- (danger) overwrites the specified sources from the stdlib-bootstrapped/src
1070-
|""".stripMargin)
1071-
}
1072-
}
10731097
)
10741098

10751099
/** Test the tasty generated by `stdlib-bootstrapped`
@@ -1087,7 +1111,7 @@ object Build {
10871111
settings(commonBootstrappedSettings).
10881112
settings(
10891113
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
1090-
javaOptions += "-Ddotty.scala.library=" + (`stdlib-bootstrapped` / Compile / packageBin).value.getAbsolutePath
1114+
javaOptions += "-Ddotty.scala.library=" + (`stdlib-full-bootstrapped` / Compile / packageBin).value.getAbsolutePath
10911115
)
10921116

10931117
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)