diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2019-04-30 10:53:39 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2019-05-03 10:36:50 -0700 |
commit | 541523eebab8f62b182643296deab26a47117f6f (patch) | |
tree | b5db369f05d6407125c9eee947adb96221844ab7 /mesonbuild/backend | |
parent | 604b2534e8516e5ddade6d2d2514b3078275d711 (diff) | |
download | meson-541523eebab8f62b182643296deab26a47117f6f.zip meson-541523eebab8f62b182643296deab26a47117f6f.tar.gz meson-541523eebab8f62b182643296deab26a47117f6f.tar.bz2 |
compilers: Split C-Like functionality into a mixin classes
Currently C++ inherits C, which can lead to diamond problems. By pulling
the code out into a standalone mixin class that the C, C++, ObjC, and
Objc++ compilers can inherit and override as necessary we remove one
source of diamonding. I've chosen to split this out into it's own file
as the CLikeCompiler class is over 1000 lines by itself. This also
breaks the VisualStudio derived classes inheriting from each other, to
avoid the same C -> CPP inheritance problems. This is all one giant
patch because there just isn't a clean way to separate this.
I've done the same for Fortran since it effectively inherits the
CCompiler (I say effectively because was it actually did was gross
beyond explanation), it's probably not correct, but it seems to work for
now. There really is a lot of layering violation going on in the
Compilers, and a really good scrubbing would do this code a lot of good.
Diffstat (limited to 'mesonbuild/backend')
-rw-r--r-- | mesonbuild/backend/backends.py | 4 | ||||
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 14 |
2 files changed, 9 insertions, 9 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index d0b4bb5..0565de3 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -23,7 +23,7 @@ import subprocess from ..mesonlib import MachineChoice, MesonException, OrderedSet from ..mesonlib import classify_unity_sources from ..mesonlib import File -from ..compilers import CompilerArgs, VisualStudioCCompiler +from ..compilers import CompilerArgs, VisualStudioLikeCompiler from collections import OrderedDict import shlex from functools import lru_cache @@ -551,7 +551,7 @@ class Backend: return args extra_args = [] # Compiler-specific escaping is needed for -D args but not for any others - if isinstance(compiler, VisualStudioCCompiler): + if isinstance(compiler, VisualStudioLikeCompiler): # MSVC needs escaping when a -D argument ends in \ or \" for arg in args: if arg.startswith('-D') or arg.startswith('/D'): diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 7eafcad..e0a6440 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -29,7 +29,7 @@ from .. import build from .. import mlog from .. import dependencies from .. import compilers -from ..compilers import CompilerArgs, CCompiler, VisualStudioCCompiler, FortranCompiler +from ..compilers import CompilerArgs, CCompiler, VisualStudioLikeCompiler, FortranCompiler from ..linkers import ArLinker from ..mesonlib import File, MachineChoice, MesonException, OrderedSet, LibType from ..mesonlib import get_compiler_for_source, has_path_sep @@ -221,7 +221,7 @@ class NinjaBackend(backends.Backend): Detect the search prefix to use.''' for compiler in self.build.compilers.values(): # Have to detect the dependency format - if isinstance(compiler, VisualStudioCCompiler): + if isinstance(compiler, VisualStudioLikeCompiler): break else: # None of our compilers are MSVC, we're done. @@ -1673,7 +1673,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) command = [ninja_quote(i) for i in compiler.get_exelist()] args = ['$ARGS'] + quoted_depargs + compiler.get_output_args('$out') + compiler.get_compile_only_args() + ['$in'] description = 'Compiling %s object $out.' % compiler.get_display_language() - if isinstance(compiler, VisualStudioCCompiler): + if isinstance(compiler, VisualStudioLikeCompiler): deps = 'msvc' depfile = None else: @@ -1698,13 +1698,13 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) if d != '$out' and d != '$in': d = quote_func(d) quoted_depargs.append(d) - if isinstance(compiler, VisualStudioCCompiler): + if isinstance(compiler, VisualStudioLikeCompiler): output = [] else: output = compiler.get_output_args('$out') command = compiler.get_exelist() + ['$ARGS'] + quoted_depargs + output + compiler.get_compile_only_args() + ['$in'] description = 'Precompiling header $in.' - if isinstance(compiler, VisualStudioCCompiler): + if isinstance(compiler, VisualStudioLikeCompiler): deps = 'msvc' depfile = None else: @@ -1886,7 +1886,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) return compiler.get_no_stdinc_args() def get_compile_debugfile_args(self, compiler, target, objfile): - if not isinstance(compiler, VisualStudioCCompiler): + if not isinstance(compiler, VisualStudioLikeCompiler): return [] # The way MSVC uses PDB files is documented exactly nowhere so # the following is what we have been able to decipher via @@ -2275,7 +2275,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) ''.format(target.get_basename()) raise InvalidArguments(msg) compiler = target.compilers[lang] - if isinstance(compiler, VisualStudioCCompiler): + if isinstance(compiler, VisualStudioLikeCompiler): (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': |