diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2022-03-17 10:40:49 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2022-09-27 11:15:07 -0400 |
commit | e1db50d4d9839cb29f73d7f4118f80262a2b47f3 (patch) | |
tree | 3d1cb7180c3883f9c4f67503a6e8831bc9f4a6de | |
parent | 838367ca6040cef527955daf450639189b8cc931 (diff) | |
download | meson-e1db50d4d9839cb29f73d7f4118f80262a2b47f3.zip meson-e1db50d4d9839cb29f73d7f4118f80262a2b47f3.tar.gz meson-e1db50d4d9839cb29f73d7f4118f80262a2b47f3.tar.bz2 |
compilers: Cleanup a bit languages/suffixes lists
Use set where order does not matter, fix is_source() to really mean only
source suffixes.
-rw-r--r-- | mesonbuild/backend/backends.py | 2 | ||||
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 2 | ||||
-rw-r--r-- | mesonbuild/backend/vs2010backend.py | 4 | ||||
-rw-r--r-- | mesonbuild/build.py | 2 | ||||
-rw-r--r-- | mesonbuild/compilers/compilers.py | 40 |
5 files changed, 27 insertions, 23 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 53e3530..28cd73e 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -839,7 +839,7 @@ class Backend: # Filter out headers and all non-source files sources: T.List['FileOrString'] = [] for s in raw_sources: - if self.environment.is_source(s) and not self.environment.is_header(s): + if self.environment.is_source(s): sources.append(s) elif self.environment.is_object(s): result.append(s.relative_name()) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index d8f2122..a64f283 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -882,7 +882,7 @@ class NinjaBackend(backends.Backend): generated_source_files = [] for rel_src in generated_sources.keys(): raw_src = File.from_built_relative(rel_src) - if self.environment.is_source(rel_src) and not self.environment.is_header(rel_src): + if self.environment.is_source(rel_src): if is_unity and self.get_target_source_can_unity(target, rel_src): unity_deps.append(raw_src) abs_src = os.path.join(self.environment.get_build_dir(), rel_src) diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index 6e72828..a2581e4 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -1246,14 +1246,14 @@ class Vs2010Backend(backends.Backend): # Unfortunately, we can't use self.object_filename_from_source() for gen in l.genlist: for src in gen.get_outputs(): - if self.environment.is_source(src) and not self.environment.is_header(src): + if self.environment.is_source(src): path = self.get_target_generated_dir(t, gen, src) gen_src_ext = '.' + os.path.splitext(path)[1][1:] extra_link_args.append(path[:-len(gen_src_ext)] + '.obj') for src in l.srclist: obj_basename = None - if self.environment.is_source(src) and not self.environment.is_header(src): + if self.environment.is_source(src): obj_basename = self.object_filename_from_source(t, src) target_private_dir = self.relpath(self.get_target_private_dir(t), self.get_target_dir(t)) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index dd5ea3c..eb72add 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -430,7 +430,7 @@ class ExtractedObjects(HoldableObject): sources.append(s) # Filter out headers and all non-source files - return [s for s in sources if environment.is_source(s) and not environment.is_header(s)] + return [s for s in sources if environment.is_source(s)] def classify_all_sources(self, sources: T.List[FileOrString], generated_sources: T.Sequence['GeneratedTypes']) -> T.Dict['Compiler', T.List['FileOrString']]: sources_ = self.get_sources(sources, generated_sources) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index d2ac7c6..725d394 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -47,12 +47,13 @@ if T.TYPE_CHECKING: about. To support a new compiler, add its information below. Also add corresponding autodetection code in environment.py.""" -header_suffixes = ('h', 'hh', 'hpp', 'hxx', 'H', 'ipp', 'moc', 'vapi', 'di') # type: T.Tuple[str, ...] -obj_suffixes = ('o', 'obj', 'res') # type: T.Tuple[str, ...] +header_suffixes = {'h', 'hh', 'hpp', 'hxx', 'H', 'ipp', 'moc', 'vapi', 'di'} +obj_suffixes = {'o', 'obj', 'res'} # To the emscripten compiler, .js files are libraries -lib_suffixes = ('a', 'lib', 'dll', 'dll.a', 'dylib', 'so', 'js') # type: T.Tuple[str, ...] +lib_suffixes = {'a', 'lib', 'dll', 'dll.a', 'dylib', 'so', 'js'} # Mapping of language to suffixes of files that should always be in that language # This means we can't include .h headers here since they could be C, C++, ObjC, etc. +# First suffix is the language's default. lang_suffixes = { 'c': ('c',), 'cpp': ('cpp', 'cc', 'cxx', 'c++', 'hh', 'hpp', 'ipp', 'hxx', 'ino', 'ixx', 'C'), @@ -69,23 +70,24 @@ lang_suffixes = { 'swift': ('swift',), 'java': ('java',), 'cython': ('pyx', ), -} # type: T.Dict[str, T.Tuple[str, ...]] +} all_languages = lang_suffixes.keys() -cpp_suffixes = lang_suffixes['cpp'] + ('h',) # type: T.Tuple[str, ...] -c_suffixes = lang_suffixes['c'] + ('h',) # type: T.Tuple[str, ...] +c_cpp_suffixes = {'h'} +cpp_suffixes = set(lang_suffixes['cpp']) | c_cpp_suffixes +c_suffixes = set(lang_suffixes['c']) | c_cpp_suffixes +assembler_suffixes = {'s', 'S'} +llvm_ir_suffixes = {'ll'} +all_suffixes = set(itertools.chain(*lang_suffixes.values(), assembler_suffixes, llvm_ir_suffixes, c_cpp_suffixes)) +source_suffixes = all_suffixes - header_suffixes # List of languages that by default consume and output libraries following the # C ABI; these can generally be used interchangeably -clib_langs = ('objcpp', 'cpp', 'objc', 'c', 'fortran',) # type: T.Tuple[str, ...] -# List of assembler suffixes that can be linked with C code directly by the linker -assembler_suffixes: T.Tuple[str, ...] = ('s', 'S') +# This must be sorted, see sort_clink(). +clib_langs = ('objcpp', 'cpp', 'objc', 'c', 'fortran') # List of languages that can be linked with C code directly by the linker # used in build.py:process_compilers() and build.py:get_dynamic_linker() -clink_langs = ('d', 'cuda') + clib_langs # type: T.Tuple[str, ...] -clink_suffixes = tuple() # type: T.Tuple[str, ...] -for _l in clink_langs + ('vala',): - clink_suffixes += lang_suffixes[_l] -clink_suffixes += ('h', 'll', 's') -all_suffixes = set(itertools.chain(*lang_suffixes.values(), clink_suffixes)) # type: T.Set[str] +# This must be sorted, see sort_clink(). +clink_langs = ('d', 'cuda') + clib_langs + SUFFIX_TO_LANG = dict(itertools.chain(*( [(suffix, lang) for suffix in v] for lang, v in lang_suffixes.items()))) # type: T.Dict[str, str] @@ -133,17 +135,19 @@ def is_source(fname: 'mesonlib.FileOrString') -> bool: if isinstance(fname, mesonlib.File): fname = fname.fname suffix = fname.split('.')[-1].lower() - return suffix in clink_suffixes + return suffix in source_suffixes def is_assembly(fname: 'mesonlib.FileOrString') -> bool: if isinstance(fname, mesonlib.File): fname = fname.fname - return fname.split('.')[-1].lower() == 's' + suffix = fname.split('.')[-1] + return suffix in assembler_suffixes def is_llvm_ir(fname: 'mesonlib.FileOrString') -> bool: if isinstance(fname, mesonlib.File): fname = fname.fname - return fname.split('.')[-1] == 'll' + suffix = fname.split('.')[-1] + return suffix in llvm_ir_suffixes @lru_cache(maxsize=None) def cached_by_name(fname: 'mesonlib.FileOrString') -> bool: |