Commit c35d024b authored by Manuel Argüelles's avatar Manuel Argüelles Committed by Martí Bolívar
Browse files

west: core: add search path argument to require()



Allow the runners to override the default search path, e.g. when
provided through command line. The default is to search for the program
binary on the system PATH.

This is useful when the runner allows to optionally override the search
path of the tool, in the case there are multiple versions or
installations, and not necessarily the tools path are present in the
system PATH environment variable. For example:
`tool = self.require(tool_name, path=args.tool_path_override)`

Signed-off-by: default avatarManuel Argüelles <manuel.arguelles@nxp.com>
parent 467ce894
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -658,19 +658,21 @@ class ZephyrBinaryRunner(abc.ABC):
                  in the order they appear on the command line.'''

    @staticmethod
    def require(program: str) -> str:
    def require(program: str, path: Optional[str] = None) -> str:
        '''Require that a program is installed before proceeding.

        :param program: name of the program that is required,
                        or path to a program binary.
        :param path:    PATH where to search for the program binary.
                        By default check on the system PATH.

        If ``program`` is an absolute path to an existing program
        binary, this call succeeds. Otherwise, try to find the program
        by name on the system PATH.
        by name on the system PATH or in the given PATH, if provided.

        If the program can be found, its path is returned.
        Otherwise, raises MissingProgram.'''
        ret = shutil.which(program)
        ret = shutil.which(program, path=path)
        if ret is None:
            raise MissingProgram(program)
        return ret