aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-09-11 18:35:02 -0400
committerEli Schwartz <eschwartz@archlinux.org>2022-09-19 15:18:59 -0400
commit0a9048e5546c17a926fd199ded798fba0f76b036 (patch)
tree0d6eb84d073fc271e39e178c49ef3b4afc922746 /mesonbuild
parent24ac3cdb9c403fa43553cece086666f48ece1b95 (diff)
downloadmeson-0a9048e5546c17a926fd199ded798fba0f76b036.zip
meson-0a9048e5546c17a926fd199ded798fba0f76b036.tar.gz
meson-0a9048e5546c17a926fd199ded798fba0f76b036.tar.bz2
compilers: don't use instance checks to determine properties
In various situations we want to figure out what type of compiler we have, because we want to know stuff like "is it the pgi one", or "does it use msvc style". The compiler object has this property already, via an API specifically designed to communicate this info, but instead we performed isinstance checks on a compiler class. This is confusing and indirect, and has the side effect of requiring more imports everywhere. We should do away with it.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/backend/ninjabackend.py28
-rw-r--r--mesonbuild/cmake/toolchain.py3
-rw-r--r--mesonbuild/environment.py4
3 files changed, 15 insertions, 20 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 45c0e9d..89f3763 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -36,13 +36,8 @@ from .. import build
from .. import mlog
from .. import compilers
from ..arglist import CompilerArgs
-from ..compilers import (
- Compiler, CCompiler,
- FortranCompiler,
- mixins,
- PGICCompiler,
- VisualStudioLikeCompiler,
-)
+from ..compilers import Compiler
+from ..compilers.c import CCompiler
from ..linkers import ArLinker, AppleArLinker, RSPFileSyntax
from ..mesonlib import (
File, LibType, MachineChoice, MesonException, OrderedSet, PerMachine,
@@ -60,6 +55,7 @@ if T.TYPE_CHECKING:
from ..interpreter import Interpreter
from ..linkers import DynamicLinker, StaticLinker
from ..compilers.cs import CsCompiler
+ from ..compilers.fortran import FortranCompiler
RUST_EDITIONS = Literal['2015', '2018', '2021']
@@ -516,12 +512,12 @@ class NinjaBackend(backends.Backend):
# Have to detect the dependency format
# IFort on windows is MSVC like, but doesn't have /showincludes
- if isinstance(compiler, FortranCompiler):
+ if compiler.language == 'fortran':
continue
- if isinstance(compiler, PGICCompiler) and mesonlib.is_windows():
+ if compiler.id == 'pgi' and mesonlib.is_windows():
# for the purpose of this function, PGI doesn't act enough like MSVC
return open(tempfilename, 'a', encoding='utf-8')
- if isinstance(compiler, VisualStudioLikeCompiler):
+ if compiler.get_argument_syntax() == 'msvc':
break
else:
# None of our compilers are MSVC, we're done.
@@ -2325,7 +2321,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
command = compiler.get_exelist()
args = ['$ARGS'] + depargs + NinjaCommandArg.list(compiler.get_output_args('$out'), Quoting.none) + compiler.get_compile_only_args() + ['$in']
description = f'Compiling {compiler.get_display_language()} object $out'
- if isinstance(compiler, VisualStudioLikeCompiler):
+ if compiler.get_argument_syntax() == 'msvc':
deps = 'msvc'
depfile = None
else:
@@ -2341,13 +2337,13 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
rule = self.compiler_to_pch_rule_name(compiler)
depargs = compiler.get_dependency_gen_args('$out', '$DEPFILE')
- if isinstance(compiler, VisualStudioLikeCompiler):
+ if compiler.get_argument_syntax() == 'msvc':
output = []
else:
output = NinjaCommandArg.list(compiler.get_output_args('$out'), Quoting.none)
command = compiler.get_exelist() + ['$ARGS'] + depargs + output + compiler.get_compile_only_args() + ['$in']
description = 'Precompiling header $in'
- if isinstance(compiler, VisualStudioLikeCompiler):
+ if compiler.get_argument_syntax() == 'msvc':
deps = 'msvc'
depfile = None
else:
@@ -2931,8 +2927,8 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
msg = f'Precompiled header of {target.get_basename()!r} must not be in the same ' \
'directory as source, please put it in a subdirectory.'
raise InvalidArguments(msg)
- compiler = target.compilers[lang]
- if isinstance(compiler, VisualStudioLikeCompiler):
+ compiler: Compiler = target.compilers[lang]
+ if compiler.get_argument_syntax() == 'msvc':
(commands, dep, dst, objs, src) = self.generate_msvc_pch_command(target, compiler, pch)
extradep = os.path.join(self.build_to_src, target.get_source_subdir(), pch[0])
elif compiler.id == 'intel':
@@ -3026,7 +3022,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
def get_link_whole_args(self, linker, target):
use_custom = False
- if isinstance(linker, mixins.visualstudio.MSVCCompiler):
+ if linker.id == 'msvc':
# Expand our object lists manually if we are on pre-Visual Studio 2015 Update 2
# (incidentally, the "linker" here actually refers to cl.exe)
if mesonlib.version_compare(linker.version, '<19.00.23918'):
diff --git a/mesonbuild/cmake/toolchain.py b/mesonbuild/cmake/toolchain.py
index c854828..477629e 100644
--- a/mesonbuild/cmake/toolchain.py
+++ b/mesonbuild/cmake/toolchain.py
@@ -16,7 +16,6 @@ from __future__ import annotations
from pathlib import Path
from .traceparser import CMakeTraceParser
from ..envconfig import CMakeSkipCompilerTest
-from ..compilers import VisualStudioLikeCompiler
from .common import language_map, cmake_get_generator_args
from .. import mlog
@@ -204,7 +203,7 @@ class CMakeToolchain:
@staticmethod
def is_cmdline_option(compiler: 'Compiler', arg: str) -> bool:
- if isinstance(compiler, VisualStudioLikeCompiler):
+ if compiler.get_argument_syntax() == 'msvc':
return arg.startswith('/')
else:
return arg.startswith('-')
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 6ac7604..394b080 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -845,10 +845,10 @@ class Environment:
def get_compiler_system_dirs(self, for_machine: MachineChoice):
for comp in self.coredata.compilers[for_machine].values():
- if isinstance(comp, compilers.ClangCompiler):
+ if comp.id == 'clang':
index = 1
break
- elif isinstance(comp, compilers.GnuCompiler):
+ elif comp.id == 'gcc':
index = 2
break
else: