diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2020-02-09 18:49:03 +0000 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2020-02-12 13:33:07 +0000 |
commit | 1464ac6ed54cad795444d240d3bdb83568f5601f (patch) | |
tree | cfa6c7e19bcc4973d13b1a29f8211ee8f73828ec | |
parent | 021fd9a1d0535453a515f44aa4f15af9553eed40 (diff) | |
download | meson-1464ac6ed54cad795444d240d3bdb83568f5601f.zip meson-1464ac6ed54cad795444d240d3bdb83568f5601f.tar.gz meson-1464ac6ed54cad795444d240d3bdb83568f5601f.tar.bz2 |
Improve error reported when language has no compiler
This gives consistent reporting of this error for all platforms.
Also, reporting this error when constructing the BuildTarget, rather
than discovering the problem during backend generation means that the
error is reported against with a location.
-rw-r--r-- | mesonbuild/build.py | 16 | ||||
-rw-r--r-- | mesonbuild/compilers/__init__.py | 2 | ||||
-rw-r--r-- | mesonbuild/compilers/compilers.py | 9 |
3 files changed, 24 insertions, 3 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 0a8ca45..7637885 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -28,7 +28,7 @@ from .mesonlib import ( extract_as_list, typeslistify, stringlistify, classify_unity_sources, get_filenames_templates_dict, substitute_values, has_path_sep, ) -from .compilers import Compiler, is_object, clink_langs, sort_clink, lang_suffixes +from .compilers import Compiler, is_object, clink_langs, sort_clink, lang_suffixes, is_known_suffix from .linkers import StaticLinker from .interpreterbase import FeatureNew @@ -652,14 +652,24 @@ class BuildTarget(Target): sources.append(s) if sources: # For each source, try to add one compiler that can compile it. - # It's ok if no compilers can do so, because users are expected to - # be able to add arbitrary non-source files to the sources list. + # + # If it has a suffix that belongs to a known language, we must have + # a compiler for that language. + # + # Otherwise, it's ok if no compilers can compile it, because users + # are expected to be able to add arbitrary non-source files to the + # sources list for s in sources: for lang, compiler in compilers.items(): if compiler.can_compile(s): if lang not in self.compilers: self.compilers[lang] = compiler break + else: + if is_known_suffix(s): + raise MesonException('No {} machine compiler for "{}"'. + format(self.for_machine.get_lower_case_name(), s)) + # Re-sort according to clink_langs self.compilers = OrderedDict(sorted(self.compilers.items(), key=lambda t: sort_clink(t[0]))) diff --git a/mesonbuild/compilers/__init__.py b/mesonbuild/compilers/__init__.py index b378a63..a4e3943 100644 --- a/mesonbuild/compilers/__init__.py +++ b/mesonbuild/compilers/__init__.py @@ -30,6 +30,7 @@ __all__ = [ 'is_llvm_ir', 'is_object', 'is_source', + 'is_known_suffix', 'lang_suffixes', 'sort_clink', @@ -115,6 +116,7 @@ from .compilers import ( is_llvm_ir, is_object, is_library, + is_known_suffix, lang_suffixes, sort_clink, CompilerArgs, diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index e8e72cf..0df6aea 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -14,6 +14,7 @@ import contextlib, os.path, re, tempfile import collections.abc +import itertools import typing as T from ..linkers import StaticLinker, GnuLikeDynamicLinkerMixin, SolarisDynamicLinker @@ -72,6 +73,7 @@ clink_suffixes = () 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)) # Languages that should use LDFLAGS arguments when linking. languages_using_ldflags = ('objcpp', 'cpp', 'objc', 'c', 'fortran', 'd', 'cuda') @@ -144,6 +146,13 @@ def is_library(fname): suffix = fname.split('.')[-1] return suffix in lib_suffixes +def is_known_suffix(fname): + if hasattr(fname, 'fname'): + fname = fname.fname + suffix = fname.split('.')[-1] + + return suffix in all_suffixes + cuda_buildtype_args = {'plain': [], 'debug': [], 'debugoptimized': [], |