From b7db3660a0709f1f47bbad0e8af85da1360a6f19 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sun, 23 Aug 2020 21:05:39 -0700 Subject: compilers/mixins/arm: make type safe --- mesonbuild/compilers/mixins/arm.py | 50 ++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/mixins/arm.py b/mesonbuild/compilers/mixins/arm.py index b331d8f..142e692 100644 --- a/mesonbuild/compilers/mixins/arm.py +++ b/mesonbuild/compilers/mixins/arm.py @@ -1,4 +1,4 @@ -# Copyright 2012-2019 The Meson development team +# Copyright 2012-2020 Meson development team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,14 +15,15 @@ """Representations specific to the arm family of compilers.""" import os -import re import typing as T from ... import mesonlib +from ...linkers import ArmClangDynamicLinker from ..compilers import clike_debug_args from .clang import clang_color_args if T.TYPE_CHECKING: + from ...envconfig import MachineChoice from ...environment import Environment arm_buildtype_args = { @@ -63,8 +64,14 @@ armclang_optimization_args = { class ArmCompiler: - # Functionality that is common to all ARM family compilers. - def __init__(self): + + """Functionality that is common to all ARM family compilers.""" + + if T.TYPE_CHECKING: + is_cross = True + can_compile_suffixes = set() # type: T.Set[str] + + def __init__(self) -> None: if not self.is_cross: raise mesonlib.EnvironmentException('armcc supports only cross-compilation.') self.id = 'arm' @@ -127,31 +134,22 @@ class ArmCompiler: class ArmclangCompiler: - def __init__(self): + + if T.TYPE_CHECKING: + can_compile_suffixes = set() # type: T.Set[str] + is_cross = True + version = '0' + linker = ArmClangDynamicLinker(MachineChoice.HOST, version='1.2.3') + + def get_pch_name(self, name: str) -> str: ... + + def __init__(self) -> None: if not self.is_cross: raise mesonlib.EnvironmentException('armclang supports only cross-compilation.') # Check whether 'armlink' is available in path - self.linker_exe = 'armlink' - args = '--vsn' - try: - p, stdo, stderr = mesonlib.Popen_safe(self.linker_exe, args) - except OSError as e: - err_msg = 'Unknown linker\nRunning "{0}" gave \n"{1}"'.format(' '.join([self.linker_exe] + [args]), e) - raise mesonlib.EnvironmentException(err_msg) - # Verify the armlink version - ver_str = re.search('.*Component.*', stdo) - if ver_str: - ver_str = ver_str.group(0) - else: - raise mesonlib.EnvironmentException('armlink version string not found') - assert ver_str # makes mypy happy - # Using the regular expression from environment.search_version, - # which is used for searching compiler version - version_regex = r'(?