Skip to content

Commit

Permalink
fix parsing for rustc -Z ls
Browse files Browse the repository at this point in the history
The linked PR in the comment changed the output format, but never
bothered to change sccache to match the new output format.  So when we
stumbled across a case of the new output format, we panicked.
  • Loading branch information
froydnj committed May 22, 2020
1 parent e54bbaa commit 35ea08f
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2270,14 +2270,18 @@ fn parse_rustc_z_ls(stdout: &str) -> Result<Vec<&str>> {
assert!(line_splits.next().is_none());

let mut libstring_splits = libstring.rsplitn(2, '-');
// Rustc prints strict hash value (rather than extra filename as it likely should be)
// https://github.com/rust-lang/rust/pull/55555
let _svh = libstring_splits
.next()
.ok_or_else(|| "No hash in lib string from rustc -Z ls")?;
let libname = libstring_splits
.next()
.expect("Zero strings from libstring split");
// Most things get printed as ${LIBNAME}-${HASH} but for some things
// (native code-only libraries?), ${LIBNAME} is all you get.
let libname = {
let maybe_hash = libstring_splits
.next()
.ok_or_else(|| "Nothing in lib string from `rustc -Z ls`")?;
if let Some(name) = libstring_splits.next() {
name
} else {
maybe_hash
}
};
assert!(libstring_splits.next().is_none());

dep_names.push(libname);
Expand Down Expand Up @@ -2852,6 +2856,25 @@ c:/foo/bar.rs:
);
}

#[cfg(feature = "dist-client")]
#[test]
fn test_parse_rustc_z_ls() {
let output = "=External Dependencies=
1 lucet_runtime
2 lucet_runtime_internals-1ff6232b6940e924
3 lucet_runtime_macros-c18e1952b835769e
";
let res = parse_rustc_z_ls(&output);
assert!(res.is_ok());
let res = res.unwrap();
assert_eq!(res.len(), 3);
assert_eq!(res[0], "lucet_runtime");
assert_eq!(res[1], "lucet_runtime_internals");
assert_eq!(res[2], "lucet_runtime_macros");
}

fn mock_dep_info(creator: &Arc<Mutex<MockCommandCreator>>, dep_srcs: &[&str]) {
// Mock the `rustc --emit=dep-info` process by writing
// a dep-info file.
Expand Down

0 comments on commit 35ea08f

Please sign in to comment.