@@ -998,6 +998,52 @@ object Build {
998998 // We first need to check that a project can depend on a JAR that only contains TASTy files.
999999 // Compile / exportJars := true,
10001000 // Compile / packageBin / mappings ~= { _.filter(_._2.endsWith(".tasty")) },
1001+ run := {
1002+ val log = streams.value.log
1003+ val args : Seq [String ] = spaceDelimited(" <arg>" ).parsed
1004+ args.foreach(println)
1005+ val rootDir = (ThisBuild / baseDirectory).value
1006+ val srcDir = (Compile / scalaSource).value.relativeTo(rootDir).get
1007+ val reference = (Compile / sourceManaged).value.relativeTo(rootDir).get / " scala-library-src"
1008+ args match {
1009+ case Seq (" list" ) =>
1010+ log.info(s " Printing list of non-overriden files in $reference" )
1011+ reference.allPaths.get()
1012+ .flatMap(_.relativeTo(reference))
1013+ .filter(_.ext == " scala" )
1014+ .sorted
1015+ .foreach(println)
1016+ case Seq (cmd @ (" clone" | " overwrite" ), files* ) =>
1017+ log.info(" Cloning scala-library sources: " + files.mkString(" , " ))
1018+ for (file <- files) {
1019+ val referenceStdlibPaths = reference / file
1020+ val destination = srcDir / file
1021+ if (! referenceStdlibPaths.exists) {
1022+ log.error(" Not found " + referenceStdlibPaths)
1023+ } else if (destination.exists && cmd == " clone" ) {
1024+ log.warn(s " Already exists $destination (use `overwrite` command to overwrite) " )
1025+ } else {
1026+ val action = if (cmd == " clone" ) " Cloning" else " Overwriting"
1027+ log.info(s " $action $destination" )
1028+ IO .copyFile(referenceStdlibPaths, destination)
1029+ }
1030+ }
1031+ case _ =>
1032+ val projectName = projectInfo.value.nameFormal
1033+ println(
1034+ s """ Usage:
1035+ |> $projectName/run list
1036+ | -- lists all files that are not overriden in stdlib-bootstrapped/src
1037+ |
1038+ |> $projectName/run clone <sources>*
1039+ | -- clones the specified sources from the stdlib-bootstrapped/src
1040+ | -- example: $projectName/run clone scala/Option.scala
1041+ |
1042+ |> $projectName/run overwrite <sources>*
1043+ | -- (danger) overwrites the specified sources from the stdlib-bootstrapped/src
1044+ | """ .stripMargin)
1045+ }
1046+ }
10011047 )
10021048
10031049 /** Test the tasty generated by `stdlib-bootstrapped`
0 commit comments