Skip to content

Commit bacd811

Browse files
dcbakerbonzini
authored andcommitted
programs: Add a couple more useful aliases
These are useful for the many cases of creating lists of commands that are mixtures of strings and programs
1 parent 081eaf1 commit bacd811

File tree

6 files changed

+29
-25
lines changed

6 files changed

+29
-25
lines changed

mesonbuild/modules/_qt.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from ..interpreter import Interpreter
2929
from ..interpreter import kwargs
3030
from ..mesonlib import FileOrString
31-
from ..programs import Program
31+
from ..programs import CommandList, Program
3232
from typing_extensions import Literal
3333

3434
QtDependencyType = T.Union[QtPkgConfigDependency, QmakeQtDependency]
@@ -441,7 +441,7 @@ def _compile_resources_impl(self, state: 'ModuleState', kwargs: 'ResourceCompile
441441

442442
# If a name was set generate a single .cpp file from all of the qrc
443443
# files, otherwise generate one .cpp file per qrc file.
444-
cmd: T.List[T.Union[Program, str]]
444+
cmd: CommandList
445445
if name:
446446
qrc_deps: T.List[File] = []
447447
for s in sources:
@@ -729,7 +729,7 @@ def compile_translations(self, state: ModuleState, args: T.Tuple, kwargs: Compil
729729
ts = os.path.basename(ts)
730730
else:
731731
outdir = state.subdir
732-
cmd: T.List[T.Union[Program, str]] = [self.tools['lrelease'], '@INPUT@', '-qm', '@OUTPUT@']
732+
cmd: CommandList = [self.tools['lrelease'], '@INPUT@', '-qm', '@OUTPUT@']
733733
lrelease_target = build.CustomTarget(
734734
f'qt{self.qt_version}-compile-{ts}',
735735
outdir,
@@ -869,8 +869,7 @@ def _moc_json_collect(self, state: ModuleState, kwargs: MocJsonCollectKwArgs) ->
869869
input_args.append(f'@INPUT{input_counter}@')
870870
input_counter += 1
871871

872-
cmd: T.List[T.Union[Program, str]] = \
873-
[self.tools['moc'], '--collect-json', '-o', '@OUTPUT@', *input_args]
872+
cmd: CommandList = [self.tools['moc'], '--collect-json', '-o', '@OUTPUT@', *input_args]
874873
return build.CustomTarget(
875874
f'moc_collect_json_{target_name}',
876875
state.subdir,
@@ -916,7 +915,7 @@ def _gen_qml_cachegen(self, state: ModuleState, kwargs: GenQmlCachegenKwArgs) ->
916915
ressource_path = os.path.join('/', kwargs['module_prefix'], source_basename)
917916
cachegen_inputs.append(ressource_path)
918917

919-
cmd: T.List[T.Union[Program, str]] = \
918+
cmd: CommandList = \
920919
[self.tools['qmlcachegen'], '-o', '@OUTPUT@', '--resource-name', f'qmlcache_{target_name}',
921920
*kwargs['extra_args'], '--resource=@INPUT@', *cachegen_inputs]
922921
cacheloader_target = build.CustomTarget(
@@ -952,7 +951,7 @@ def _qml_type_registrar(self, state: ModuleState, kwargs: GenQmlTypeRegistrarKwA
952951
install_dir: T.List[T.Union[str, Literal[False]]] = [False]
953952
install_tag: T.List[T.Union[str, None]] = [None]
954953

955-
cmd: T.List[T.Union[Program, str]] = [
954+
cmd: CommandList = [
956955
self.tools['qmltyperegistrar'],
957956
'--import-name', import_name,
958957
'--major-version', major_version,

mesonbuild/modules/codegen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from ..interpreter.kwargs import ExtractRequired
3030
from ..interpreterbase import TYPE_var, TYPE_kwargs
3131
from ..mesonlib import MachineChoice
32+
from ..programs import CommandList
3233

3334
LexImpls = Literal['lex', 'flex', 'reflex', 'win_flex']
3435
YaccImpls = Literal['yacc', 'byacc', 'bison', 'win_bison']
@@ -87,9 +88,8 @@ class _CodeGenerator(HoldableObject):
8788
program: Program
8889
arguments: ImmutableListProtocol[str] = dataclasses.field(default_factory=list)
8990

90-
def command(self) -> T.List[T.Union[Program, str]]:
91-
return (T.cast('T.List[T.Union[Program, str]]', [self.program]) +
92-
T.cast('T.List[T.Union[Program, str]]', self.arguments))
91+
def command(self) -> CommandList:
92+
return T.cast('CommandList', [self.program]) + T.cast('CommandList', self.arguments)
9393

9494
def found(self) -> bool:
9595
return self.program.found()

mesonbuild/modules/gnome.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from ..interpreter import Interpreter
4545
from ..interpreterbase import TYPE_var, TYPE_kwargs
4646
from ..mesonlib import FileOrString
47-
from ..programs import Program
47+
from ..programs import Program, CommandList, CommandListEntry
4848

4949
class PostInstall(TypedDict):
5050
glib_compile_schemas: bool
@@ -395,7 +395,7 @@ def compile_resources(self, state: 'ModuleState', args: T.Tuple[str, 'FileOrStri
395395
glib_version = self._get_native_glib_version(state)
396396

397397
glib_compile_resources = self._find_tool(state, 'glib-compile-resources')
398-
cmd: T.List[T.Union[Program, str]] = [glib_compile_resources, '@INPUT@']
398+
cmd: CommandList = [glib_compile_resources, '@INPUT@']
399399

400400
source_dirs = kwargs['source_dir']
401401
dependencies = kwargs['dependencies']
@@ -493,7 +493,7 @@ def compile_resources(self, state: 'ModuleState', args: T.Tuple[str, 'FileOrStri
493493
raise MesonException('GResource header is installed yet export is not enabled')
494494

495495
depfile: T.Optional[str] = None
496-
target_cmd: T.List[T.Union[Program, str]]
496+
target_cmd: CommandList
497497
if not mesonlib.version_compare(glib_version, gresource_dep_needed_version):
498498
# This will eventually go out of sync if dependencies are added
499499
target_cmd = cmd
@@ -1190,7 +1190,8 @@ def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[Execut
11901190

11911191
gir_inc_dirs: T.List[str] = []
11921192

1193-
scan_command: T.List[T.Union[str, Program, Executable]] = [giscanner]
1193+
# Executables are passed as indexes other than 0 in this List
1194+
scan_command: T.List[T.Union[CommandListEntry, Executable]] = [giscanner]
11941195
scan_command += ['--quiet']
11951196
scan_command += ['--no-libtool']
11961197
scan_command += ['--namespace=' + ns, '--nsversion=' + nsversion]
@@ -1264,7 +1265,7 @@ def compile_schemas(self, state: 'ModuleState', args: T.List['TYPE_var'], kwargs
12641265
srcdir = os.path.join(state.build_to_src, state.subdir)
12651266
outdir = state.subdir
12661267

1267-
cmd: T.List[T.Union[Program, str]] = [self._find_tool(state, 'glib-compile-schemas'), '--targetdir', outdir, srcdir]
1268+
cmd: CommandList = [self._find_tool(state, 'glib-compile-schemas'), '--targetdir', outdir, srcdir]
12681269
if state.subdir == '':
12691270
targetname = 'gsettings-compile'
12701271
else:
@@ -1344,7 +1345,7 @@ def yelp(self, state: 'ModuleState', args: T.Tuple[str, T.List[str]], kwargs: 'Y
13441345

13451346
pot_file = os.path.join('@SOURCE_ROOT@', state.subdir, 'C', project_id + '.pot')
13461347
pot_sources = [os.path.join('@SOURCE_ROOT@', state.subdir, 'C', s) for s in sources]
1347-
pot_args: T.List[T.Union[Program, str]] = [itstool, '-o', pot_file]
1348+
pot_args: CommandList = [itstool, '-o', pot_file]
13481349
pot_args.extend(pot_sources)
13491350
pottarget = build.RunTarget(f'help-{project_id}-pot', pot_args, [],
13501351
os.path.join(state.subdir, 'C'), state.subproject,
@@ -1376,7 +1377,7 @@ def yelp(self, state: 'ModuleState', args: T.Tuple[str, T.List[str]], kwargs: 'Y
13761377
targets.append(l_data)
13771378

13781379
po_file = l + '.po'
1379-
po_args: T.List[T.Union[Program, str]] = [
1380+
po_args: CommandList = [
13801381
msgmerge, '-q', '-o',
13811382
os.path.join('@SOURCE_ROOT@', l_subdir, po_file),
13821383
os.path.join('@SOURCE_ROOT@', l_subdir, po_file), pot_file]
@@ -1641,7 +1642,7 @@ def gdbus_codegen(self, state: 'ModuleState', args: T.Tuple[str, T.Optional[T.Un
16411642
kwargs: 'GdbusCodegen') -> ModuleReturnValue:
16421643
namebase = args[0]
16431644
xml_files: T.List[T.Union['FileOrString', build.GeneratedTypes]] = [args[1]] if args[1] else []
1644-
cmd: T.List[T.Union[Program, str]] = [self._find_tool(state, 'gdbus-codegen')]
1645+
cmd: CommandList = [self._find_tool(state, 'gdbus-codegen')]
16451646
cmd.extend(kwargs['extra_args'])
16461647

16471648
# Autocleanup supported?
@@ -2046,7 +2047,7 @@ def _make_mkenum_impl(
20462047
install_dir: T.Optional[T.Sequence[T.Union[str, bool]]] = None,
20472048
depends: T.Optional[T.Sequence[build.BuildTargetTypes]] = None
20482049
) -> build.CustomTarget:
2049-
real_cmd: T.List[T.Union[str, Program]] = [self._find_tool(state, 'glib-mkenums')]
2050+
real_cmd: CommandList = [self._find_tool(state, 'glib-mkenums')]
20502051
real_cmd.extend(cmd)
20512052
_install_dir = install_dir or state.environment.coredata.optstore.get_value_for(OptionKey('includedir'))
20522053
assert isinstance(_install_dir, str), 'for mypy'
@@ -2092,7 +2093,7 @@ def genmarshal(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'GenMarsh
20922093

20932094
new_genmarshal = mesonlib.version_compare(self._get_native_glib_version(state), '>= 2.53.3')
20942095

2095-
cmd: T.List[T.Union[Program, str]] = [self._find_tool(state, 'glib-genmarshal'), '--quiet']
2096+
cmd: CommandList = [self._find_tool(state, 'glib-genmarshal'), '--quiet']
20962097
if kwargs['prefix']:
20972098
cmd.extend(['--prefix', kwargs['prefix']])
20982099
if kwargs['extra_args']:
@@ -2239,8 +2240,7 @@ def generate_vapi(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'Gener
22392240
build_dir = os.path.join(state.environment.get_build_dir(), state.subdir)
22402241
source_dir = os.path.join(state.environment.get_source_dir(), state.subdir)
22412242
pkg_cmd, vapi_depends, vapi_packages, vapi_includes, packages = self._extract_vapi_packages(state, kwargs['packages'])
2242-
cmd: T.List[T.Union[Program, str]]
2243-
cmd = [state.find_program('vapigen'), '--quiet', f'--library={library}', f'--directory={build_dir}']
2243+
cmd: CommandList = [state.find_program('vapigen'), '--quiet', f'--library={library}', f'--directory={build_dir}']
22442244
cmd.extend([f'--vapidir={d}' for d in kwargs['vapi_dirs']])
22452245
cmd.extend([f'--metadatadir={d}' for d in kwargs['metadata_dirs']])
22462246
cmd.extend([f'--girdir={d}' for d in kwargs['gir_dirs']])

mesonbuild/modules/wayland.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from . import ModuleState
1818
from ..dependencies import Dependency
1919
from ..interpreter import Interpreter
20-
from ..programs import Program
20+
from ..programs import CommandList, Program
2121
from ..mesonlib import FileOrString
2222

2323
class ScanXML(TypedDict):
@@ -88,7 +88,7 @@ def scan_xml(self, state: ModuleState, args: T.Tuple[T.List[FileOrString]], kwar
8888
targets.append(code)
8989

9090
for side in sides:
91-
command: T.List[T.Union[Program, str]] = [self.scanner_bin, f'{side}-header', '@INPUT@', '@OUTPUT@']
91+
command: CommandList = [self.scanner_bin, f'{side}-header', '@INPUT@', '@OUTPUT@']
9292
if kwargs['include_core_only']:
9393
command.append('--include-core-only')
9494

mesonbuild/modules/windows.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from ..compilers import Compiler
2424
from ..interpreter import Interpreter
2525
from ..interpreter.interpreter import SourceOutputs
26+
from ..programs import CommandList
2627

2728
from typing_extensions import TypedDict
2829

@@ -201,7 +202,7 @@ def get_names() -> T.Iterable[T.Tuple[str, str, T.Union[str, mesonlib.File, buil
201202
name = name.replace('/', '_').replace('\\', '_').replace(':', '_')
202203
name_formatted = name_formatted.replace('/', '_').replace('\\', '_').replace(':', '_')
203204
output = f'{name}_@BASENAME@.{suffix}'
204-
command: T.List[T.Union[str, ExternalProgram]] = []
205+
command: CommandList = []
205206
command.append(rescomp)
206207
command.extend(res_args)
207208
depfile: T.Optional[str] = None

mesonbuild/programs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
from .mesonlib import MachineChoice, OrderedSet
2121

2222
if T.TYPE_CHECKING:
23+
from typing_extensions import TypeAlias
2324
from .environment import Environment
2425
from .interpreter import Interpreter
2526

27+
CommandListEntry: TypeAlias = T.Union[str, 'Program']
28+
CommandList: TypeAlias = T.List[CommandListEntry]
29+
2630

2731
class Program(mesonlib.HoldableObject, metaclass=ABCMeta):
2832
''' A base class for LocalProgram and ExternalProgram.'''

0 commit comments

Comments
 (0)