Build broken on old-ish Python versions
While attempting to build Mesa main (9df68c63) on a Ubuntu 20.04 system with Python 3.8.10, I get the following error:
[100/1883] Generating src/vulkan/runtime/vk_physical_device_features with a custom command
FAILED: src/vulkan/runtime/vk_physical_device_features.c src/vulkan/runtime/vk_physical_device_features.h
/usr/bin/python3 ../../../../devel/jh-source/mesa/src/vulkan/util/vk_physical_device_features.py --xml ../../../../devel/jh-source/mesa/src/vulkan/registry/vk.xml --out-c src/vulkan/runtime/vk_physical_device_features.c --out-h src/vulkan/runtime/vk_physical_device_features.h
Traceback (most recent call last):
File "../../../../devel/jh-source/mesa/src/vulkan/util/vk_physical_device_features.py", line 116, in <module>
class FeatureStruct(typing.NamedTuple):
File "../../../../devel/jh-source/mesa/src/vulkan/util/vk_physical_device_features.py", line 119, in FeatureStruct
features: list[str]
TypeError: 'type' object is not subscriptable
The problem appears to have been introduced by cd35ab95. We should raise the Python 3 version requirement to 3.9 to make the code legal or modify the affected code. When attemping to fix that issue I found out the script is also using the string removeprefix() method which, again, is new to Python 3.9.
If the Python 3 version requirement is not raised to Python 3.9, the following patch appears to fix the build for me and works under both Python 3.8 and Python 3.11. NB: not a Python expert here.
diff --git a/src/vulkan/util/vk_physical_device_features.py b/src/vulkan/util/vk_physical_device_features.py
index 333540236e0..54eb28b6347 100644
--- a/src/vulkan/util/vk_physical_device_features.py
+++ b/src/vulkan/util/vk_physical_device_features.py
@@ -24,6 +24,7 @@ COPYRIGHT=u"""
import argparse
from collections import OrderedDict
+from dataclasses import dataclass
import os
import sys
import typing
@@ -110,13 +111,19 @@ for (feature_structs, features) in KNOWN_ALIASES:
assert rename not in RENAMED_FEATURES, f"{rename} already exists in RENAMED_FEATURES"
RENAMED_FEATURES[rename] = flag
+def remove_prefix(a_str, prefix):
+ if a_str.startswith(prefix):
+ return a_str[len(prefix):]
+ return a_str
+
def get_renamed_feature(c_type, feature):
- return RENAMED_FEATURES.get((c_type.removeprefix('VkPhysicalDevice'), feature), feature)
+ return RENAMED_FEATURES.get((remove_prefix(c_type, 'VkPhysicalDevice'), feature), feature)
-class FeatureStruct(typing.NamedTuple):
+@dataclass
+class FeatureStruct:
c_type: str
s_type: str
- features: list[str]
+ features: typing.List[str]
TEMPLATE_C = Template(COPYRIGHT + """
/* This file generated from ${filename}, don't edit directly. */
@@ -407,12 +414,12 @@ def get_feature_structs_from_xml(xml_files, api='vulkan'):
if renamed_flag not in features:
features[renamed_flag] = f.c_type
else:
- a = features[renamed_flag].removeprefix('VkPhysicalDevice')
- b = f.c_type.removeprefix('VkPhysicalDevice')
+ a = remove_prefix(features[renamed_flag], 'VkPhysicalDevice')
+ b = remove_prefix(f.c_type, 'VkPhysicalDevice')
if (a, flag) not in RENAMED_FEATURES or (b, flag) not in RENAMED_FEATURES:
diagnostics.append(f'{a} and {b} both define {flag}')
- unused_renames.pop((f.c_type.removeprefix('VkPhysicalDevice'), flag), None)
+ unused_renames.pop((remove_prefix(f.c_type, 'VkPhysicalDevice'), flag), None)
for rename in unused_renames:
diagnostics.append(f'unused rename {rename}')