From 40d1826522d3d0e8c739ff8e2677c0beead82a34 Mon Sep 17 00:00:00 2001 From: Eryk Szpotanski Date: Mon, 29 Jul 2024 13:38:03 +0200 Subject: [PATCH] simulator: Format displayed commands with quotes for multiple arguments Signed-off-by: Eryk Szpotanski --- .../scala/chiseltest/simulator/IcarusSimulator.scala | 6 ++++-- src/main/scala/chiseltest/simulator/Utils.scala | 9 +++++++++ .../scala/chiseltest/simulator/VerilatorSimulator.scala | 3 ++- .../chiseltest/simulator/ipc/IPCSimulatorContext.scala | 4 ++-- 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 src/main/scala/chiseltest/simulator/Utils.scala diff --git a/src/main/scala/chiseltest/simulator/IcarusSimulator.scala b/src/main/scala/chiseltest/simulator/IcarusSimulator.scala index 92f57c678..8c58db22f 100644 --- a/src/main/scala/chiseltest/simulator/IcarusSimulator.scala +++ b/src/main/scala/chiseltest/simulator/IcarusSimulator.scala @@ -113,7 +113,9 @@ private object IcarusSimulator extends Simulator with LazyLogging { val success = ret.exitCode == 0 && os.exists(lib) assert( success, - s"failed to compiler VPI shared library for circuit ${topName} in work dir $compileDir\n" + cmd.mkString(" ") + s"failed to compiler VPI shared library for circuit ${topName} in work dir $compileDir\n" + Utils.quoteCmdArgs( + cmd + ) ) lib } @@ -141,7 +143,7 @@ private object IcarusSimulator extends Simulator with LazyLogging { val ret = os.proc(cmd).call(cwd = os.pwd, check = false) val success = ret.exitCode == 0 && os.exists(os.pwd / simBinary) - assert(success, s"iverilog command failed on circuit ${topName} in work dir $targetDir\n" + cmd.mkString(" ")) + assert(success, s"iverilog command failed on circuit ${topName} in work dir $targetDir\n" + Utils.quoteCmdArgs(cmd)) Seq("vvp", simBinary.toString()) } diff --git a/src/main/scala/chiseltest/simulator/Utils.scala b/src/main/scala/chiseltest/simulator/Utils.scala new file mode 100644 index 000000000..d8a202d6d --- /dev/null +++ b/src/main/scala/chiseltest/simulator/Utils.scala @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: Apache-2.0 + +package chiseltest.simulator + +object Utils { + def quoteCmdArgs(cmd: Seq[String]): String = { + cmd.map(arg => if (arg.contains(" ")) s""""$arg"""" else arg).mkString(" ") + } +} diff --git a/src/main/scala/chiseltest/simulator/VerilatorSimulator.scala b/src/main/scala/chiseltest/simulator/VerilatorSimulator.scala index 1720e1767..3a2003050 100644 --- a/src/main/scala/chiseltest/simulator/VerilatorSimulator.scala +++ b/src/main/scala/chiseltest/simulator/VerilatorSimulator.scala @@ -5,6 +5,7 @@ package chiseltest.simulator import firrtl2._ import firrtl2.annotations._ import chiseltest.simulator.jna._ +import chiseltest.simulator.Utils.quoteCmdArgs case object VerilatorBackendAnnotation extends SimulatorAnnotation { override def getSimulator: Simulator = VerilatorSimulator @@ -219,7 +220,7 @@ private object VerilatorSimulator extends Simulator { private def run(cmd: Seq[String], cwd: os.Path, verbose: Boolean): os.CommandResult = { if (verbose) { // print the command and pipe the output to stdout - println(cmd.mkString(" ")) + println(quoteCmdArgs(cmd)) os.proc(cmd) .call(cwd = cwd, stdout = os.ProcessOutput.Readlines(println), stderr = os.ProcessOutput.Readlines(println)) } else { diff --git a/src/main/scala/chiseltest/simulator/ipc/IPCSimulatorContext.scala b/src/main/scala/chiseltest/simulator/ipc/IPCSimulatorContext.scala index 646a807a5..31159db29 100644 --- a/src/main/scala/chiseltest/simulator/ipc/IPCSimulatorContext.scala +++ b/src/main/scala/chiseltest/simulator/ipc/IPCSimulatorContext.scala @@ -321,7 +321,7 @@ private[chiseltest] class IPCSimulatorContext( private def start(): Unit = { if (verbose) - println(s"""STARTING ${cmd.mkString(" ")}""") + println(s"""STARTING ${Utils.quoteCmdArgs(cmd)}""") mwhile(!recvOutputs) {} isRunning = true } @@ -417,7 +417,7 @@ private[chiseltest] class IPCSimulatorContext( private object TesterProcess { def apply(cmd: Seq[String], logs: ArrayBuffer[String], verbose: Boolean): Process = { require(new java.io.File(cmd.head).exists, s"${cmd.head} doesn't exist") - val processBuilder = Process(cmd.mkString(" ")) + val processBuilder = Process(Utils.quoteCmdArgs(cmd)) // This makes everything written to stderr get added as lines to logs val processLogger = ProcessLogger( { str => if (verbose) println(str) },