Debian Codegraph @

mesonbuild/interpreter/kwargs.py

raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright © 2021-2025 Intel Corporation
3 # Copyright © 2021-2025 Intel Corporation
4 from __future__ import annotations
5
6 """Keyword Argument type annotations."""
7
8 import typing as T
9
10 from typing_extensions import TypedDict, Literal, Protocol, NotRequired
11
12 from .. import build
13 from .. import options
14 from ..compilers import Compiler
15 from ..compilers.compilers import Language
16 from ..dependencies.base import Dependency, DependencyMethods, IncludeType
17 from ..interpreterbase import Feature
18 from ..mesonlib import EnvironmentVariables, MachineChoice, File, FileMode, FileOrString
19 from ..options import OptionKey
20 from ..modules.cmake import CMakeSubprojectOptions
21 from ..programs import Program, ExternalProgram
22 from .type_checking import PkgConfigDefineType, SourcesVarargsType
23
24 TargetDepends = T.Union[build.CustomTarget, build.CustomTargetIndex, build.BuildTarget, build.GeneratedList, Program]
25 CustomTargetInputs = T.Union[str, build.BuildTarget, build.GeneratedTypes,
26 build.ExtractedObjects, Program, File]
27 BuildTargetObjects = T.Union[str, File, build.ExtractedObjects, build.GeneratedTypes]
28 RustAbi = Literal['rust', 'c']
29
30 class NativeKW(TypedDict):
31
32 native: MachineChoice
33
34
35 class FuncAddProjectArgs(TypedDict):
36
37 """Keyword Arguments for the add_*_arguments family of arguments.
38
39 including `add_global_arguments`, `add_project_arguments`, and their
40 link variants
41
42 Because of the use of a convertor function, we get the native keyword as
43 a MachineChoice instance already.
44 """
45
46 native: MachineChoice
47 language: T.List[Language]
48
49
50 class BaseTest(TypedDict):
51
52 """Shared base for the Rust module."""
53
54 should_fail: T.Optional[bool]
55 expected_fail: T.Optional[bool]
56 expected_exitcode: T.Optional[int]
57 timeout: int
58 workdir: T.Optional[str]
59 priority: int
60 env: EnvironmentVariables
61 depends: T.List[TargetDepends]
62 suite: T.List[str]
63 verbose: bool
64
65
66 class FuncBenchmark(BaseTest):
67
68 """Keyword arguments used by `benchmark` and `test`, but not Rust"""
69
70 # Needs complex refactor for rust test to go in BaseTest
71 args: T.List[build.CommandTypes]
72 protocol: Literal['exitcode', 'tap', 'gtest', 'rust']
73
74 class FuncTest(FuncBenchmark):
75
76 """Keyword Arguments for `test` but not `benchmark`"""
77
78 is_parallel: bool
79
80
81 class ExtractRequired(TypedDict):
82
83 """Keyword Arguments consumed by the `extract_required_kwargs` function.
84
85 Any function that uses the `required` keyword argument which accepts either
86 a boolean or a feature option should inherit its arguments from this class.
87 """
88
89 required: T.Union[bool, Feature]
90
91
92 class ExtractSearchDirs(TypedDict):
93
94 """Keyword arguments consumed by the `extract_search_dirs` function.
95
96 See the not in `ExtractRequired`
97 """
98
99 dirs: T.List[str]
100
101
102 class FuncGenerator(TypedDict):
103
104 """Keyword rguments for the generator function."""
105
106 arguments: T.List[str]
107 output: T.List[str]
108 depfile: T.Optional[str]
109 capture: bool
110 depends: T.List[TargetDepends]
111
112
113 class GeneratorProcess(TypedDict):
114
115 """Keyword Arguments for generator.process."""
116
117 preserve_path_from: T.Optional[str]
118 extra_args: T.List[str]
119 env: EnvironmentVariables
120 depends: T.List[build.GeneratedTypes]
121
122 class DependencyMethodPartialDependency(TypedDict):
123
124 """ Keyword Arguments for the dep.partial_dependency methods """
125
126 compile_args: bool
127 link_args: bool
128 links: bool
129 includes: bool
130 sources: bool
131
132 class BuildTargeMethodExtractAllObjects(TypedDict):
133 recursive: bool
134
135 class FuncInstallSubdir(TypedDict):
136
137 install_dir: str
138 install_tag: T.Optional[str]
139 strip_directory: bool
140 exclude_files: T.List[str]
141 exclude_directories: T.List[str]
142 install_mode: FileMode
143 follow_symlinks: T.Optional[bool]
144
145
146 class FuncInstallData(TypedDict):
147
148 install_dir: str
149 sources: T.List[FileOrString]
150 rename: T.List[str]
151 install_mode: FileMode
152 install_tag: T.Optional[str]
153 follow_symlinks: T.Optional[bool]
154 preserve_path: bool
155
156
157 class FuncInstallEmptyDir(TypedDict):
158
159 install_mode: FileMode
160 install_tag: T.Optional[str]
161
162
163 class FuncInstallHeaders(TypedDict):
164
165 install_dir: T.Optional[str]
166 install_mode: FileMode
167 subdir: T.Optional[str]
168 follow_symlinks: T.Optional[bool]
169 install_tag: T.Optional[str]
170 preserve_path: bool
171
172
173 class FuncInstallMan(TypedDict):
174
175 install_dir: T.Optional[str]
176 install_mode: FileMode
177 install_tag: T.Optional[str]
178 locale: T.Optional[str]
179
180
181 class FuncInstallSymlink(TypedDict):
182
183 install_dir: T.Optional[str]
184 install_tag: T.Optional[str]
185 pointing_to: str
186
187
188 class FuncImportModule(ExtractRequired):
189
190 disabler: bool
191
192
193 class FuncIncludeDirectories(TypedDict):
194
195 is_system: bool
196
197 class FuncAddLanguages(ExtractRequired):
198
199 native: MachineChoice | None
200
201 class RunTarget(TypedDict):
202
203 command: T.List[build.CommandTypes]
204 depends: T.List[TargetDepends]
205 env: EnvironmentVariables
206
207
208 class CustomTarget(TypedDict):
209
210 build_always: bool
211 build_always_stale: T.Optional[bool]
212 build_by_default: T.Optional[bool]
213 build_subdir: str
214 capture: bool
215 command: T.List[build.CommandTypes]
216 console: bool
217 depend_files: T.List[FileOrString]
218 depends: T.List[TargetDepends]
219 depfile: T.Optional[str]
220 env: EnvironmentVariables
221 feed: bool
222 input: T.List[CustomTargetInputs]
223 install: bool
224 install_dir: T.List[T.Union[str, T.Literal[False]]]
225 install_mode: FileMode
226 install_tag: T.List[T.Optional[str]]
227 output: T.List[str]
228
229 class AddTestSetup(TypedDict):
230
231 exe_wrapper: T.List[T.Union[str, ExternalProgram]]
232 gdb: bool
233 timeout_multiplier: int
234 is_default: bool
235 exclude_suites: T.List[str]
236 env: EnvironmentVariables
237
238
239 class Project(TypedDict):
240
241 version: FileOrString
242 meson_version: T.Optional[str]
243 default_options: options.OptionDict
244 license: T.List[str]
245 license_files: T.List[str]
246 subproject_dir: str
247
248
249 class _FoundProto(Protocol):
250
251 """Protocol for subdir arguments.
252
253 This allows us to define any object that has a found(self) -> bool method
254 """
255
256 def found(self) -> bool: ...
257
258
259 class Subdir(TypedDict):
260
261 if_found: T.List[_FoundProto]
262
263
264 class Summary(TypedDict):
265
266 section: str
267 bool_yn: bool
268 list_sep: T.Optional[str]
269
270
271 class FindProgram(ExtractRequired, ExtractSearchDirs):
272
273 default_options: T.Dict[OptionKey, options.ElementaryOptionValues]
274 native: MachineChoice
275 version: T.List[str]
276 version_argument: str
277
278
279 class RunCommand(TypedDict):
280
281 check: bool
282 capture: T.Optional[bool]
283 console: T.Optional[bool]
284 env: EnvironmentVariables
285
286
287 class FeatureOptionRequire(TypedDict):
288
289 error_message: T.Optional[str]
290
291
292 class DependencyPkgConfigVar(TypedDict):
293
294 default: T.Optional[str]
295 define_variable: PkgConfigDefineType
296
297
298 class DependencyGetVariable(TypedDict):
299
300 cmake: T.Optional[str]
301 pkgconfig: T.Optional[str]
302 configtool: T.Optional[str]
303 internal: T.Optional[str]
304 system: T.Optional[str]
305 default_value: T.Optional[str]
306 pkgconfig_define: PkgConfigDefineType
307
308
309 class ConfigurationDataSet(TypedDict):
310
311 description: T.Optional[str]
312
313 class VcsTag(TypedDict):
314
315 command: T.List[build.CommandTypes]
316 fallback: T.Optional[str]
317 input: list[CustomTargetInputs]
318 output: T.List[str]
319 replace_string: str
320 install: bool
321 install_tag: T.Optional[str]
322 install_dir: T.Optional[str]
323 install_mode: FileMode
324
325
326 class ConfigureFile(TypedDict):
327
328 output: str
329 capture: bool
330 format: T.Literal['meson', 'cmake', 'cmake@']
331 output_format: T.Literal['c', 'json', 'nasm']
332 depfile: T.Optional[str]
333 install: T.Optional[bool]
334 install_dir: T.Union[str, T.Literal[False]]
335 install_mode: FileMode
336 install_tag: T.Optional[str]
337 encoding: str
338 command: T.Optional[T.List[T.Union[build.Executable, Program, Compiler, File, str]]]
339 input: T.List[FileOrString]
340 configuration: T.Optional[T.Union[T.Dict[str, T.Union[str, int, bool]], build.ConfigurationData]]
341 macro_name: T.Optional[str]
342 build_subdir: str
343 copy: bool
344
345
346 class Subproject(ExtractRequired):
347
348 default_options: T.Dict[OptionKey, options.ElementaryOptionValues]
349 version: T.List[str]
350 native: MachineChoice
351
352
353 class DoSubproject(ExtractRequired):
354
355 default_options: T.Dict[OptionKey, options.ElementaryOptionValues]
356 version: T.List[str]
357 cmake_options: T.List[str]
358 options: T.Optional[CMakeSubprojectOptions]
359 for_machine: MachineChoice
360
361
362 class BaseBuildTarget(TypedDict):
363
364 """Arguments used by all BuildTarget like functions.
365
366 This really exists because Jar is so different than all of the other
367 BuildTarget functions.
368 """
369
370 build_by_default: bool
371 build_rpath: str
372 build_subdir: str
373 dependencies: T.List[Dependency]
374 extra_files: T.List[FileOrString]
375 gnu_symbol_visibility: str
376 include_directories: T.List[T.Union[str, build.IncludeDirs]]
377 install: bool
378 install_mode: FileMode
379 install_tag: T.Optional[str]
380 install_rpath: str
381 implicit_include_directories: bool
382 link_depends: T.List[T.Union[str, File, build.BuildTargetTypes]]
383 link_language: T.Optional[Language]
384 link_whole: T.List[build.StaticTargetTypes]
385 link_with: T.List[build.LinkableTargetTypes]
386 name_prefix: T.Optional[str]
387 name_suffix: T.Optional[str]
388 native: MachineChoice
389 objects: T.List[BuildTargetObjects]
390 override_options: T.Dict[str, options.ElementaryOptionValues]
391 depend_files: NotRequired[T.List[File]]
392 resources: T.List[str]
393 vala_header: T.Optional[str]
394 vala_vapi: T.Optional[str]
395 vala_gir: T.Optional[str]
396
397
398 class BuildTarget(BaseBuildTarget):
399
400 """Arguments shared by non-JAR functions"""
401
402 d_debug: T.List[T.Union[str, int]]
403 d_import_dirs: T.List[T.Union[str, build.IncludeDirs]]
404 d_module_versions: T.List[T.Union[str, int]]
405 d_unittest: bool
406 install_dir: T.List[T.Union[str, bool]]
407 install_vala_header: T.Union[str, bool, None]
408 install_vala_vapi: T.Union[str, bool, None]
409 install_vala_gir: T.Union[str, bool, None]
410 rust_crate_type: T.Optional[Literal['bin', 'lib', 'rlib', 'dylib', 'cdylib', 'staticlib', 'proc-macro']]
411 rust_dependency_map: T.Dict[str, str]
412 swift_interoperability_mode: Literal['c', 'cpp']
413 swift_module_name: str
414 sources: SourcesVarargsType
415 link_args: T.List[str]
416 link_early_args: T.List[str]
417 c_pch: T.Optional[T.Tuple[str, T.Optional[str]]]
418 cpp_pch: T.Optional[T.Tuple[str, T.Optional[str]]]
419 c_args: T.List[str]
420 cpp_args: T.List[str]
421 cuda_args: T.List[str]
422 fortran_args: T.List[str]
423 d_args: T.List[str]
424 objc_args: T.List[str]
425 objcpp_args: T.List[str]
426 rust_args: T.List[str]
427 vala_args: T.List[T.Union[str, File]] # Yes, Vala is really special
428 cs_args: T.List[str]
429 swift_args: T.List[str]
430 cython_args: T.List[str]
431 nasm_args: T.List[str]
432 masm_args: T.List[str]
433
434
435 class _LibraryMixin(TypedDict):
436
437 rust_abi: T.Optional[RustAbi]
438
439
440 class _LinkableTargetMixin(TypedDict):
441
442 vs_module_defs: T.Optional[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex]]
443 win_subsystem: T.Optional[str]
444
445
446 class _ExecutableMixin(TypedDict):
447
448 export_dynamic: T.Optional[bool]
449 gui_app: T.Optional[bool]
450 implib: T.Optional[T.Union[str, bool]]
451 pie: T.Optional[bool]
452 android_exe_type: T.Optional[Literal['application', 'executable']]
453
454
455 class Executable(BuildTarget, _ExecutableMixin, _LinkableTargetMixin):
456 pass
457
458
459 class _StaticLibMixin(TypedDict):
460
461 prelink: bool
462 pic: T.Optional[bool]
463
464
465 class StaticLibrary(BuildTarget, _StaticLibMixin, _LibraryMixin):
466 pass
467
468
469 class _SharedLibMixin(TypedDict):
470
471 darwin_versions: T.Optional[T.Tuple[str, str]]
472 soversion: T.Optional[str]
473 version: T.Optional[str]
474 shortname: str
475
476
477 class SharedLibrary(BuildTarget, _SharedLibMixin, _LibraryMixin, _LinkableTargetMixin):
478 pass
479
480
481 class SharedModule(BuildTarget, _LibraryMixin, _LinkableTargetMixin):
482 pass
483
484
485 class Library(BuildTarget, _SharedLibMixin, _StaticLibMixin, _LibraryMixin, _LinkableTargetMixin):
486
487 """For library, both_library, and as a base for build_target"""
488
489 c_static_args: NotRequired[T.List[str]]
490 c_shared_args: NotRequired[T.List[str]]
491 cpp_static_args: NotRequired[T.List[str]]
492 cpp_shared_args: NotRequired[T.List[str]]
493 cuda_static_args: NotRequired[T.List[str]]
494 cuda_shared_args: NotRequired[T.List[str]]
495 fortran_static_args: NotRequired[T.List[str]]
496 fortran_shared_args: NotRequired[T.List[str]]
497 d_static_args: NotRequired[T.List[str]]
498 d_shared_args: NotRequired[T.List[str]]
499 objc_static_args: NotRequired[T.List[str]]
500 objc_shared_args: NotRequired[T.List[str]]
501 objcpp_static_args: NotRequired[T.List[str]]
502 objcpp_shared_args: NotRequired[T.List[str]]
503 rust_static_args: NotRequired[T.List[str]]
504 rust_shared_args: NotRequired[T.List[str]]
505 vala_static_args: NotRequired[T.List[T.Union[str, File]]] # Yes, Vala is really special
506 vala_shared_args: NotRequired[T.List[T.Union[str, File]]] # Yes, Vala is really special
507 cs_static_args: NotRequired[T.List[str]]
508 cs_shared_args: NotRequired[T.List[str]]
509 swift_static_args: NotRequired[T.List[str]]
510 swift_shared_args: NotRequired[T.List[str]]
511 cython_static_args: NotRequired[T.List[str]]
512 cython_shared_args: NotRequired[T.List[str]]
513 nasm_static_args: NotRequired[T.List[str]]
514 nasm_shared_args: NotRequired[T.List[str]]
515 masm_static_args: NotRequired[T.List[str]]
516 masm_shared_args: NotRequired[T.List[str]]
517
518
519 class _JarMixin(TypedDict):
520
521 main_class: str
522 java_resources: T.Optional[build.StructuredSources]
523 java_args: T.List[str]
524
525
526 class Jar(BaseBuildTarget, _JarMixin):
527
528 sources: T.Union[str, build.TargetSources, build.ExtractedObjects, build.BuildTarget]
529
530
531 class BuildTargetFunc(Library, _ExecutableMixin, _JarMixin):
532
533 target_type: Literal['executable', 'shared_library', 'static_library',
534 'shared_module', 'both_libraries', 'library', 'jar']
535
536
537 class FuncDeclareDependency(TypedDict):
538
539 compile_args: T.List[str]
540 d_import_dirs: T.List[T.Union[build.IncludeDirs, str]]
541 d_module_versions: T.List[T.Union[str, int]]
542 dependencies: T.List[Dependency]
543 extra_files: T.List[FileOrString]
544 include_directories: T.List[T.Union[build.IncludeDirs, str]]
545 link_args: T.List[str]
546 link_whole: T.List[build.StaticTargetTypes]
547 link_with: T.List[build.LinkableTargetTypes]
548 objects: T.List[build.ExtractedObjects]
549 sources: T.List[str | build.TargetSources]
550 variables: T.Dict[str, str]
551 version: T.Optional[str]
552
553
554 class FuncDependency(ExtractRequired):
555
556 allow_fallback: T.Optional[bool]
557 cmake_args: T.List[str]
558 cmake_module_path: T.List[str]
559 cmake_package_version: str
560 components: T.List[str]
561 default_options: T.Dict[OptionKey, options.ElementaryOptionValues]
562 fallback: T.Union[str, T.List[str], None]
563 include_type: IncludeType
564 language: T.Optional[Language]
565 main: bool
566 method: DependencyMethods
567 modules: T.List[str]
568 native: MachineChoice
569 not_found_message: str
570 optional_modules: T.List[str]
571 private_headers: bool
572 static: T.Optional[bool]
573 version: T.List[str]
574
575
576 class FuncExpectError(TypedDict):
577
578 how: str
579
580
581 class FuncEnvironment(TypedDict):
582
583 method: Literal['set', 'prepend', 'append']
584 separator: str
585
586
587 class MachineMapArgs(TypedDict):
588
589 native: NotRequired[MachineChoice]
590 install: NotRequired[bool]