1use anyhow::Result;
2#[allow(clippy::wildcard_imports)]
3use dylint_internal::{self, cargo::*};
4use std::{
5 fs::read_dir,
6 path::{Path, PathBuf},
7};
8
9pub fn build() -> Result<()> {
10 dylint_internal::build()
12 .sanitize_environment()
13 .current_dir(
14 Path::new(env!("CARGO_MANIFEST_DIR"))
15 .join("..")
16 .join("dylint-link"),
17 )
18 .success()?;
19
20 for example in iter()? {
21 let example = example?;
22 dylint_internal::build()
23 .sanitize_environment()
24 .current_dir(&example)
25 .success()?;
26 }
27
28 Ok(())
29}
30
31pub fn iter() -> Result<impl Iterator<Item = Result<PathBuf>>> {
32 let iter = read_dir(env!("CARGO_MANIFEST_DIR"))?;
33 Ok(iter
34 .map(|entry| -> Result<Option<PathBuf>> {
35 let entry = entry?;
36 let path = entry.path();
37 Ok(
38 if path.is_dir() && path.file_name() != Some(std::ffi::OsStr::new("src")) {
39 Some(path)
40 } else {
41 None
42 },
43 )
44 })
45 .filter_map(Result::transpose))
46}
47
48#[cfg(test)]
49mod test {
50 use super::*;
51
52 #[test]
53 fn examples() {
54 for path in iter().unwrap() {
55 let path = path.unwrap();
56 dylint_internal::test()
57 .sanitize_environment()
58 .current_dir(path)
59 .success()
60 .unwrap();
61 }
62 }
63}