Skip to content

Commit

Permalink
Add scala2-library-cc/run diff sbt command
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
nicolasstucki committed Dec 20, 2023
1 parent 2039d62 commit a7108d7
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,8 @@ object Build {
},
run := {
val log = streams.value.log
val projectName = projectInfo.value.nameFormal
val args: Seq[String] = spaceDelimited("<arg>").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"
Expand Down Expand Up @@ -1180,8 +1180,23 @@ object Build {
IO.copyFile(referenceStdlibPaths, destination)
}
}
case "diff" +: rest =>
log.info(s"Diffing ${name.value}/src with scala-library sources")
if (rest.size > 1) {
log.error(s"Too many arguments for $projectName/run diff")
} else {
val path = rest.headOption.getOrElse("")
val fullPath = srcDir / path
if (!fullPath.exists) {
log.error(s"$fullPath does not exist")
} else {
val command = s"git diff --diff-filter=ACMR --no-index --color=always -- $reference/$path $fullPath"
log.info(command)
import _root_.scala.sys.process._
command.!
}
}
case _ =>
val projectName = projectInfo.value.nameFormal
println(
s"""Usage:
|> $projectName/run list
Expand All @@ -1193,6 +1208,12 @@ object Build {
|
|> $projectName/run overwrite <sources>*
| -- (danger) overwrites the specified sources from the ${name.value}/src
|
|> $projectName/run diff [path]
| -- shows the git diff between the reference library sources the sources used to compile $projectName
| -- [path] optional path in the library, eg:
| -- $projectName/run diff scala/Option.scala
| -- $projectName/run diff scala/collection/immutable
|""".stripMargin)
}
}
Expand Down

0 comments on commit a7108d7

Please sign in to comment.