from pathlib import Path


def _get_buildkit_copy(package, pkgmeta):
    """
    Returns a pathlib.Path relative to the output directory to copy buildkit and bundles to,
        otherwise returns None if buildkit does not need to be copied.
    """
    while package:
        if package in pkgmeta:
            if 'buildkit_copy' in pkgmeta[package]:
                return Path(pkgmeta[package]['buildkit_copy'])
            if 'depends' in pkgmeta[package]:
                package = pkgmeta[package]['depends']
            else:
                break
        else:
            break
    return None