def all_roots(source_root_config: SourceRootConfig) -> AllSourceRoots: source_roots = source_root_config.get_source_roots() all_paths: Set[str] = set() for path in source_roots.traverse(): if path.startswith("^/"): all_paths.add(f"{path[2:]}/") else: all_paths.add(f"**/{path}/") snapshot = yield Get(Snapshot, PathGlobs(include=tuple(all_paths))) all_source_roots: Set[SourceRoot] = set() # The globs above can match on subdirectories of the source roots. # For instance, `src/*/` might match 'src/rust/' as well as # 'src/rust/engine/process_execution/bazel_protos/src/gen'. # So we use find_by_path to verify every candidate source root. for directory in snapshot.dirs: match: SourceRoot = source_roots.find_by_path(directory) if match: all_source_roots.add(match) yield AllSourceRoots(all_source_roots)
async def all_roots(source_root_config: SourceRootConfig) -> AllSourceRoots: source_root_pattern_matcher = source_root_config.get_pattern_matcher() # Create globs corresponding to all source root patterns. all_paths: Set[str] = set() for path in source_root_pattern_matcher.get_patterns(): if path == "/": all_paths.add("**") elif path.startswith("/"): all_paths.add(f"{path[1:]}/") else: all_paths.add(f"**/{path}/") # Match the patterns against actual files, to find the roots that actually exist. snapshot = await Get[Snapshot](PathGlobs(globs=sorted(all_paths))) responses = await MultiGet( Get[OptionalSourceRoot](SourceRootRequest(PurePath(d))) for d in snapshot.dirs ) all_source_roots = { response.source_root for response in responses if response.source_root is not None } return AllSourceRoots(all_source_roots)