Skip to content

Commit ec50c61

Browse files
committed
Add scala2-library-bootstrapped/run diff command
This command allow us to quickly see the diff between the original library and the overwritten files in `scala2-library-bootstrapped/src`. Instructions are printed with `scala2-library-bootstrapped/run` as with other commands for `scala2-library-bootstrapped`.
1 parent eae8831 commit ec50c61

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

project/Build.scala

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,8 @@ object Build {
11061106
},
11071107
run := {
11081108
val log = streams.value.log
1109+
val projectName = projectInfo.value.nameFormal
11091110
val args: Seq[String] = spaceDelimited("<arg>").parsed
1110-
args.foreach(println)
11111111
val rootDir = (ThisBuild / baseDirectory).value
11121112
val srcDir = (Compile / scalaSource).value.relativeTo(rootDir).get
11131113
val reference = (Compile/sourceManaged).value.relativeTo(rootDir).get / "scala-library-src"
@@ -1135,19 +1135,41 @@ object Build {
11351135
IO.copyFile(referenceStdlibPaths, destination)
11361136
}
11371137
}
1138+
case "diff" +: rest =>
1139+
log.info(s"Diffing ${name.value}/src with scala-library sources")
1140+
if (rest.size > 1) {
1141+
log.error(s"Too many arguments for $projectName/run diff")
1142+
} else {
1143+
val path = rest.headOption.getOrElse("")
1144+
val fullPath = srcDir / path
1145+
if (!fullPath.exists) {
1146+
log.error(s"$fullPath does not exist")
1147+
} else {
1148+
val command = s"git diff --diff-filter=ACMR --no-index --color=always -- $reference/$path $fullPath"
1149+
log.info(command)
1150+
import _root_.scala.sys.process._
1151+
command.!
1152+
}
1153+
}
11381154
case _ =>
11391155
val projectName = projectInfo.value.nameFormal
11401156
println(
11411157
s"""Usage:
11421158
|> $projectName/run list
1143-
| -- lists all files that are not overriden in scala2-library-bootstrapped/src
1159+
| -- lists all files that are not overriden in ${name.value}/src
11441160
|
11451161
|> $projectName/run clone <sources>*
1146-
| -- clones the specified sources from the scala2-library-bootstrapped/src
1162+
| -- clones the specified sources from the ${name.value}/src
11471163
| -- example: $projectName/run clone scala/Option.scala
11481164
|
11491165
|> $projectName/run overwrite <sources>*
1150-
| -- (danger) overwrites the specified sources from the scala2-library-bootstrapped/src
1166+
| -- (danger) overwrites the specified sources from the ${name.value}/src
1167+
|
1168+
|> $projectName/run diff [path]
1169+
| -- shows the git diff between the reference library sources the sources used to compile $projectName
1170+
| -- [path] optional path in the library, eg:
1171+
| -- $projectName/run diff scala/Predef.scala
1172+
| -- $projectName/run diff scala/collection/immutable
11511173
|""".stripMargin)
11521174
}
11531175
}

0 commit comments

Comments
 (0)