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) } }