Skip to content

Commit 0f4ca79

Browse files
committed
submodule detection for proper fix on #96188
This commit resolves an internal FIXME note within the bootstrap by implementing submodule detection. This is accomplished through an iterative process over the `.gitmodules` file. Signed-off-by: ozkanonur <[email protected]>
1 parent 540a50d commit 0f4ca79

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

src/bootstrap/Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ dependencies = [
4545
"hex",
4646
"ignore",
4747
"is-terminal",
48+
"lazy_static",
4849
"libc",
4950
"object",
5051
"once_cell",

src/bootstrap/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ cmake = "0.1.38"
3636
filetime = "0.2"
3737
getopts = "0.2.19"
3838
cc = "1.0.69"
39+
lazy_static = "1"
3940
libc = "0.2"
4041
hex = "0.4"
4142
object = { version = "0.29.0", default-features = false, features = ["archive", "coff", "read_core", "unaligned"] }

src/bootstrap/builder.rs

+35-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use std::collections::BTreeSet;
44
use std::env;
55
use std::ffi::OsStr;
66
use std::fmt::{Debug, Write};
7-
use std::fs::{self};
7+
use std::fs::{self, File};
88
use std::hash::Hash;
9+
use std::io::{BufRead, BufReader};
910
use std::ops::Deref;
1011
use std::path::{Component, Path, PathBuf};
1112
use std::process::Command;
@@ -484,17 +485,43 @@ impl<'a> ShouldRun<'a> {
484485

485486
// multiple aliases for the same job
486487
pub fn paths(mut self, paths: &[&str]) -> Self {
488+
lazy_static::lazy_static! {
489+
static ref SUBMODULES_PATHS: Vec<String> = get_submodules_paths();
490+
}
491+
492+
fn get_submodules_paths() -> Vec<String> {
493+
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
494+
let src = manifest_dir.ancestors().nth(2).unwrap();
495+
let file = File::open(src.join(".gitmodules")).unwrap();
496+
497+
let mut submodules_paths = vec![];
498+
for line in BufReader::new(file).lines() {
499+
if let Ok(line) = line {
500+
let line = line.trim();
501+
502+
if line.starts_with("path") {
503+
let actual_path = line.split(' ').last().unwrap();
504+
submodules_paths.push(actual_path.to_owned());
505+
}
506+
}
507+
}
508+
509+
submodules_paths
510+
}
511+
487512
self.paths.insert(PathSet::Set(
488513
paths
489514
.iter()
490515
.map(|p| {
491-
// FIXME(#96188): make sure this is actually a path.
492-
// This currently breaks for paths within submodules.
493-
//assert!(
494-
// self.builder.src.join(p).exists(),
495-
// "`should_run.paths` should correspond to real on-disk paths - use `alias` if there is no relevant path: {}",
496-
// p
497-
//);
516+
// assert only if `p` isn't submodule
517+
if !SUBMODULES_PATHS.iter().find(|sm_p| p.contains(*sm_p)).is_some() {
518+
assert!(
519+
self.builder.src.join(p).exists(),
520+
"`should_run.paths` should correspond to real on-disk paths - use `alias` if there is no relevant path: {}",
521+
p
522+
);
523+
}
524+
498525
TaskPath { path: p.into(), kind: Some(self.kind) }
499526
})
500527
.collect(),

0 commit comments

Comments
 (0)