diff options
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/build.py | 11 | ||||
-rw-r--r-- | mesonbuild/compilers.py | 11 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 14 |
3 files changed, 20 insertions, 16 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index c28a8a4..1f646dc 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -12,15 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +import copy, os, re +from collections import OrderedDict + from . import environment from . import dependencies from . import mlog -import copy, os, re from .mesonlib import File, MesonException from .mesonlib import flatten, stringlistify, classify_unity_sources from .mesonlib import get_filenames_templates_dict, substitute_values from .environment import for_windows, for_darwin -from .compilers import is_object, clike_langs, lang_suffixes +from .compilers import is_object, clike_langs, sort_clike, lang_suffixes known_basic_kwargs = {'install': True, 'c_pch': True, @@ -291,7 +293,7 @@ class BuildTarget(Target): self.is_unity = environment.coredata.get_builtin_option('unity') self.environment = environment self.sources = [] - self.compilers = {} + self.compilers = OrderedDict() self.objects = [] self.external_deps = [] self.include_dirs = [] @@ -444,6 +446,9 @@ class BuildTarget(Target): if lang not in self.compilers: self.compilers[lang] = compiler break + # Re-sort according to clike_langs + self.compilers = OrderedDict(sorted(self.compilers.items(), + key=lambda t: sort_clike(t[0]))) else: # No source files, target consists of only object files of unknown # origin. Just add the first clike compiler that we have and hope diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 22fb522..76a9067 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -57,6 +57,17 @@ clike_suffixes += ('h', 'll', 's') # All these are only for C-like languages; see `clike_langs` above. +def sort_clike(lang): + ''' + Sorting function to sort the list of languages according to + reversed(compilers.clike_langs) and append the unknown langs in the end. + The purpose is to prefer C over C++ for files that can be compiled by + both such as assembly, C, etc. Also applies to ObjC, ObjC++, etc. + ''' + if lang not in clike_langs: + return 1 + return -clike_langs.index(lang) + def is_header(fname): if hasattr(fname, 'fname'): fname = fname.fname diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 550e2f9..198c758 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1752,22 +1752,10 @@ class Interpreter(InterpreterBase): self.coredata.compiler_options = new_options return comp, cross_comp - @staticmethod - def sort_clike(lang): - ''' - Sorting function to sort the list of languages according to - reversed(compilers.clike_langs) and append the unknown langs in the end. - The purpose is to prefer C over C++ for files that can be compiled by - both such as assembly, C, etc. Also applies to ObjC, ObjC++, etc. - ''' - if lang not in compilers.clike_langs: - return 1 - return -compilers.clike_langs.index(lang) - def add_languages(self, args, required): success = True need_cross_compiler = self.environment.is_cross_build() and self.environment.cross_info.need_cross_compiler() - for lang in sorted(args, key=self.sort_clike): + for lang in sorted(args, key=compilers.sort_clike): lang = lang.lower() if lang in self.coredata.compilers: comp = self.coredata.compilers[lang] |