Skip to content

Commit a268df3

Browse files
committed
refactor to ingest old format but keep some of the prior changes
1 parent 3dc4508 commit a268df3

File tree

1 file changed

+25
-26
lines changed
  • src/cargo/core/compiler/fingerprint

1 file changed

+25
-26
lines changed

src/cargo/core/compiler/fingerprint/mod.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ pub fn translate_dep_info(
22152215
#[derive(Default)]
22162216
pub struct RustcDepInfo {
22172217
/// The list of files that the main target in the dep-info file depends on.
2218-
pub files: Vec<(PathBuf, Option<(u64, Checksum)>)>,
2218+
pub files: HashMap<PathBuf, Option<(u64, Checksum)>>,
22192219
/// The list of environment variables we found that the rustc compilation
22202220
/// depends on.
22212221
///
@@ -2379,38 +2379,37 @@ pub fn parse_rustc_dep_info(rustc_dep_info: &Path) -> CargoResult<RustcDepInfo>
23792379
if found_deps {
23802380
continue;
23812381
}
2382-
let mut parsing_checksum_index = None;
2383-
let mut last_seen_checksum = None;
23842382
found_deps = true;
23852383
let mut deps = line[pos + 2..].split_whitespace();
23862384

23872385
while let Some(s) = deps.next() {
2388-
let mut word = s.to_string();
2389-
if word == "#" {
2390-
parsing_checksum_index = Some(0);
2391-
continue;
2392-
}
2393-
while word.ends_with('\\') {
2394-
word.pop();
2395-
word.push(' ');
2396-
word.push_str(deps.next().ok_or_else(|| {
2386+
let mut file = s.to_string();
2387+
while file.ends_with('\\') {
2388+
file.pop();
2389+
file.push(' ');
2390+
file.push_str(deps.next().ok_or_else(|| {
23972391
internal("malformed dep-info format, trailing \\".to_string())
23982392
})?);
23992393
}
2400-
if let Some(parsing_checksum_index) = parsing_checksum_index.as_mut() {
2401-
// By now files list is built, checksum data is provided in the same order as
2402-
// the file list
2403-
if let Some(checksum) = word.strip_prefix("checksum:") {
2404-
last_seen_checksum = Some(Checksum::from_str(checksum)?);
2405-
} else if let Some(file_len) = word.strip_prefix("file_len:") {
2406-
let file_len = file_len.parse::<u64>()?;
2407-
let file_entry = &mut ret.files[*parsing_checksum_index];
2408-
file_entry.1 = last_seen_checksum.take().map(|c| (file_len, c));
2409-
*parsing_checksum_index += 1;
2410-
}
2411-
} else {
2412-
ret.files.push((word.into(), None));
2413-
}
2394+
ret.files.insert(file.into(), None);
2395+
}
2396+
} else if let Some(rest) = line.strip_prefix("# checksum:") {
2397+
let mut parts = rest.splitn(3, ' ');
2398+
let Some(checksum) = parts.next().map(Checksum::from_str).transpose()? else {
2399+
continue;
2400+
};
2401+
let Some(Ok(file_len)) = parts
2402+
.next()
2403+
.and_then(|s| s.strip_prefix("file_len:").map(|s| s.parse::<u64>()))
2404+
else {
2405+
continue;
2406+
};
2407+
let Some(path) = parts.next().map(PathBuf::from) else {
2408+
continue;
2409+
};
2410+
2411+
if let Some(entry) = ret.files.get_mut(&path) {
2412+
*entry = Some((file_len, checksum));
24142413
}
24152414
}
24162415
}

0 commit comments

Comments
 (0)