Skip to content

Commit

Permalink
Add patcher
Browse files Browse the repository at this point in the history
  • Loading branch information
bobismijnnaam committed Aug 8, 2024
1 parent bc829b6 commit 8c4477e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions bin/patcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e
ROOT=$(dirname $(dirname $(readlink -f $0)))
(cd $ROOT; ./mill -j 0 vercors.main.runScript)
$ROOT/out/vercors/main/runScript.dest/patcher "$@"
11 changes: 11 additions & 0 deletions bin/patcher.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off
setlocal

set BIN=%~dp0
set ROOT=%BIN%..

pushd %ROOT%
call mill vercors.main.runScript
popd

"%ROOT%\out\vercors\main\runScript.dest\patcher" %*
1 change: 1 addition & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ object vercors extends Module {
"carbon" -> "viper.carbon.Carbon",
"silicon" -> "viper.silicon.SiliconRunner",
"bashOptions" -> "vct.options.BashCompletion",
"patcher" -> "hre.util.Patch",
) }
override def packedResources = T.sources()
override def bareResourcePaths = T {
Expand Down
22 changes: 19 additions & 3 deletions src/hre/hre/util/Patch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,25 @@ case object Patch {
}

def main(args: Array[String]): Unit = {
println(fromFile(Paths.get(
"examples/concepts/veymont/FM2024 - VeyMont/1-TTTmsg/testFiles/1-TTTmsg-patches.txt"
)))
if (args.length != 3) {
println(
"Incorrect number of arguments. Expected usage: `patcher [patch path] [input path] [output path]`"
)
return
}

val patchFile = Paths.get(args(0))
val inFile = Paths.get(args(1))
val outFile = Paths.get(args(2))

Files.writeString(
outFile,
applyAll(Patch.fromFile(patchFile), Files.readString(inFile)),
)

println(
s"Patched $inFile with patch in $patchFile and wrote result to $outFile"
)
}

def applyAll(patches: Seq[Patch], source: String): String =
Expand Down

0 comments on commit 8c4477e

Please sign in to comment.