Move submodule lookup to Builder
This commit is contained in:
parent
688c30dc9f
commit
6f4f39a8d5
1 changed files with 32 additions and 23 deletions
|
@ -554,29 +554,7 @@ impl<'a> ShouldRun<'a> {
|
||||||
///
|
///
|
||||||
/// [`path`]: ShouldRun::path
|
/// [`path`]: ShouldRun::path
|
||||||
pub fn paths(mut self, paths: &[&str]) -> Self {
|
pub fn paths(mut self, paths: &[&str]) -> Self {
|
||||||
static SUBMODULES_PATHS: OnceLock<Vec<String>> = OnceLock::new();
|
let submodules_paths = self.builder.get_all_submodules();
|
||||||
|
|
||||||
let init_submodules_paths = |src: &PathBuf| {
|
|
||||||
let file = File::open(src.join(".gitmodules")).unwrap();
|
|
||||||
|
|
||||||
let mut submodules_paths = vec![];
|
|
||||||
for line in BufReader::new(file).lines() {
|
|
||||||
if let Ok(line) = line {
|
|
||||||
let line = line.trim();
|
|
||||||
|
|
||||||
if line.starts_with("path") {
|
|
||||||
let actual_path =
|
|
||||||
line.split(' ').last().expect("Couldn't get value of path");
|
|
||||||
submodules_paths.push(actual_path.to_owned());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
submodules_paths
|
|
||||||
};
|
|
||||||
|
|
||||||
let submodules_paths =
|
|
||||||
SUBMODULES_PATHS.get_or_init(|| init_submodules_paths(&self.builder.src));
|
|
||||||
|
|
||||||
self.paths.insert(PathSet::Set(
|
self.paths.insert(PathSet::Set(
|
||||||
paths
|
paths
|
||||||
|
@ -2151,6 +2129,37 @@ impl<'a> Builder<'a> {
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return paths of all submodules managed by git.
|
||||||
|
/// If the current checkout is not managed by git, returns an empty slice.
|
||||||
|
pub fn get_all_submodules(&self) -> &[String] {
|
||||||
|
if !self.rust_info().is_managed_git_subrepository() {
|
||||||
|
return &[];
|
||||||
|
}
|
||||||
|
|
||||||
|
static SUBMODULES_PATHS: OnceLock<Vec<String>> = OnceLock::new();
|
||||||
|
|
||||||
|
let init_submodules_paths = |src: &PathBuf| {
|
||||||
|
let file = File::open(src.join(".gitmodules")).unwrap();
|
||||||
|
|
||||||
|
let mut submodules_paths = vec![];
|
||||||
|
for line in BufReader::new(file).lines() {
|
||||||
|
if let Ok(line) = line {
|
||||||
|
let line = line.trim();
|
||||||
|
|
||||||
|
if line.starts_with("path") {
|
||||||
|
let actual_path =
|
||||||
|
line.split(' ').last().expect("Couldn't get value of path");
|
||||||
|
submodules_paths.push(actual_path.to_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
submodules_paths
|
||||||
|
};
|
||||||
|
|
||||||
|
&SUBMODULES_PATHS.get_or_init(|| init_submodules_paths(&self.src))
|
||||||
|
}
|
||||||
|
|
||||||
/// Ensure that a given step is built *only if it's supposed to be built by default*, returning
|
/// Ensure that a given step is built *only if it's supposed to be built by default*, returning
|
||||||
/// its output. This will cache the step, so it's safe (and good!) to call this as often as
|
/// its output. This will cache the step, so it's safe (and good!) to call this as often as
|
||||||
/// needed to ensure that all dependencies are build.
|
/// needed to ensure that all dependencies are build.
|
||||||
|
|
Loading…
Add table
Reference in a new issue