diff --git a/Manip.scala b/Manip.scala index 2a9124c..4133bc3 100644 --- a/Manip.scala +++ b/Manip.scala @@ -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 @@ -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 diff --git a/project.scala b/project.scala index 8623156..a3fbb24 100644 --- a/project.scala +++ b/project.scala @@ -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