From f4b6cc6628f88af6489f388cd854829f91c9444f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 7 Oct 2021 13:43:12 +0530 Subject: [PATCH] Forgot the key the is_gcc cache by cc --- setup.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 5427844fc..13202a5a0 100755 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ import sysconfig import tempfile import time from contextlib import suppress -from functools import partial +from functools import lru_cache, partial from pathlib import Path from typing import ( Callable, Dict, Iterable, Iterator, List, NamedTuple, Optional, Sequence, @@ -290,11 +290,14 @@ int main(void) { return '' -def is_gcc(cc: List[str]) -> bool: - if not hasattr(is_gcc, 'ans'): - raw = subprocess.check_output(cc + ['--version']).decode('utf-8').splitlines()[0] - setattr(is_gcc, 'ans', '(GCC)' in raw.split()) - return bool(getattr(is_gcc, 'ans')) +def is_gcc(cc: Iterable[str]) -> bool: + + @lru_cache + def f(cc: Tuple[str]) -> bool: + raw = subprocess.check_output(cc + ('--version',)).decode('utf-8').splitlines()[0] + return '(GCC)' in raw.split() + + return f(tuple(cc)) def init_env(