Skip to content

Commit 6f4f39a

Browse files
committed
Move submodule lookup to Builder
1 parent 688c30d commit 6f4f39a

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

src/bootstrap/src/core/builder.rs

+32-23
Original file line numberDiff line numberDiff line change
@@ -554,29 +554,7 @@ impl<'a> ShouldRun<'a> {
554554
///
555555
/// [`path`]: ShouldRun::path
556556
pub fn paths(mut self, paths: &[&str]) -> Self {
557-
static SUBMODULES_PATHS: OnceLock<Vec<String>> = OnceLock::new();
558-
559-
let init_submodules_paths = |src: &PathBuf| {
560-
let file = File::open(src.join(".gitmodules")).unwrap();
561-
562-
let mut submodules_paths = vec![];
563-
for line in BufReader::new(file).lines() {
564-
if let Ok(line) = line {
565-
let line = line.trim();
566-
567-
if line.starts_with("path") {
568-
let actual_path =
569-
line.split(' ').last().expect("Couldn't get value of path");
570-
submodules_paths.push(actual_path.to_owned());
571-
}
572-
}
573-
}
574-
575-
submodules_paths
576-
};
577-
578-
let submodules_paths =
579-
SUBMODULES_PATHS.get_or_init(|| init_submodules_paths(&self.builder.src));
557+
let submodules_paths = self.builder.get_all_submodules();
580558

581559
self.paths.insert(PathSet::Set(
582560
paths
@@ -2151,6 +2129,37 @@ impl<'a> Builder<'a> {
21512129
out
21522130
}
21532131

2132+
/// Return paths of all submodules managed by git.
2133+
/// If the current checkout is not managed by git, returns an empty slice.
2134+
pub fn get_all_submodules(&self) -> &[String] {
2135+
if !self.rust_info().is_managed_git_subrepository() {
2136+
return &[];
2137+
}
2138+
2139+
static SUBMODULES_PATHS: OnceLock<Vec<String>> = OnceLock::new();
2140+
2141+
let init_submodules_paths = |src: &PathBuf| {
2142+
let file = File::open(src.join(".gitmodules")).unwrap();
2143+
2144+
let mut submodules_paths = vec![];
2145+
for line in BufReader::new(file).lines() {
2146+
if let Ok(line) = line {
2147+
let line = line.trim();
2148+
2149+
if line.starts_with("path") {
2150+
let actual_path =
2151+
line.split(' ').last().expect("Couldn't get value of path");
2152+
submodules_paths.push(actual_path.to_owned());
2153+
}
2154+
}
2155+
}
2156+
2157+
submodules_paths
2158+
};
2159+
2160+
&SUBMODULES_PATHS.get_or_init(|| init_submodules_paths(&self.src))
2161+
}
2162+
21542163
/// Ensure that a given step is built *only if it's supposed to be built by default*, returning
21552164
/// its output. This will cache the step, so it's safe (and good!) to call this as often as
21562165
/// needed to ensure that all dependencies are build.

0 commit comments

Comments
 (0)