back.verilog: better error message if Yosys is not found.
authorwhitequark <cz@m-labs.hk>
Sun, 13 Jan 2019 08:10:23 +0000 (08:10 +0000)
committerwhitequark <cz@m-labs.hk>
Sun, 13 Jan 2019 08:10:23 +0000 (08:10 +0000)
Fixes #17.

nmigen/back/verilog.py

index 0b86fe3f1818c1b45b8647b2245b086a8e2cbbc4..0f5b9be5372b0e012ff2e7449ced99ddd7b945c0 100644 (file)
@@ -12,12 +12,21 @@ class YosysError(Exception):
 
 
 def convert(*args, **kwargs):
+    try:
+        popen = subprocess.Popen([os.getenv("YOSYS", "yosys"), "-q", "-"],
+            stdin=subprocess.PIPE,
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE,
+            encoding="utf-8")
+    except FileNotFoundError as e:
+        if os.getenv("YOSYS"):
+            raise YosysError("Could not find Yosys in {} as specified via the YOSYS environment "
+                             "variable".format(os.getenv("YOSYS"))) from e
+        else:
+            raise YosysError("Could not find Yosys in PATH. Place `yosys` in PATH or specify "
+                             "path explicitly via the YOSYS environment variable") from e
+
     il_text = rtlil.convert(*args, **kwargs)
-    popen = subprocess.Popen([os.getenv("YOSYS", "yosys"), "-q", "-"],
-        stdin=subprocess.PIPE,
-        stdout=subprocess.PIPE,
-        stderr=subprocess.PIPE,
-        encoding="utf-8")
     verilog_text, error = popen.communicate("""
 # Convert nMigen's RTLIL to readable Verilog.
 read_ilang <<rtlil