diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2020-03-09 01:20:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-09 01:20:57 +0200 |
commit | 5c51d4521ab37edce88c61fd5067c93a44078854 (patch) | |
tree | 51910cba73b3017087fc13b6bdb64afd3bd4e09e /mesonbuild | |
parent | 3a57e5177ba949cff5f971f7338a1c75a2724ac2 (diff) | |
parent | 48e5c1234ad4dd0438324ab8164f94d12a8c2218 (diff) | |
download | meson-5c51d4521ab37edce88c61fd5067c93a44078854.zip meson-5c51d4521ab37edce88c61fd5067c93a44078854.tar.gz meson-5c51d4521ab37edce88c61fd5067c93a44078854.tar.bz2 |
Merge pull request #6532 from jon-turney/languages-native-kwarg
Add add_languages(native:)
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/build.py | 16 | ||||
-rw-r--r-- | mesonbuild/compilers/__init__.py | 2 | ||||
-rw-r--r-- | mesonbuild/compilers/compilers.py | 9 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 21 |
4 files changed, 39 insertions, 9 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 6755dca..61894fe 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, unholder ) -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 @@ -651,14 +651,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 caa8600..366bb50 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 functools import lru_cache @@ -75,6 +76,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') @@ -147,6 +149,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': [], diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index e8284bb..af6eda3 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2119,7 +2119,7 @@ _base_test_args = {'args', 'depends', 'env', 'should_fail', 'timeout', 'workdir' permitted_kwargs = {'add_global_arguments': {'language', 'native'}, 'add_global_link_arguments': {'language', 'native'}, - 'add_languages': {'required'}, + 'add_languages': {'required', 'native'}, 'add_project_link_arguments': {'language', 'native'}, 'add_project_arguments': {'language', 'native'}, 'add_test_setup': {'exe_wrapper', 'gdb', 'timeout_multiplier', 'env', 'is_default'}, @@ -2951,11 +2951,13 @@ external dependencies (including libraries) must go to "dependencies".''') self.build.projects[self.subproject] = proj_name mlog.log('Project name:', mlog.bold(proj_name)) mlog.log('Project version:', mlog.bold(self.project_version)) - self.add_languages(proj_langs, True) + self.add_languages(proj_langs, True, MachineChoice.BUILD) + self.add_languages(proj_langs, True, MachineChoice.HOST) self.set_backend() if not self.is_subproject(): self.check_stdlibs() + @FeatureNewKwargs('add_languages', '0.54.0', ['native']) @permittedKwargs(permitted_kwargs['add_languages']) @stringArgs def func_add_languages(self, node, args, kwargs): @@ -2964,7 +2966,15 @@ external dependencies (including libraries) must go to "dependencies".''') for lang in sorted(args, key=compilers.sort_clink): mlog.log('Compiler for language', mlog.bold(lang), 'skipped: feature', mlog.bold(feature), 'disabled') return False - return self.add_languages(args, required) + if 'native' in kwargs: + return self.add_languages(args, required, self.machine_from_native_kwarg(kwargs)) + else: + # absent 'native' means 'both' for backwards compatibility + mlog.warning('add_languages is missing native:, assuming languages are wanted for both host and build.', + location=self.current_node) + success = self.add_languages(args, False, MachineChoice.BUILD) + success &= self.add_languages(args, required, MachineChoice.HOST) + return success def get_message_string_arg(self, arg): if isinstance(arg, list): @@ -3060,9 +3070,8 @@ external dependencies (including libraries) must go to "dependencies".''') self.validate_arguments(args, 0, []) raise Exception() - def add_languages(self, args: T.Sequence[str], required: bool) -> bool: - success = self.add_languages_for(args, required, MachineChoice.BUILD) - success &= self.add_languages_for(args, required, MachineChoice.HOST) + def add_languages(self, args: T.Sequence[str], required: bool, for_machine: MachineChoice) -> bool: + success = self.add_languages_for(args, required, for_machine) if not self.coredata.is_cross_build(): self.coredata.copy_build_options_from_regular_ones() return success |