compilers: Allow setting env and workdir for run checks

This is not exposed in API, but will be used internally.
pull/12983/head
Xavier Claessens 1 year ago committed by Xavier Claessens
parent b1358ef61f
commit 6b569527bc
  1. 6
      mesonbuild/compilers/compilers.py
  2. 6
      mesonbuild/compilers/d.py

@ -625,7 +625,9 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
def run(self, code: 'mesonlib.FileOrString', env: 'Environment',
extra_args: T.Union[T.List[str], T.Callable[[CompileCheckMode], T.List[str]], None] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> RunResult:
dependencies: T.Optional[T.List['Dependency']] = None,
run_env: T.Optional[T.Dict[str, str]] = None,
run_cwd: T.Optional[str] = None) -> RunResult:
need_exe_wrapper = env.need_exe_wrapper(self.for_machine)
if need_exe_wrapper and self.exe_wrapper is None:
raise CrossNoRunException('Can not run test applications in this cross environment.')
@ -638,7 +640,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
else:
cmdlist = [p.output_name]
try:
pe, so, se = mesonlib.Popen_safe(cmdlist)
pe, so, se = mesonlib.Popen_safe(cmdlist, env=run_env, cwd=run_cwd)
except Exception as e:
mlog.debug(f'Could not run: {cmdlist} (error: {e})\n')
return RunResult(False)

@ -572,9 +572,11 @@ class DCompiler(Compiler):
def run(self, code: 'mesonlib.FileOrString', env: 'Environment',
extra_args: T.Union[T.List[str], T.Callable[[CompileCheckMode], T.List[str]], None] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> compilers.RunResult:
dependencies: T.Optional[T.List['Dependency']] = None,
run_env: T.Optional[T.Dict[str, str]] = None,
run_cwd: T.Optional[str] = None) -> compilers.RunResult:
extra_args = self._get_compile_extra_args(extra_args)
return super().run(code, env, extra_args, dependencies)
return super().run(code, env, extra_args, dependencies, run_env, run_cwd)
def sizeof(self, typename: str, prefix: str, env: 'Environment', *,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,

Loading…
Cancel
Save