Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

logging: quote arguments when there is a space in the arg when logging cmds #737

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions src/main/scala/chiseltest/simulator/IcarusSimulator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ 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" + Util.quoteCmdArgs(cmd)
)
lib
}
Expand Down Expand Up @@ -141,7 +141,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" + Util.quoteCmdArgs(cmd))
Seq("vvp", simBinary.toString())
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/scala/chiseltest/simulator/Util.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Utils {
def quoteCmdArgs(cmd: Seq[String]): String = {
cmd.map(arg => if (arg.contains(" ")) s""""$arg"""" else arg).mkString(" ")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,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(Util.quoteCmdArgs(cmd))
os.proc(cmd)
.call(cwd = cwd, stdout = os.ProcessOutput.Readlines(println), stderr = os.ProcessOutput.Readlines(println))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private[chiseltest] class IPCSimulatorContext(

private def start(): Unit = {
if (verbose)
println(s"""STARTING ${cmd.mkString(" ")}""")
println(s"""STARTING ${Util.quoteCmdArgs(cmd)}""")
mwhile(!recvOutputs) {}
isRunning = true
}
Expand Down Expand Up @@ -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(Util.quoteCmdArgs(cmd))
// This makes everything written to stderr get added as lines to logs
val processLogger = ProcessLogger(
{ str => if (verbose) println(str) },
Expand Down
Loading