-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional warnings for
windows-bindgen
to improve diagnostics (#…
- Loading branch information
Showing
7 changed files
with
132 additions
and
15 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,65 @@ | ||
use super::*; | ||
use std::sync::RwLock; | ||
|
||
#[derive(Default)] | ||
pub(crate) struct WarningBuilder(RwLock<Vec<String>>); | ||
|
||
impl WarningBuilder { | ||
pub fn build(self) -> Warnings { | ||
Warnings(self.0.write().unwrap().split_off(0)) | ||
} | ||
|
||
pub fn add(&self, message: String) { | ||
self.0.write().unwrap().push(message); | ||
} | ||
|
||
pub fn skip_method(&self, method: MethodDef, dependencies: &TypeMap, config: &Config) { | ||
let mut message = String::new(); | ||
writeln!( | ||
&mut message, | ||
"skipping `{}.{}` due to missing dependencies:", | ||
method.parent().type_name(), | ||
method.name() | ||
) | ||
.unwrap(); | ||
|
||
for tn in dependencies.keys() { | ||
if !config.types.contains_key(tn) && config.references.contains(*tn).is_none() { | ||
writeln!(&mut message, " {tn}").unwrap(); | ||
} | ||
} | ||
|
||
self.add(message); | ||
} | ||
} | ||
|
||
/// Contains warnings collected during code generation. | ||
#[derive(Debug)] | ||
pub struct Warnings(Vec<String>); | ||
|
||
impl Warnings { | ||
/// Panics if any warnings are present. | ||
#[track_caller] | ||
pub fn unwrap(&self) { | ||
if !self.is_empty() { | ||
panic!("{self}"); | ||
} | ||
} | ||
} | ||
|
||
impl std::fmt::Display for Warnings { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
for message in &self.0 { | ||
write!(f, "{message}")?; | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl std::ops::Deref for Warnings { | ||
type Target = Vec<String>; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} |
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