Skip to content

Commit 2cdeff3

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 2bcc5a2 commit 2cdeff3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

project/Build.scala

+23-2
Original file line numberDiff line numberDiff line change
@@ -1144,8 +1144,8 @@ object Build {
11441144
},
11451145
run := {
11461146
val log = streams.value.log
1147+
val projectName = projectInfo.value.nameFormal
11471148
val args: Seq[String] = spaceDelimited("<arg>").parsed
1148-
args.foreach(println)
11491149
val rootDir = (ThisBuild / baseDirectory).value
11501150
val srcDir = (Compile / scalaSource).value.relativeTo(rootDir).get
11511151
val reference = (Compile/sourceManaged).value.relativeTo(rootDir).get / "scala-library-src"
@@ -1173,8 +1173,23 @@ object Build {
11731173
IO.copyFile(referenceStdlibPaths, destination)
11741174
}
11751175
}
1176+
case "diff" +: rest =>
1177+
log.info(s"Diffing ${name.value}/src with scala-library sources")
1178+
if (rest.size > 1) {
1179+
log.error(s"Too many arguments for $projectName/run diff")
1180+
} else {
1181+
val path = rest.headOption.getOrElse("")
1182+
val fullPath = srcDir / path
1183+
if (!fullPath.exists) {
1184+
log.error(s"$fullPath does not exist")
1185+
} else {
1186+
val command = s"git diff --diff-filter=ACMR --no-index --color=always -- $reference/$path $fullPath"
1187+
log.info(command)
1188+
import _root_.scala.sys.process._
1189+
command.!
1190+
}
1191+
}
11761192
case _ =>
1177-
val projectName = projectInfo.value.nameFormal
11781193
println(
11791194
s"""Usage:
11801195
|> $projectName/run list
@@ -1186,6 +1201,12 @@ object Build {
11861201
|
11871202
|> $projectName/run overwrite <sources>*
11881203
| -- (danger) overwrites the specified sources from the ${name.value}/src
1204+
|
1205+
|> $projectName/run diff [path]
1206+
| -- shows the git diff between the reference library sources the sources used to compile $projectName
1207+
| -- [path] optional path in the library, eg:
1208+
| -- $projectName/run diff scala/Option.scala
1209+
| -- $projectName/run diff scala/collection/immutable
11891210
|""".stripMargin)
11901211
}
11911212
}

0 commit comments

Comments
 (0)