Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions Manip.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package distcompiler

import cats.syntax.all.given
import util.{++, toShortString}
import com.github.difflib.{DiffUtils, UnifiedDiffUtils}
import scala.jdk.CollectionConverters._

enum Manip[+T]:
private inline given DebugInfo = DebugInfo.poison
Expand Down Expand Up @@ -438,20 +440,21 @@ object Manip:
)

private def takeDiff()(using RefMap): Unit =
val result =
os.proc(
"diff",
"--report-identical-files",
"--ignore-space-change",
prevPath,
currPath
).call(
stdout = os.PathRedirect(diffPath),
check = false
)
if result.exitCode == 0 || result.exitCode == 1
then () // fine (1 is used to mean files are different)
else throw RuntimeException(result.toString())
val prevLines = os.read.lines(prevPath).asJava
val currLines = os.read.lines(currPath).asJava
val patch = DiffUtils.diff(prevLines, currLines)
val unifiedDiff = UnifiedDiffUtils.generateUnifiedDiff(
prevPath.toString(),
currPath.toString(),
prevLines,
patch,
3
)

os.write.over(
diffPath,
unifiedDiff.asScala.mkString("\n")
)

override def beforePass(debugInfo: DebugInfo)(using RefMap): Unit =
passCounter += 1
Expand Down
1 change: 1 addition & 0 deletions project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//> using dep org.typelevel::cats-core:2.13.0
//> using dep dev.zio::izumi-reflect:3.0.1
//> using dep com.lihaoyi::ujson::4.1.0
//> using dependency "io.github.java-diff-utils:java-diff-utils:4.15"
//> using test.dep org.scalameta::munit:1.1.0

//> using javaProp distcompiler.Node.assertErrorRefCorrectness=no
Expand Down