Skip to content

Commit

Permalink
compilers: Allow setting env and workdir for run checks
Browse files Browse the repository at this point in the history
This is not exposed in API, but will be used internally.
  • Loading branch information
xclaesse committed Mar 15, 2024
1 parent b1358ef commit 6b56952
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,9 @@ def has_header_symbol(self, hname: str, symbol: str, prefix: str,

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.')
Expand All @@ -638,7 +640,7 @@ def run(self, code: 'mesonlib.FileOrString', env: 'Environment',
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)
Expand Down
6 changes: 4 additions & 2 deletions mesonbuild/compilers/d.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,11 @@ def _get_compile_extra_args(self, extra_args: T.Union[T.List[str], T.Callable[[C

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,
Expand Down

0 comments on commit 6b56952

Please sign in to comment.