diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2022-09-11 18:35:02 -0400 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2022-09-19 15:18:59 -0400 |
commit | 0a9048e5546c17a926fd199ded798fba0f76b036 (patch) | |
tree | 0d6eb84d073fc271e39e178c49ef3b4afc922746 /mesonbuild/backend/ninjabackend.py | |
parent | 24ac3cdb9c403fa43553cece086666f48ece1b95 (diff) | |
download | meson-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/backend/ninjabackend.py')
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 28 |
1 files changed, 12 insertions, 16 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'): |