MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / find_build_dirs

Function find_build_dirs

crates/memtrack/src/allocators/static_linked.rs:22–82  ·  view source on GitHub ↗

Walk upward and downward from current directory to find build directories. Returns all found build directories in order of preference.

()

Source from the content-addressed store, hash-verified

20/// Walk upward and downward from current directory to find build directories.
21/// Returns all found build directories in order of preference.
22fn find_build_dirs() -> Vec<PathBuf> {
23 let mut dirs = Vec::new();
24 let Ok(current_dir) = std::env::current_dir() else {
25 return dirs;
26 };
27
28 let patterns = ["target/codspeed/analysis", "bazel-bin", "build"];
29 let mut check_patterns = |dir: &Path| {
30 for pattern in &patterns {
31 let path = dir.join(pattern);
32 if path.is_dir() {
33 dirs.push(path);
34 }
35 }
36 };
37
38 // Walk upward from parent directories
39 // Note: We skip current_dir here since the downward walk (below) already checks it
40 let mut current = current_dir.clone();
41 while current.pop() {
42 check_patterns(&current);
43 }
44
45 // Walk downward from current directory
46 let mut stack = vec![current_dir];
47 while let Some(dir) = stack.pop() {
48 check_patterns(&dir);
49
50 // Read subdirectories
51 let Ok(entries) = fs::read_dir(&dir) else {
52 continue;
53 };
54
55 for entry in entries.filter_map(Result::ok) {
56 let path = entry.path();
57
58 let Some(name) = path.file_name().and_then(|n| n.to_str()) else {
59 continue;
60 };
61
62 // Skip hidden dirs and common excludes
63 if name.starts_with('.') || matches!(name, "node_modules" | "vendor" | "venv") {
64 continue;
65 }
66
67 // Don't recursive into dirs that we want to match.
68 // This can happen with `target` as it contains build dirs for statically linked crates.
69 if matches!(name, "target" | "bazel-bin" | "build") {
70 continue;
71 }
72
73 if path.is_file() {
74 continue;
75 }
76
77 stack.push(path);
78 }
79 }

Callers 1

find_allFunction · 0.85

Calls 2

pathMethod · 0.80
file_nameMethod · 0.80

Tested by

no test coverage detected