]> git.tdb.fi Git - libs/gl.git/blobdiff - scripts/extgen.py
Be smarter about detecting backport extensions
[libs/gl.git] / scripts / extgen.py
index ec57e2efb912fd9287185d7d5f0ab5bd9aa8609c..7083e13a1e6dcfc8ad00a3179bcd13cbe7f12bdb 100755 (executable)
@@ -31,6 +31,7 @@ if sys.argv[i].startswith("gl"):
        i += 1
 
 target_ext = sys.argv[i]
+backport_ext = None
 out_base = None
 if target_ext.endswith(".glext"):
        fn = target_ext
@@ -46,6 +47,8 @@ if target_ext.endswith(".glext"):
                                core_version = parts[2]
                elif parts[0]=="secondary":
                        secondary.append(parts[1])
+               elif parts[0]=="backport":
+                       backport_ext = parts[1]
        if i+1<len(sys.argv):
                out_base = os.path.splitext(sys.argv[i+1])[0]
 else:
@@ -55,7 +58,6 @@ else:
                core_version = secondary.pop(0)
 
 ext_type = target_ext.split('_')[0]
-backport_ext = None
 
 if core_version:
        core_version = map(int, core_version.split('.'))
@@ -95,7 +97,9 @@ class Extension:
        def __init__(self, name):
                self.name = name
                self.supported_apis = []
-               self.ext_type = name[0:name.find('_')]
+               underscore = name.find('_')
+               self.ext_type = name[0:underscore]
+               self.base_name = name[underscore+1:]
 
 extensions = {}
 things = {}
@@ -315,6 +319,7 @@ enums = filter(is_relevant, enums)
 enums.sort(key=(lambda e: e.value))
 
 # Some final preparations for creating the files
+backport_ext_candidates = []
 for t in itertools.chain(funcs, enums):
        if target_api in t.supported_apis and t.supported_apis[target_api]!="ext":
                t.version = t.supported_apis[target_api]
@@ -323,7 +328,27 @@ for t in itertools.chain(funcs, enums):
 
        # Things in backport extensions don't acquire an extension suffix
        if t.extension and not t.name.endswith(ext_type) and target_api in t.supported_apis:
-               backport_ext = t.extension
+               if t.extension not in backport_ext_candidates:
+                       backport_ext_candidates.append(t.extension)
+
+if backport_ext:
+       if backport_ext=="none":
+               backport_ext = None
+       else:
+               backport_ext = extensions[backport_ext]
+
+               if backport_ext not in backport_ext_candidates:
+                       print "Warning: explicitly specified backport extension %s does not look like a backport extension"
+elif backport_ext_candidates:
+       if len(backport_ext_candidates)>1:
+               print "Warning: multiple backport extension candidates: %s"%(" ".join(e.name for e in backport_ext_candidates))
+
+       for e in backport_ext_candidates:
+               if e.base_name==target_ext.base_name:
+                       backport_ext = e
+
+       if not backport_ext and len(backport_ext_candidates)==1:
+               print "Warning: potential backport extension has mismatched name: %s"%backport_ext_candidates[0].name
 
 for f in funcs:
        f.typedef = "FPtr_%s"%f.name