mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Fix ninja BuildAction name sanitization (#4291)
rust commit 8296ad0 changes the output of std::any::type_name to include regions such as lifetime and generic arguments, which results in invalid Ninja rule names being generated, such as `CargoBuild<_>`.
This commit is contained in:
parent
4fdb4983dd
commit
e3d0a30443
2 changed files with 42 additions and 1 deletions
|
@ -239,6 +239,7 @@ jcznk <https://github.com/jcznk>
|
||||||
Thomas Rixen <thomas.rixen@student.uclouvain.be>
|
Thomas Rixen <thomas.rixen@student.uclouvain.be>
|
||||||
Siyuan Mattuwu Yan <syan4@ualberta.ca>
|
Siyuan Mattuwu Yan <syan4@ualberta.ca>
|
||||||
Lee Doughty <https://github.com/leedoughty>
|
Lee Doughty <https://github.com/leedoughty>
|
||||||
|
memchr <memchr@proton.me>
|
||||||
|
|
||||||
********************
|
********************
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,46 @@ pub trait BuildAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
std::any::type_name::<Self>().split("::").last().unwrap()
|
std::any::type_name::<Self>()
|
||||||
|
.split("::")
|
||||||
|
.last()
|
||||||
|
.unwrap()
|
||||||
|
.split('<')
|
||||||
|
.next()
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
trait TestBuildAction {}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
impl<T: TestBuildAction + ?Sized> BuildAction for T {
|
||||||
|
fn command(&self) -> &str {
|
||||||
|
"test"
|
||||||
|
}
|
||||||
|
fn files(&mut self, _build: &mut impl FilesHandle) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code, unused_variables)]
|
||||||
|
#[test]
|
||||||
|
fn should_strip_regions_in_type_name() {
|
||||||
|
struct Bare;
|
||||||
|
impl TestBuildAction for Bare {}
|
||||||
|
assert_eq!(Bare {}.name(), "Bare");
|
||||||
|
|
||||||
|
struct WithLifeTime<'a>(&'a str);
|
||||||
|
impl TestBuildAction for WithLifeTime<'_> {}
|
||||||
|
assert_eq!(WithLifeTime("test").name(), "WithLifeTime");
|
||||||
|
|
||||||
|
struct WithMultiLifeTime<'a, 'b>(&'a str, &'b str);
|
||||||
|
impl TestBuildAction for WithMultiLifeTime<'_, '_> {}
|
||||||
|
assert_eq!(
|
||||||
|
WithMultiLifeTime("test", "test").name(),
|
||||||
|
"WithMultiLifeTime"
|
||||||
|
);
|
||||||
|
|
||||||
|
struct WithGeneric<T>(T);
|
||||||
|
impl<T> TestBuildAction for WithGeneric<T> {}
|
||||||
|
assert_eq!(WithGeneric(3).name(), "WithGeneric");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue