compiler.py: deal with temporarily broken compiler (#48418)

When a compiler is temporarily broken, we cache `c_compiler_output:`
`null`. This commit ensures we retry to obtain the `c_compiler_output`.
This commit is contained in:
Harmen Stoppels 2025-01-07 09:56:05 +01:00 committed by GitHub
parent 3b21ff109f
commit ca8ea63796
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -749,12 +749,18 @@ def __init__(self, compiler, feature, flag_name, ver_string=None):
class CompilerCacheEntry:
"""Deserialized cache entry for a compiler"""
__slots__ = ["c_compiler_output", "real_version"]
__slots__ = ("c_compiler_output", "real_version")
def __init__(self, c_compiler_output: Optional[str], real_version: str):
self.c_compiler_output = c_compiler_output
self.real_version = real_version
@property
def empty(self) -> bool:
"""Sometimes the compiler is temporarily broken, preventing us from getting output. The
call site determines if that is a problem."""
return self.c_compiler_output is None
@classmethod
def from_dict(cls, data: Dict[str, Optional[str]]):
if not isinstance(data, dict):
@ -792,9 +798,10 @@ def __init__(self, cache: "FileCache") -> None:
self.cache.init_entry(self.name)
self._data: Dict[str, Dict[str, Optional[str]]] = {}
def _get_entry(self, key: str) -> Optional[CompilerCacheEntry]:
def _get_entry(self, key: str, *, allow_empty: bool) -> Optional[CompilerCacheEntry]:
try:
return CompilerCacheEntry.from_dict(self._data[key])
entry = CompilerCacheEntry.from_dict(self._data[key])
return entry if allow_empty or not entry.empty else None
except ValueError:
del self._data[key]
except KeyError:
@ -812,7 +819,7 @@ def get(self, compiler: Compiler) -> CompilerCacheEntry:
self._data = {}
key = self._key(compiler)
value = self._get_entry(key)
value = self._get_entry(key, allow_empty=False)
if value is not None:
return value
@ -826,7 +833,7 @@ def get(self, compiler: Compiler) -> CompilerCacheEntry:
self._data = {}
# Use cache entry that may have been created by another process in the meantime.
entry = self._get_entry(key)
entry = self._get_entry(key, allow_empty=True)
# Finally compute the cache entry
if entry is None: