This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
203: add --shorten-paths r=jonas-schievink a=japaric this flags compresses the paths to crates.io dependencies from full paths to the format `[$cratename-$crateversion]/src/module/file.rs` cc #66 --- before: ``` console $ cargo rb hello (..) stack backtrace: (..) 4: main at src/bin/hello.rs:6:1 5: ResetTrampoline at /home/japaric/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs:547:26 6: Reset at /home/japaric/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs:550:13 ``` after: ``` console $ cargo rb hello (..) stack backtrace: (..) 4: main at src/bin/hello.rs:6:1 5: ResetTrampoline at [cortex-m-rt-0.6.13]/src/lib.rs:547:26 6: Reset at [cortex-m-rt-0.6.13]/src/lib.rs:550:13 ``` currently only paths in the backtrace are modify (because that was the easiest thing to implement / test) TODO: - [x] also compress paths in defmt logs Co-authored-by: Jorge Aparicio <[email protected]>
- Loading branch information
Showing
4 changed files
with
81 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::path::Path; | ||
|
||
pub(crate) fn shorten_paths(path: &Path) -> String { | ||
if let Some(dep) = Dependency::from_path(path) { | ||
format!("[{}]/{}", dep.name_version, dep.path.display()) | ||
} else { | ||
path.display().to_string() | ||
} | ||
} | ||
|
||
struct Dependency<'p> { | ||
name_version: &'p str, | ||
path: &'p Path, | ||
} | ||
|
||
impl<'p> Dependency<'p> { | ||
// as of Rust 1.52.1 this path looks like this on Linux | ||
// /home/some-user/.cargo/registry/src/jackfan.us.kg-0123456789abcdef/crate-name-0.1.2/src/lib.rs | ||
// on Windows the `/home/some-user` part becomes something else | ||
fn from_path(path: &'p Path) -> Option<Self> { | ||
if !path.is_absolute() { | ||
return None; | ||
} | ||
|
||
let mut components = path.components(); | ||
let _registry = components.find(|component| match component { | ||
std::path::Component::Normal(component) => *component == "registry", | ||
_ => false, | ||
})?; | ||
|
||
if let std::path::Component::Normal(src) = components.next()? { | ||
if src != "src" { | ||
return None; | ||
} | ||
} | ||
|
||
if let std::path::Component::Normal(github) = components.next()? { | ||
let github = github.to_str()?; | ||
if !github.starts_with("jackfan.us.kg-") { | ||
return None; | ||
} | ||
} | ||
|
||
if let std::path::Component::Normal(name_version) = components.next()? { | ||
let name_version = name_version.to_str()?; | ||
Some(Dependency { | ||
name_version, | ||
path: components.as_path(), | ||
}) | ||
} else { | ||
None | ||
} | ||
} | ||
} |