Skip to content

Commit d514a56

Browse files
committed
Rename BaseProgram to Program and use it where possible
When both ExternalProgram and LocalProgram are accepted, use Program instead.
1 parent 0125c3a commit d514a56

File tree

18 files changed

+106
-110
lines changed

18 files changed

+106
-110
lines changed

mesonbuild/backend/backends.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def determine_swift_dep_dirs(self, target: build.BuildTarget) -> T.List[str]:
535535
return result
536536

537537
def get_executable_serialisation(
538-
self, cmd: T.Sequence[T.Union[programs.ExternalProgram, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, File, str, build.LocalProgram]],
538+
self, cmd: T.Sequence[T.Union[programs.Program, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, File, str]],
539539
workdir: T.Optional[str] = None,
540540
extra_bdeps: T.Optional[T.List[build.BuildTarget]] = None,
541541
capture: T.Optional[str] = None,
@@ -550,7 +550,7 @@ def get_executable_serialisation(
550550
exe, *raw_cmd_args = cmd
551551
if isinstance(exe, build.LocalProgram):
552552
exe = exe.program
553-
if isinstance(exe, programs.ExternalProgram):
553+
if isinstance(exe, programs.Program):
554554
exe_cmd = exe.get_command()
555555
exe_for_machine = exe.for_machine
556556
elif isinstance(exe, build.BuildTarget):
@@ -575,7 +575,7 @@ def get_executable_serialisation(
575575
for c in raw_cmd_args:
576576
if isinstance(c, build.LocalProgram):
577577
c = c.program
578-
if isinstance(c, programs.ExternalProgram):
578+
if isinstance(c, programs.Program):
579579
cmd_args += c.get_command()
580580
elif isinstance(c, (build.BuildTarget, build.CustomTarget, build.CustomTargetIndex)):
581581
cmd_args.append(self.get_target_filename_abs(c))
@@ -1128,7 +1128,7 @@ def extract_dll_paths(cls, target: build.BuildTarget) -> T.Set[str]:
11281128
return results
11291129

11301130
def determine_windows_extra_paths(
1131-
self, target: T.Union[build.BuildTargetTypes, programs.ExternalProgram, mesonlib.File, str],
1131+
self, target: T.Union[build.BuildTargetTypes, programs.Program, mesonlib.File, str],
11321132
extra_bdeps: T.Sequence[build.BuildTargetTypes]) -> T.List[str]:
11331133
"""On Windows there is no such thing as an rpath.
11341134

mesonbuild/build.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def __init__(self, environment: Environment):
363363
self.stdlibs = PerMachine({}, {})
364364
self.test_setups: T.Dict[str, TestSetup] = {}
365365
self.test_setup_default_name = None
366-
self.find_overrides: T.Dict[str, T.Union[programs.ExternalProgram, LocalProgram]] = {}
366+
self.find_overrides: T.Dict[str, programs.Program] = {}
367367
self.searched_programs: T.Set[str] = set() # The list of all programs that have been searched for.
368368

369369
# If we are doing a cross build we need two caches, if we're doing a
@@ -1980,7 +1980,7 @@ def __str__(self) -> str:
19801980

19811981
class Generator(HoldableObject):
19821982
def __init__(self, env: Environment,
1983-
exe: T.Union[Executable, programs.ExternalProgram, LocalProgram, CustomTarget, CustomTargetIndex],
1983+
exe: T.Union[Executable, programs.Program, CustomTarget, CustomTargetIndex],
19841984
arguments: T.List[str],
19851985
output: T.List[str],
19861986
# how2dataclass
@@ -2766,7 +2766,7 @@ class CommandBase:
27662766
dependencies: T.List[T.Union[BuildTarget, 'CustomTarget']]
27672767
subproject: str
27682768

2769-
def flatten_command(self, cmd: T.Sequence[T.Union[str, File, programs.ExternalProgram, BuildTargetTypes, LocalProgram]]) -> \
2769+
def flatten_command(self, cmd: T.Sequence[T.Union[str, File, programs.Program, BuildTargetTypes]]) -> \
27702770
T.List[T.Union[str, File, BuildTarget, CustomTarget, programs.ExternalProgram]]:
27712771
cmd = listify(cmd)
27722772
final_cmd: T.List[T.Union[str, File, BuildTarget, 'CustomTarget']] = []
@@ -2840,7 +2840,7 @@ def __init__(self,
28402840
environment: Environment,
28412841
command: T.Sequence[T.Union[
28422842
str, BuildTargetTypes, GeneratedList,
2843-
programs.ExternalProgram, File, LocalProgram]],
2843+
programs.Program, File]],
28442844
sources: T.Sequence[T.Union[
28452845
str, File, BuildTargetTypes, ExtractedObjects,
28462846
GeneratedList, programs.ExternalProgram]],
@@ -3101,7 +3101,7 @@ class RunTarget(Target, CommandBase):
31013101
typename = 'run'
31023102

31033103
def __init__(self, name: str,
3104-
command: T.Sequence[T.Union[str, File, BuildTargetTypes, programs.ExternalProgram, LocalProgram]],
3104+
command: T.Sequence[T.Union[str, File, BuildTargetTypes, programs.Program]],
31053105
dependencies: T.Sequence[AnyTargetType],
31063106
subdir: str,
31073107
subproject: str,
@@ -3331,7 +3331,7 @@ def get(self, name: str) -> T.Tuple[T.Union[str, int, bool], T.Optional[str]]:
33313331
def keys(self) -> T.Iterator[str]:
33323332
return self.values.keys()
33333333

3334-
class LocalProgram(programs.BaseProgram):
3334+
class LocalProgram(programs.Program):
33353335
''' A wrapper for a program that may have build dependencies.'''
33363336
def __init__(self, program: T.Union[programs.ExternalProgram, Executable, CustomTarget, CustomTargetIndex], version: str,
33373337
depends: T.Optional[T.List[T.Union[BuildTarget, CustomTarget]]] = None,

mesonbuild/interpreter/interpreter.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
FileMode, MachineChoice, is_parent_path, listify,
2222
extract_as_list, has_path_sep, path_is_in_root, PerMachine)
2323
from ..options import OptionKey
24-
from ..programs import ExternalProgram, NonExistingExternalProgram, BaseProgram
24+
from ..programs import ExternalProgram, NonExistingExternalProgram, Program
2525
from ..dependencies import Dependency
2626
from ..depfile import DepFile
2727
from ..interpreterbase import ContainerTypeInfo, InterpreterBase, KwargInfo, typed_kwargs, typed_pos_args
@@ -130,7 +130,7 @@
130130

131131
BuildTargetSource = T.Union[mesonlib.FileOrString, build.GeneratedTypes, build.StructuredSources]
132132

133-
ProgramVersionFunc = T.Callable[[T.Union[ExternalProgram, build.LocalProgram]], str]
133+
ProgramVersionFunc = T.Callable[[Program], str]
134134

135135
TestClass = T.TypeVar('TestClass', bound=Test)
136136

@@ -447,7 +447,7 @@ def build_holder_map(self) -> None:
447447
'''
448448
self.bound_holder_map.update({
449449
dependencies.Dependency: OBJ.DependencyHolder,
450-
BaseProgram: OBJ.BaseProgramHolder,
450+
Program: OBJ.ProgramHolder,
451451
compilers.Compiler: compilerOBJ.CompilerHolder,
452452
ModuleObject: OBJ.ModuleObjectHolder,
453453
MutableModuleObject: OBJ.MutableModuleObjectHolder,
@@ -745,17 +745,17 @@ def validate_arguments(self, args, argcount, arg_types):
745745
# better error messages when overridden
746746
@typed_pos_args(
747747
'run_command',
748-
(build.Executable, ExternalProgram, compilers.Compiler, mesonlib.File, str, build.LocalProgram),
749-
varargs=(build.Executable, ExternalProgram, compilers.Compiler, mesonlib.File, str, build.LocalProgram))
748+
(build.Executable, Program, compilers.Compiler, mesonlib.File, str),
749+
varargs=(build.Executable, Program, compilers.Compiler, mesonlib.File, str))
750750
@typed_kwargs(
751751
'run_command',
752752
KwargInfo('check', (bool, NoneType), since='0.47.0'),
753753
KwargInfo('capture', bool, default=True, since='0.47.0'),
754754
ENV_KW.evolve(since='0.50.0'),
755755
)
756756
def func_run_command(self, node: mparser.BaseNode,
757-
args: T.Tuple[T.Union[build.Executable, ExternalProgram, compilers.Compiler, mesonlib.File, str, build.LocalProgram],
758-
T.List[T.Union[build.Executable, ExternalProgram, compilers.Compiler, mesonlib.File, str, build.LocalProgram]]],
757+
args: T.Tuple[T.Union[build.Executable, Program, compilers.Compiler, mesonlib.File, str],
758+
T.List[T.Union[build.Executable, Program, compilers.Compiler, mesonlib.File, str]]],
759759
kwargs: 'kwtypes.RunCommand') -> RunProcess:
760760
return self.run_command_impl(args, kwargs)
761761

@@ -767,8 +767,8 @@ def _compiled_exe_error(self, cmd: T.Union[build.LocalProgram, build.Executable]
767767
raise InterpreterException(f'Program {descr!r} is a compiled executable and therefore cannot be used during configuration')
768768

769769
def run_command_impl(self,
770-
args: T.Tuple[T.Union[build.Executable, ExternalProgram, compilers.Compiler, mesonlib.File, str, build.LocalProgram],
771-
T.List[T.Union[build.Executable, ExternalProgram, compilers.Compiler, mesonlib.File, str, build.LocalProgram]]],
770+
args: T.Tuple[T.Union[build.Executable, Program, compilers.Compiler, mesonlib.File, str],
771+
T.List[T.Union[build.Executable, Program, compilers.Compiler, mesonlib.File, str]]],
772772
kwargs: 'kwtypes.RunCommand',
773773
in_builddir: bool = False) -> RunProcess:
774774
cmd, cargs = args
@@ -1595,7 +1595,7 @@ def program_from_system(self, args: T.List[mesonlib.FileOrString], search_dirs:
15951595

15961596
def program_from_overrides(self, command_names: T.List[mesonlib.FileOrString],
15971597
extra_info: T.List['mlog.TV_Loggable']
1598-
) -> T.Optional[T.Union[ExternalProgram, build.LocalProgram]]:
1598+
) -> T.Optional[Program]:
15991599
for name in command_names:
16001600
if not isinstance(name, str):
16011601
continue
@@ -1610,7 +1610,7 @@ def store_name_lookups(self, command_names: T.List[mesonlib.FileOrString]) -> No
16101610
if isinstance(name, str):
16111611
self.build.searched_programs.add(name)
16121612

1613-
def add_find_program_override(self, name: str, exe: T.Union[ExternalProgram, build.LocalProgram]) -> None:
1613+
def add_find_program_override(self, name: str, exe: Program) -> None:
16141614
if name in self.build.searched_programs:
16151615
raise InterpreterException(f'Tried to override finding of executable "{name}" which has already been found.')
16161616
if name in self.build.find_overrides:
@@ -1635,7 +1635,7 @@ def find_program_impl(self, args: T.List[mesonlib.FileOrString],
16351635
search_dirs: T.Optional[T.List[str]] = None,
16361636
version_arg: T.Optional[str] = '',
16371637
version_func: T.Optional[ProgramVersionFunc] = None
1638-
) -> T.Union[ExternalProgram, build.LocalProgram]:
1638+
) -> Program:
16391639
args = mesonlib.listify(args)
16401640

16411641
extra_info: T.List[mlog.TV_Loggable] = []
@@ -1667,7 +1667,7 @@ def program_lookup(self, args: T.List[mesonlib.FileOrString], for_machine: Machi
16671667
version_arg: T.Optional[str],
16681668
version_func: T.Optional[ProgramVersionFunc],
16691669
extra_info: T.List[mlog.TV_Loggable]
1670-
) -> T.Optional[T.Union[ExternalProgram, build.LocalProgram]]:
1670+
) -> T.Optional[Program]:
16711671
progobj = self.program_from_overrides(args, extra_info)
16721672
if progobj:
16731673
return progobj
@@ -1703,7 +1703,7 @@ def program_lookup(self, args: T.List[mesonlib.FileOrString], for_machine: Machi
17031703

17041704
return progobj
17051705

1706-
def check_program_version(self, progobj: T.Union[ExternalProgram, build.LocalProgram],
1706+
def check_program_version(self, progobj: Program,
17071707
wanted: T.Union[str, T.List[str]],
17081708
version_func: T.Optional[ProgramVersionFunc],
17091709
extra_info: T.List[mlog.TV_Loggable]) -> bool:
@@ -1730,7 +1730,7 @@ def check_program_version(self, progobj: T.Union[ExternalProgram, build.LocalPro
17301730
def find_program_fallback(self, fallback: str, args: T.List[mesonlib.FileOrString],
17311731
default_options: OptionDict,
17321732
required: bool, extra_info: T.List[mlog.TV_Loggable]
1733-
) -> T.Optional[T.Union[ExternalProgram, build.LocalProgram]]:
1733+
) -> T.Optional[Program]:
17341734
mlog.log('Fallback to subproject', mlog.bold(fallback), 'which provides program',
17351735
mlog.bold(' '.join(args)))
17361736
sp_kwargs: kwtypes.DoSubproject = {
@@ -1757,7 +1757,7 @@ def find_program_fallback(self, fallback: str, args: T.List[mesonlib.FileOrStrin
17571757
@disablerIfNotFound
17581758
def func_find_program(self, node: mparser.BaseNode, args: T.Tuple[T.List[mesonlib.FileOrString]],
17591759
kwargs: 'kwtypes.FindProgram',
1760-
) -> T.Union[ExternalProgram, build.LocalProgram]:
1760+
) -> Program:
17611761
disabled, required, feature = extract_required_kwarg(kwargs, self.subproject)
17621762
if disabled:
17631763
mlog.log('Program', mlog.bold(' '.join(args[0])), 'skipped: feature', mlog.bold(feature), 'disabled')
@@ -2193,7 +2193,7 @@ def func_alias_target(self, node: mparser.BaseNode, args: T.Tuple[str, T.List[T.
21932193
self.add_target(name, tg)
21942194
return tg
21952195

2196-
@typed_pos_args('generator', (build.Executable, ExternalProgram, build.LocalProgram))
2196+
@typed_pos_args('generator', (build.Executable, Program))
21972197
@typed_kwargs(
21982198
'generator',
21992199
KwargInfo('arguments', ContainerTypeInfo(list, str, allow_empty=False), required=True, listify=True),
@@ -2203,7 +2203,7 @@ def func_alias_target(self, node: mparser.BaseNode, args: T.Tuple[str, T.List[T.
22032203
KwargInfo('capture', bool, default=False, since='0.43.0'),
22042204
)
22052205
def func_generator(self, node: mparser.FunctionNode,
2206-
args: T.Tuple[T.Union[build.Executable, ExternalProgram, build.LocalProgram]],
2206+
args: T.Tuple[T.Union[build.Executable, Program]],
22072207
kwargs: 'kwtypes.FuncGenerator') -> build.Generator:
22082208
for rule in kwargs['output']:
22092209
if '@BASENAME@' not in rule and '@PLAINNAME@' not in rule:
@@ -2217,17 +2217,17 @@ def func_generator(self, node: mparser.FunctionNode,
22172217

22182218
return build.Generator(self.environment, args[0], **kwargs)
22192219

2220-
@typed_pos_args('benchmark', str, (build.Executable, build.Jar, ExternalProgram, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.LocalProgram))
2220+
@typed_pos_args('benchmark', str, (build.Executable, build.Jar, Program, mesonlib.File, build.CustomTarget, build.CustomTargetIndex))
22212221
@typed_kwargs('benchmark', *TEST_KWS)
22222222
def func_benchmark(self, node: mparser.BaseNode,
2223-
args: T.Tuple[str, T.Union[build.Executable, build.Jar, ExternalProgram, mesonlib.File, build.LocalProgram]],
2223+
args: T.Tuple[str, T.Union[build.Executable, build.Jar, Program, mesonlib.File]],
22242224
kwargs: 'kwtypes.FuncBenchmark') -> None:
22252225
self.add_test(node, args, kwargs, False)
22262226

2227-
@typed_pos_args('test', str, (build.Executable, build.Jar, ExternalProgram, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.LocalProgram))
2227+
@typed_pos_args('test', str, (build.Executable, build.Jar, Program, mesonlib.File, build.CustomTarget, build.CustomTargetIndex))
22282228
@typed_kwargs('test', *TEST_KWS, KwargInfo('is_parallel', bool, default=True))
22292229
def func_test(self, node: mparser.BaseNode,
2230-
args: T.Tuple[str, T.Union[build.Executable, build.Jar, ExternalProgram, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.LocalProgram]],
2230+
args: T.Tuple[str, T.Union[build.Executable, build.Jar, Program, mesonlib.File]],
22312231
kwargs: 'kwtypes.FuncTest') -> None:
22322232
self.add_test(node, args, kwargs, True)
22332233

@@ -2241,7 +2241,7 @@ def unpack_env_kwarg(self, kwargs: T.Union[EnvironmentVariables, T.Dict[str, 'TY
22412241
return ENV_KW.convertor(envlist)
22422242

22432243
def make_test(self, node: mparser.BaseNode,
2244-
args: T.Tuple[str, T.Union[build.Executable, build.Jar, ExternalProgram, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.LocalProgram]],
2244+
args: T.Tuple[str, T.Union[build.Executable, build.Jar, Program, mesonlib.File, build.CustomTarget, build.CustomTargetIndex]],
22452245
kwargs: 'kwtypes.BaseTest',
22462246
klass: T.Type[TestClass] = Test) -> TestClass:
22472247
name = args[0]
@@ -2619,7 +2619,7 @@ def validate_build_subdir(self, build_subdir: str, target: str):
26192619
KwargInfo('capture', bool, default=False, since='0.41.0'),
26202620
KwargInfo(
26212621
'command',
2622-
(ContainerTypeInfo(list, (build.Executable, ExternalProgram, compilers.Compiler, mesonlib.File, str, build.LocalProgram), allow_empty=False), NoneType),
2622+
(ContainerTypeInfo(list, (build.Executable, Program, compilers.Compiler, mesonlib.File, str)), NoneType),
26232623
listify=True,
26242624
),
26252625
KwargInfo(

mesonbuild/interpreter/interpreterobjects.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
flatten, resolve_second_level_holders, InterpreterException, InvalidArguments, InvalidCode)
2424
from ..interpreter.type_checking import NoneType, ENV_KW, ENV_SEPARATOR_KW, PKGCONFIG_DEFINE_KW
2525
from ..dependencies import Dependency, ExternalLibrary, InternalDependency
26-
from ..programs import ExternalProgram, BaseProgram
26+
from ..programs import ExternalProgram, Program
2727
from ..mesonlib import HoldableObject, listify, Popen_safe
2828

2929
import typing as T
@@ -633,10 +633,9 @@ def as_shared_method(self, args: T.List[TYPE_var], kwargs: InternalDependencyAsK
633633
raise InterpreterException('as_shared method is only supported on declare_dependency() objects')
634634
return self.held_object.get_as_shared(kwargs['recursive'])
635635

636-
_BASEPROG = T.TypeVar('_BASEPROG', bound=BaseProgram)
637636

638-
class BaseProgramHolder(ObjectHolder[_BASEPROG]):
639-
def __init__(self, ep: _BASEPROG, interpreter: 'Interpreter') -> None:
637+
class ProgramHolder(ObjectHolder[Program]):
638+
def __init__(self, ep: Program, interpreter: 'Interpreter') -> None:
640639
super().__init__(ep, interpreter)
641640

642641
@noPosargs

mesonbuild/interpreter/kwargs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ..mesonlib import EnvironmentVariables, MachineChoice, File, FileMode, FileOrString
1717
from ..options import OptionKey
1818
from ..modules.cmake import CMakeSubprojectOptions
19-
from ..programs import ExternalProgram
19+
from ..programs import ExternalProgram, Program
2020
from .type_checking import PkgConfigDefineType, SourcesVarargsType
2121

2222
TestArgs = T.Union[str, File, build.Target, ExternalProgram]
@@ -171,8 +171,7 @@ class FuncAddLanguages(ExtractRequired):
171171

172172
class RunTarget(TypedDict):
173173

174-
command: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, ExternalProgram,
175-
File, build.LocalProgram]]
174+
command: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, Program, File]]
176175
depends: T.List[T.Union[build.BuildTarget, build.CustomTarget]]
177176
env: EnvironmentVariables
178177

@@ -184,7 +183,7 @@ class CustomTarget(TypedDict):
184183
build_by_default: T.Optional[bool]
185184
build_subdir: str
186185
capture: bool
187-
command: T.List[T.Union[str, build.BuildTargetTypes, ExternalProgram, File, build.LocalProgram]]
186+
command: T.List[T.Union[str, build.BuildTargetTypes, Program, File]]
188187
console: bool
189188
depend_files: T.List[FileOrString]
190189
depends: T.List[T.Union[build.BuildTarget, build.CustomTarget]]

0 commit comments

Comments
 (0)