Fix full ids for files to match common spec

This commit is contained in:
Nick Rolfe
2020-10-30 12:45:23 +00:00
parent 7f03206b52
commit 79d15051be

View File

@@ -46,7 +46,7 @@ impl Extractor {
source: &source,
trap_output: vec![
TrapEntry::Comment(format!("Auto-generated TRAP file for {}", path.display())),
TrapEntry::MapLabelToKey(file_label, path_string.clone()),
TrapEntry::MapLabelToKey(file_label, full_id_for_file(path)),
TrapEntry::GenericTuple(
"files".to_owned(),
vec![
@@ -73,6 +73,25 @@ impl Extractor {
}
}
fn full_id_for_file(path: &Path) -> String {
let full_id = format!("{};sourcefile", path.display());
if cfg!(windows) {
// Strip the Windows long path prefix, since std::fs::canonicalize adds it,
// but it's not part of the common CodeQL spec for file ids.
let win_long_path_prefix = r"\\?\";
let full_id = match full_id.strip_prefix(win_long_path_prefix) {
Some(s) => s.to_owned(),
None => full_id,
};
// And replace backslashes with forward slashes.
full_id.replace(r"\", "/")
} else {
full_id
}
}
fn build_schema_lookup<'a>(schema: &'a Vec<Entry>) -> Map<&'a TypeName, &'a Entry> {
let mut map = std::collections::BTreeMap::new();
for entry in schema {