Skip to content

Commit 3e2a9a5

Browse files
Add scala2-library-bootstrapped/run diff command (#19306)
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`. Extracted from #18967. Also useful for #19231.
2 parents 33bdaac + 045d667 commit 3e2a9a5

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

project/Build.scala

+27-4
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,42 @@ 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+
// `--diff-filter=ACMR` is missing `D` on purpose not to show all the files that have not been overwritten.
1149+
val command = s"git diff --diff-filter=ACMR --no-index --color=always -- $reference/$path $fullPath"
1150+
log.info(command)
1151+
import _root_.scala.sys.process._
1152+
command.!
1153+
}
1154+
}
11381155
case _ =>
11391156
val projectName = projectInfo.value.nameFormal
11401157
println(
11411158
s"""Usage:
11421159
|> $projectName/run list
1143-
| -- lists all files that are not overriden in scala2-library-bootstrapped/src
1160+
| -- lists all files that are not overriden in ${name.value}/src
11441161
|
11451162
|> $projectName/run clone <sources>*
1146-
| -- clones the specified sources from the scala2-library-bootstrapped/src
1163+
| -- clones the specified sources from the ${name.value}/src
11471164
| -- example: $projectName/run clone scala/Option.scala
11481165
|
11491166
|> $projectName/run overwrite <sources>*
1150-
| -- (danger) overwrites the specified sources from the scala2-library-bootstrapped/src
1167+
| -- (danger) overwrites the specified sources from the ${name.value}/src
1168+
|
1169+
|> $projectName/run diff [path]
1170+
| -- shows the git diff between the reference library sources the sources used to compile $projectName
1171+
| -- [path] optional path in the library, eg:
1172+
| -- $projectName/run diff scala/Predef.scala
1173+
| -- $projectName/run diff scala/collection/immutable
11511174
|""".stripMargin)
11521175
}
11531176
}

0 commit comments

Comments
 (0)