diff options
| author | Jim Lawson | 2018-05-15 16:34:21 -0700 |
|---|---|---|
| committer | Jack Koenig | 2018-05-15 16:34:21 -0700 |
| commit | bc3927c82ed8593ad250514238bae7c09d286bdb (patch) | |
| tree | 1b53aa5738c429f3271c8d8311d1f568bcdcb0fc | |
| parent | 84b5fc1bc97e014bc03056a3f752c40ec6100701 (diff) | |
Don't use bash to determine command availability - fixes #807 (#808)
| -rw-r--r-- | src/main/scala/firrtl/Driver.scala | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/main/scala/firrtl/Driver.scala b/src/main/scala/firrtl/Driver.scala index 7d8686ba..10489da4 100644 --- a/src/main/scala/firrtl/Driver.scala +++ b/src/main/scala/firrtl/Driver.scala @@ -339,19 +339,36 @@ object FileUtils { } } - /** Indicate if an external command (executable) is available. + /** Indicate if an external command (executable) is available (from the current PATH). * - * @param cmd the command/executable - * @return true if ```cmd``` is found in PATH. + * @param cmd the command/executable plus any arguments to the command as a Seq(). + * @return true if ```cmd <args>``` returns a 0 exit status. */ - def isCommandAvailable(cmd: String): Boolean = { + def isCommandAvailable(cmd: Seq[String]): Boolean = { // Eat any output. val sb = new StringBuffer val ioToDevNull = BasicIO(withIn = false, sb, None) - Seq("bash", "-c", "which %s".format(cmd)).run(ioToDevNull).exitValue == 0 + try { + cmd.run(ioToDevNull).exitValue == 0 + } catch { + case e: Throwable => false + } + } + + /** Indicate if an external command (executable) is available (from the current PATH). + * + * @param cmd the command/executable (without any arguments). + * @return true if ```cmd``` returns a 0 exit status. + */ + def isCommandAvailable(cmd:String): Boolean = { + isCommandAvailable(Seq(cmd)) } - /** Flag indicating if vcs is available (for Verilog compilation and testing). */ - lazy val isVCSAvailable: Boolean = isCommandAvailable("vcs") + /** Flag indicating if vcs is available (for Verilog compilation and testing). + * We used to use a bash command (`which ...`) to determine this, but this is problematic on Windows (issue #807). + * Instead we try to run the executable itself (with innocuous arguments) and interpret any errors/exceptions + * as an indication that the executable is unavailable. + */ + lazy val isVCSAvailable: Boolean = isCommandAvailable(Seq("vcs", "-platform")) } |
