code: def scan_build_files(project_tree, base_relpath, build_ignore_patterns=None):
      
      if base_relpath and os.path.isabs(base_relpath):
        raise BuildFile.BadPathError('base_relpath parameter ({}) should be a relative path.'
                                     .format(base_relpath))
      if base_relpath and not project_tree.isdir(base_relpath):
        raise BuildFile.BadPathError('Can only scan directories and {0} is not a valid dir.'
                                     .format(base_relpath))
      if build_ignore_patterns and not isinstance(build_ignore_patterns, PathSpec):
        raise TypeError("build_ignore_patterns should be pathspec.pathspec.PathSpec instance, "
                        "instead {} was given.".format(type(build_ignore_patterns)))
  
      build_files = set()
      for root, dirs, files in project_tree.walk(base_relpath or '', topdown=True):
        excluded_dirs = list(build_ignore_patterns.match_files('{}/'.format(os.path.join(root, dirname))
                                                            for dirname in dirs))
        for subdir in excluded_dirs:
          # Remove trailing '/' from paths which were added to indicate that paths are paths to directories.
          dirs.remove(fast_relpath(subdir, root)[:-1])
        for filename in files:
          if BuildFile._is_buildfile_name(filename):
            build_files.add(os.path.join(root, filename))
  
      return BuildFile._build_files_from_paths(project_tree, build_files, build_ignore_patterns)
docs: Looks for all BUILD files
      :param project_tree: Project tree to scan in.
      :type project_tree: :class:`pants.base.project_tree.ProjectTree`
      :param base_relpath: Directory under root_dir to scan.
      :param build_ignore_patterns: .gitignore like patterns to exclude from BUILD files scan.
      :type build_ignore_patterns: pathspec.pathspec.PathSpec