From 827bc932e3079082192d9baf59e44f640f74e5ef Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Fri, 16 Feb 2024 13:42:10 -0800 Subject: [PATCH] [svsim] Better error message when verilator not on PATH --- svsim/src/main/scala/verilator/Backend.scala | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/svsim/src/main/scala/verilator/Backend.scala b/svsim/src/main/scala/verilator/Backend.scala index 91729debd84..de6c843835d 100644 --- a/svsim/src/main/scala/verilator/Backend.scala +++ b/svsim/src/main/scala/verilator/Backend.scala @@ -3,7 +3,8 @@ package svsim.verilator import svsim._ -import java.io.{BufferedReader, InputStreamReader} +import scala.sys.process._ +import scala.collection.mutable object Backend { object CompilationSettings { @@ -22,10 +23,12 @@ object Backend { enableAllAssertions: Boolean = false) def initializeFromProcessEnvironment() = { - val process = Runtime.getRuntime().exec(Array("which", "verilator")) - val outputReader = new BufferedReader(new InputStreamReader(process.getInputStream())) - val executablePath = outputReader.lines().findFirst().get() - process.waitFor() + val output = mutable.ArrayBuffer.empty[String] + val exitCode = List("which", "verilator").!(ProcessLogger(output += _)) + if (exitCode != 0) { + throw new Exception(s"verilator not found on the PATH!\n${output.mkString("\n")}") + } + val executablePath = output.head.trim new Backend(executablePath = executablePath) } }