build/generic_plaform: add loose parameter to return None when not available/existing.
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 6 Aug 2020 17:32:02 +0000 (19:32 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 6 Aug 2020 17:33:04 +0000 (19:33 +0200)
Similar to loose parameter already present on Platform.lookup_request.

litex/build/generic_platform.py

index 2fdda7184e2b636a9cea91711fc752dd4581a19f..21608831be539e04308bc7d77ee83299c016a83a 100644 (file)
@@ -82,11 +82,14 @@ class PlatformInfo:
         return "{}({})".format(self.__class__.__name__, repr(self.info))
 
 
-def _lookup(description, name, number):
+def _lookup(description, name, number, loose=True):
     for resource in description:
         if resource[0] == name and (number is None or resource[1] == number):
             return resource
-    raise ConstraintError("Resource not found: {}:{}".format(name, number))
+    if loose:
+        return None
+    else:
+        raise ConstraintError("Resource not found: {}:{}".format(name, number))
 
 
 def _resource_type(resource):
@@ -178,8 +181,10 @@ class ConstraintManager:
     def add_extension(self, io):
         self.available.extend(io)
 
-    def request(self, name, number=None):
-        resource = _lookup(self.available, name, number)
+    def request(self, name, number=None, loose=False):
+        resource = _lookup(self.available, name, number, loose)
+        if resource is None:
+            return None
         rt, ri = _resource_type(resource)
         if number is None:
             resource_name = name