def _prune_folders(folders, includes, excludes):
    """
    Given a list of folders, return a copy of it that includes just the folders
    that should be considered part of the build based on the given list of
    include and exclude patterns.

    The filters are applied in the order: "include, exclude" such that if there
    are no includes, we assume that everything is included by default.
    """
    result = []
    for folder in folders:
        if not includes or folder in includes:
            if folder not in excludes:
                result.append(folder)

    return result