freedreno: make gen_header.py check parent directory
authorRob Clark <robdclark@chromium.org>
Thu, 23 Jul 2020 22:28:47 +0000 (15:28 -0700)
committerMarge Bot <eric+marge@anholt.net>
Tue, 28 Jul 2020 09:45:08 +0000 (09:45 +0000)
With the next commit, the xml files will be no longer be all in the same
directory.  But checking up a single directory level to resolve import
will be sufficient.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6070>

src/freedreno/registers/gen_header.py

index b8fa8cc0caa1ea3482bd72482af9f21b473effff..291f7e9d2999338b0a4ffd25e62b497cd288a4dc 100644 (file)
@@ -332,7 +332,14 @@ class Parser(object):
                        raise self.error(e);
 
        def do_parse(self, filename):
-               file = open(filename, "rb")
+               try:
+                       file = open(filename, "rb")
+               except FileNotFoundError as e:
+                       # Look for the file in the parent directory if not
+                       # found in same directory:
+                       path = os.path.dirname(filename)
+                       base = os.path.basename(filename)
+                       file = open(path + "/../" + base, "rb")
                parser = xml.parsers.expat.ParserCreate()
                self.stack.append((parser, filename))
                parser.StartElementHandler = self.start_element