From 1b15176168d90c913153c0da598e130e9214b3ab Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Wed, 3 Jan 2024 23:29:19 -0500 Subject: [PATCH] cuda module: inline single-shot function to get compiler version It is pretty trivial and more confusing when standalone, especially the use of a sentinel "unknown" string as a standin for "this isn't one of the allowed object types". Much easier to directly raise an error in the fallthrough/else. --- mesonbuild/modules/cuda.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/mesonbuild/modules/cuda.py b/mesonbuild/modules/cuda.py index b062bbf38..b52288ab5 100644 --- a/mesonbuild/modules/cuda.py +++ b/mesonbuild/modules/cuda.py @@ -123,14 +123,6 @@ class CudaModule(NewExtensionModule): return [c.detected_cc] return [] - @staticmethod - def _version_from_compiler(c): - if isinstance(c, CudaCompiler): - return c.version - if isinstance(c, str): - return c - return 'unknown' - def _validate_nvcc_arch_args(self, args, kwargs: ArchFlagsKwargs): argerror = InvalidArguments('The first argument must be an NVCC compiler object, or its version string!') @@ -138,8 +130,11 @@ class CudaModule(NewExtensionModule): raise argerror else: compiler = args[0] - cuda_version = self._version_from_compiler(compiler) - if cuda_version == 'unknown': + if isinstance(compiler, CudaCompiler): + cuda_version = compiler.version + elif isinstance(compiler, str): + cuda_version = compiler + else: raise argerror arch_list = [] if len(args) <= 1 else flatten(args[1:])