def find_port_file()

in src/advisor/helpers/find_port.py [0:0]


def find_port_file(filename, other_files, other_files_dirs=None):
    """Given a filename file searches other_files for a file that may
    be an aarch64 port of file.

    Args:
        file (str): The file to find the port for.
        other_files (list): The list of files to search through for the port.
        other_files_dirs (set, optional): The set of directories containing
        the files in other_files.

    Returns:
        str: A file name that may be an aarch64 port of file, or Nine.

    Examples:
        >>> find_port_file('/work/app/source/kernel-otherarch.c',
                           ['/work/app/source/common.c',
                            '/work/app/source/kernel-aarch64.c'],
                           ['/work/app/source'])
        '/work/app/source/kernel-aarch64.c'
    """
    head, tail = os.path.split(filename)
    filenames = port_filenames(tail)
    for port_filename in filenames:
        port_path = os.path.join(head, port_filename)
        if port_path in other_files:
            return port_path
    if not other_files_dirs:
        other_files_dirs = set()
        for file in other_files:
            other_files_dirs.add(os.path.dirname(file))
    port_dir = find_port_dir(head, other_files_dirs)
    if port_dir:
        return os.path.join(port_dir, tail)
    return None