From 303ea18cb60567e45a755c6b6289a601f27d46e6 Mon Sep 17 00:00:00 2001 From: Alan Green Date: Tue, 23 Jun 2020 22:12:02 +1000 Subject: [PATCH] _yosys: handle unparseable versions Do not use yosys binaries with unparseable version numbers. This ensures that nmigen always knows what version of yosys it is generating RTLIL for. The effect of this change is that if the version number of the system yosys is unparsable, nmigen will attempt to fallback to the builtin Yosys. Fixes #409. --- nmigen/_yosys.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/nmigen/_yosys.py b/nmigen/_yosys.py index 6071d04..c02c7c4 100644 --- a/nmigen/_yosys.py +++ b/nmigen/_yosys.py @@ -53,6 +53,8 @@ class YosysBinary: Returns ------- + ``None`` if version number could not be determined, or a 3-tuple ``(major, minor, distance)`` if it could. + major : int Major version. minor : int @@ -151,7 +153,10 @@ class _SystemYosys(YosysBinary): def version(cls): version = cls.run(["-V"]) match = re.match(r"^Yosys (\d+)\.(\d+)(?:\+(\d+))?", version) - return (int(match[1]), int(match[2]), int(match[3] or 0)) + if match: + return (int(match[1]), int(match[2]), int(match[3] or 0)) + else: + return None @classmethod def data_dir(cls): @@ -208,8 +213,10 @@ def find_yosys(requirement): "an unrecognized clause {!r}" .format(clause)) for proxy in proxies: - if proxy.available() and requirement(proxy.version()): - return proxy + if proxy.available(): + version = proxy.version() + if version is not None and requirement(version): + return proxy else: if "NMIGEN_USE_YOSYS" in os.environ: raise YosysError("Could not find an acceptable Yosys binary. Searched: {}" -- 2.30.2