diff --git a/project/Build.scala b/project/Build.scala index 892a98b2852f..d592f1bdabe2 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -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("").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 * + | -- clones the specified sources from the stdlib-bootstrapped/src + | -- example: $projectName/run clone scala/Option.scala + | + |> $projectName/run overwrite * + | -- (danger) overwrites the specified sources from the stdlib-bootstrapped/src + |""".stripMargin) + } + } ) /** Test the tasty generated by `stdlib-bootstrapped`