From f995c4ed6d3ee6709e29a3ae9a926396fd035ee2 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 24 Nov 2023 10:17:02 +0100 Subject: [PATCH] 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 ``` --- project/Build.scala | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/project/Build.scala b/project/Build.scala index 83da5f0df94a..2be361665d35 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1144,8 +1144,8 @@ object Build { }, run := { val log = streams.value.log + val projectName = projectInfo.value.nameFormal val args: Seq[String] = spaceDelimited("").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" @@ -1173,8 +1173,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 @@ -1186,6 +1201,12 @@ object Build { | |> $projectName/run overwrite * | -- (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) } }