Remove useless EmptyExternalProgram

It is only used by Environment.get_exe_wrapper() and every callers were
handling None already. Type annotation was wrong, it already could
return None for the case an exe wrapper is needed but none is provided.
pull/10990/head
Xavier Claessens 2 years ago
parent 302a29593a
commit 548c9adad4
  1. 5
      mesonbuild/backend/backends.py
  2. 8
      mesonbuild/environment.py
  3. 5
      mesonbuild/modules/gnome.py
  4. 19
      mesonbuild/programs.py

@ -1108,10 +1108,7 @@ class Backend:
break
is_cross = self.environment.is_cross_build(test_for_machine)
if is_cross and self.environment.need_exe_wrapper():
exe_wrapper = self.environment.get_exe_wrapper()
else:
exe_wrapper = None
exe_wrapper = self.environment.get_exe_wrapper()
machine = self.environment.machines[exe.for_machine]
if machine.is_windows() or machine.is_cygwin():
extra_bdeps: T.List[T.Union[build.BuildTarget, build.CustomTarget]] = []

@ -25,9 +25,7 @@ from .mesonlib import (
search_version, MesonBugException
)
from . import mlog
from .programs import (
ExternalProgram, EmptyExternalProgram
)
from .programs import ExternalProgram
from .envconfig import (
BinaryTable, MachineInfo, Properties, known_cpu_families, CMakeVariables,
@ -852,7 +850,7 @@ class Environment:
return value
return not machine_info_can_run(self.machines[for_machine])
def get_exe_wrapper(self) -> ExternalProgram:
def get_exe_wrapper(self) -> T.Optional[ExternalProgram]:
if not self.need_exe_wrapper():
return EmptyExternalProgram()
return None
return self.exe_wrapper

@ -39,7 +39,7 @@ from ..interpreterbase.decorators import typed_pos_args
from ..mesonlib import (
MachineChoice, MesonException, OrderedSet, Popen_safe, join_args,
)
from ..programs import OverrideProgram, EmptyExternalProgram
from ..programs import OverrideProgram
from ..scripts.gettext import read_linguas
if T.TYPE_CHECKING:
@ -1464,9 +1464,8 @@ class GnomeModule(ExtensionModule):
t_args.append(f'--{program_name}={path}')
if namespace:
t_args.append('--namespace=' + namespace)
# if not need_exe_wrapper, we get an EmptyExternalProgram. If none provided, we get NoneType
exe_wrapper = state.environment.get_exe_wrapper()
if not isinstance(exe_wrapper, (NoneType, EmptyExternalProgram)):
if exe_wrapper:
t_args.append('--run=' + ' '.join(exe_wrapper.get_command()))
t_args.append(f'--htmlargs={"@@".join(kwargs["html_args"])}')
t_args.append(f'--scanargs={"@@".join(kwargs["scan_args"])}')

@ -345,25 +345,6 @@ class NonExistingExternalProgram(ExternalProgram): # lgtm [py/missing-call-to-i
return False
class EmptyExternalProgram(ExternalProgram): # lgtm [py/missing-call-to-init]
'''
A program object that returns an empty list of commands. Used for cases
such as a cross file exe_wrapper to represent that it's not required.
'''
def __init__(self) -> None:
self.name = None
self.command = []
self.path = None
def __repr__(self) -> str:
r = '<{} {!r} -> {!r}>'
return r.format(self.__class__.__name__, self.name, self.command)
def found(self) -> bool:
return True
class OverrideProgram(ExternalProgram):
"""A script overriding a program."""

Loading…
Cancel
Save