Skip to content

Commit a7108d7

Browse files
committed
Add scala2-library-cc/run diff sbt command
This command runs `git diff` to show the changes that where made relative to the original Scala 2 library sources. Usage: ``` sbt> scala2-library-cc/run diff # shows all changes sbt> scala2-library-cc/run diff scala/Option.scala # show changes in this file sbt> scala2-library-cc/run diff scala/collection/immutable # show changes in this directory ```
1 parent 2039d62 commit a7108d7

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

project/Build.scala

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,8 +1151,8 @@ object Build {
11511151
},
11521152
run := {
11531153
val log = streams.value.log
1154+
val projectName = projectInfo.value.nameFormal
11541155
val args: Seq[String] = spaceDelimited("<arg>").parsed
1155-
args.foreach(println)
11561156
val rootDir = (ThisBuild / baseDirectory).value
11571157
val srcDir = (Compile / scalaSource).value.relativeTo(rootDir).get
11581158
val reference = (Compile/sourceManaged).value.relativeTo(rootDir).get / "scala-library-src"
@@ -1180,8 +1180,23 @@ object Build {
11801180
IO.copyFile(referenceStdlibPaths, destination)
11811181
}
11821182
}
1183+
case "diff" +: rest =>
1184+
log.info(s"Diffing ${name.value}/src with scala-library sources")
1185+
if (rest.size > 1) {
1186+
log.error(s"Too many arguments for $projectName/run diff")
1187+
} else {
1188+
val path = rest.headOption.getOrElse("")
1189+
val fullPath = srcDir / path
1190+
if (!fullPath.exists) {
1191+
log.error(s"$fullPath does not exist")
1192+
} else {
1193+
val command = s"git diff --diff-filter=ACMR --no-index --color=always -- $reference/$path $fullPath"
1194+
log.info(command)
1195+
import _root_.scala.sys.process._
1196+
command.!
1197+
}
1198+
}
11831199
case _ =>
1184-
val projectName = projectInfo.value.nameFormal
11851200
println(
11861201
s"""Usage:
11871202
|> $projectName/run list
@@ -1193,6 +1208,12 @@ object Build {
11931208
|
11941209
|> $projectName/run overwrite <sources>*
11951210
| -- (danger) overwrites the specified sources from the ${name.value}/src
1211+
|
1212+
|> $projectName/run diff [path]
1213+
| -- shows the git diff between the reference library sources the sources used to compile $projectName
1214+
| -- [path] optional path in the library, eg:
1215+
| -- $projectName/run diff scala/Option.scala
1216+
| -- $projectName/run diff scala/collection/immutable
11961217
|""".stripMargin)
11971218
}
11981219
}

0 commit comments

Comments
 (0)