Debian Codegraph @

mesonbuild/compilers/mixins/tasking.py

raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2012-2023 The Meson development team
3 from __future__ import annotations
4
5 """Representations specific to the TASKING embedded C/C++ compiler family."""
6
7 import os
8 import typing as T
9
10 from ...compilers.compilers import SimplePrefixLinkerOptionStyle
11 from ...mesonlib import EnvironmentException
12 from ...options import OptionKey
13
14 if T.TYPE_CHECKING:
15 from ...compilers.compilers import Compiler
16 else:
17 # This is a bit clever, for mypy we pretend that these mixins descend from
18 # Compiler, so we get all of the methods and attributes defined for us, but
19 # for runtime we make them descend from object (which all classes normally
20 # do). This gives us DRYer type checking, with no runtime impact
21 Compiler = object
22
23 tasking_buildtype_args: T.Mapping[str, T.List[str]] = {
24 'plain': [],
25 'debug': [],
26 'debugoptimized': [],
27 'release': [],
28 'minsize': [],
29 'custom': []
30 }
31
32 tasking_optimization_args: T.Mapping[str, T.List[str]] = {
33 'plain': [],
34 '0': ['-O0'],
35 'g': ['-O1'], # There is no debug specific level, O1 is recommended by the compiler
36 '1': ['-O1'],
37 '2': ['-O2'],
38 '3': ['-O3'],
39 's': ['-Os']
40 }
41
42 tasking_debug_args: T.Mapping[bool, T.List[str]] = {
43 False: [],
44 True: ['-g3']
45 }
46
47 class TaskingCompiler(Compiler):
48 '''
49 Functionality that is common to all TASKING family compilers.
50 '''
51
52 LINKER_OPTION_STYLE = SimplePrefixLinkerOptionStyle('-Wl')
53
54 def __init__(self) -> None:
55 if not self.is_cross:
56 raise EnvironmentException(f'{id} supports only cross-compilation.')
57
58 self.base_options = {
59 OptionKey(o) for o in [
60 'b_lto',
61 'b_staticpic',
62 'b_ndebug'
63 ]
64 }
65
66 default_warn_args = [] # type: T.List[str]
67 self.warn_args = {'0': [],
68 '1': default_warn_args,
69 '2': default_warn_args + [],
70 '3': default_warn_args + [],
71 'everything': default_warn_args + []} # type: T.Dict[str, T.List[str]]
72 # TODO: add additional compilable files so that meson can detect it
73 self.can_compile_suffixes.add('asm')
74
75 def get_pic_args(self) -> T.List[str]:
76 return ['--pic']
77
78 def get_buildtype_args(self, buildtype: str) -> T.List[str]:
79 return tasking_buildtype_args[buildtype]
80
81 def get_debug_args(self, is_debug: bool) -> T.List[str]:
82 return tasking_debug_args[is_debug]
83
84 def get_compile_only_args(self) -> T.List[str]:
85 return ['-c']
86
87 def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
88 return [f'--dep-file={outfile}']
89
90 def get_depfile_suffix(self) -> str:
91 return 'dep'
92
93 def get_no_stdinc_args(self) -> T.List[str]:
94 return ['--no-stdinc']
95
96 def get_werror_args(self) -> T.List[str]:
97 return ['--warnings-as-errors']
98
99 def get_no_stdlib_link_args(self) -> T.List[str]:
100 return ['--no-default-libraries']
101
102 def get_output_args(self, outputname: str) -> T.List[str]:
103 return ['-o', outputname]
104
105 def get_include_args(self, path: str, is_system: bool) -> T.List[str]:
106 if path == '':
107 path = '.'
108 return ['-I' + path]
109
110 def get_optimization_args(self, optimization_level: str) -> T.List[str]:
111 return tasking_optimization_args[optimization_level]
112
113 def get_no_optimization_args(self) -> T.List[str]:
114 return ['-O0']
115
116 def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.Tuple[T.List[str], T.List[str]]:
117 mil_link_list = []
118 obj_file_list = []
119 for obj in obj_list:
120 if obj.endswith('.mil'):
121 mil_link_list.append(obj)
122 else:
123 obj_file_list.append(obj)
124 obj_file_list.append(prelink_name)
125
126 return obj_file_list, ['--mil-link', '-o', prelink_name, '-c'] + mil_link_list
127
128 def get_prelink_append_compile_args(self) -> bool:
129 return True
130
131 def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]:
132 for idx, i in enumerate(parameter_list):
133 if i[:2] == '-I' or i[:2] == '-L':
134 parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:]))
135
136 return parameter_list
137
138 def get_preprocess_only_args(self) -> T.List[str]:
139 return ['-E']