Skip to content

Add script to copy reference stdlib sources into stdlib-bootstrapped #17487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,52 @@ object Build {
// We first need to check that a project can depend on a JAR that only contains TASTy files.
// Compile / exportJars := true,
// Compile / packageBin / mappings ~= { _.filter(_._2.endsWith(".tasty")) },
run := {
val log = streams.value.log
val args: Seq[String] = spaceDelimited("<arg>").parsed
args.foreach(println)
val rootDir = (ThisBuild / baseDirectory).value
val srcDir = (Compile / scalaSource).value.relativeTo(rootDir).get
val reference = (Compile/sourceManaged).value.relativeTo(rootDir).get / "scala-library-src"
args match {
case Seq("list") =>
log.info(s"Printing list of non-overriden files in $reference")
reference.allPaths.get()
.flatMap(_.relativeTo(reference))
.filter(_.ext == "scala")
.sorted
.foreach(println)
case Seq(cmd @ ("clone" | "overwrite"), files*) =>
log.info("Cloning scala-library sources: " + files.mkString(", "))
for (file <- files) {
val referenceStdlibPaths = reference / file
val destination = srcDir / file
if (!referenceStdlibPaths.exists) {
log.error("Not found " + referenceStdlibPaths)
} else if (destination.exists && cmd == "clone") {
log.warn(s"Already exists $destination (use `overwrite` command to overwrite)")
} else {
val action = if (cmd == "clone") "Cloning" else "Overwriting"
log.info(s"$action $destination")
IO.copyFile(referenceStdlibPaths, destination)
}
}
case _ =>
val projectName = projectInfo.value.nameFormal
println(
s"""Usage:
|> $projectName/run list
| -- lists all files that are not overriden in stdlib-bootstrapped/src
|
|> $projectName/run clone <sources>*
| -- clones the specified sources from the stdlib-bootstrapped/src
| -- example: $projectName/run clone scala/Option.scala
|
|> $projectName/run overwrite <sources>*
| -- (danger) overwrites the specified sources from the stdlib-bootstrapped/src
|""".stripMargin)
}
}
)

/** Test the tasty generated by `stdlib-bootstrapped`
Expand Down