|
4 | 4 | use std::collections::BTreeMap; |
5 | 5 | use std::path::Path; |
6 | 6 |
|
| 7 | +use crate::walk::filter_not_rust; |
| 8 | + |
7 | 9 | const COMMENT: &str = "//"; |
8 | 10 | const LLVM_COMPONENTS_HEADER: &str = "needs-llvm-components:"; |
9 | 11 | const COMPILE_FLAGS_HEADER: &str = "compile-flags:"; |
@@ -35,61 +37,57 @@ struct RevisionInfo<'a> { |
35 | 37 | } |
36 | 38 |
|
37 | 39 | pub fn check(path: &Path, bad: &mut bool) { |
38 | | - crate::walk::walk( |
39 | | - path, |
40 | | - |path| path.extension().map(|p| p == "rs") == Some(false), |
41 | | - &mut |entry, content| { |
42 | | - let file = entry.path().display(); |
43 | | - let mut header_map = BTreeMap::new(); |
44 | | - iter_header(content, &mut |cfg, directive| { |
45 | | - if let Some(value) = directive.strip_prefix(LLVM_COMPONENTS_HEADER) { |
46 | | - let info = header_map.entry(cfg).or_insert(RevisionInfo::default()); |
47 | | - let comp_vec = info.llvm_components.get_or_insert(Vec::new()); |
48 | | - for component in value.split(' ') { |
49 | | - let component = component.trim(); |
50 | | - if !component.is_empty() { |
51 | | - comp_vec.push(component); |
52 | | - } |
53 | | - } |
54 | | - } else if directive.starts_with(COMPILE_FLAGS_HEADER) { |
55 | | - let compile_flags = &directive[COMPILE_FLAGS_HEADER.len()..]; |
56 | | - if let Some((_, v)) = compile_flags.split_once("--target") { |
57 | | - if let Some((arch, _)) = |
58 | | - v.trim_start_matches(|c| c == ' ' || c == '=').split_once("-") |
59 | | - { |
60 | | - let info = header_map.entry(cfg).or_insert(RevisionInfo::default()); |
61 | | - info.target_arch.replace(arch); |
62 | | - } else { |
63 | | - eprintln!("{file}: seems to have a malformed --target value"); |
64 | | - *bad = true; |
65 | | - } |
| 40 | + crate::walk::walk(path, filter_not_rust, &mut |entry, content| { |
| 41 | + let file = entry.path().display(); |
| 42 | + let mut header_map = BTreeMap::new(); |
| 43 | + iter_header(content, &mut |cfg, directive| { |
| 44 | + if let Some(value) = directive.strip_prefix(LLVM_COMPONENTS_HEADER) { |
| 45 | + let info = header_map.entry(cfg).or_insert(RevisionInfo::default()); |
| 46 | + let comp_vec = info.llvm_components.get_or_insert(Vec::new()); |
| 47 | + for component in value.split(' ') { |
| 48 | + let component = component.trim(); |
| 49 | + if !component.is_empty() { |
| 50 | + comp_vec.push(component); |
66 | 51 | } |
67 | 52 | } |
68 | | - }); |
69 | | - for (rev, RevisionInfo { target_arch, llvm_components }) in &header_map { |
70 | | - let rev = rev.unwrap_or("[unspecified]"); |
71 | | - match (target_arch, llvm_components) { |
72 | | - (None, None) => {} |
73 | | - (Some(_), None) => { |
74 | | - eprintln!( |
75 | | - "{}: revision {} should specify `{}` as it has `--target` set", |
76 | | - file, rev, LLVM_COMPONENTS_HEADER |
77 | | - ); |
| 53 | + } else if directive.starts_with(COMPILE_FLAGS_HEADER) { |
| 54 | + let compile_flags = &directive[COMPILE_FLAGS_HEADER.len()..]; |
| 55 | + if let Some((_, v)) = compile_flags.split_once("--target") { |
| 56 | + if let Some((arch, _)) = |
| 57 | + v.trim_start_matches(|c| c == ' ' || c == '=').split_once("-") |
| 58 | + { |
| 59 | + let info = header_map.entry(cfg).or_insert(RevisionInfo::default()); |
| 60 | + info.target_arch.replace(arch); |
| 61 | + } else { |
| 62 | + eprintln!("{file}: seems to have a malformed --target value"); |
78 | 63 | *bad = true; |
79 | 64 | } |
80 | | - (None, Some(_)) => { |
81 | | - eprintln!( |
82 | | - "{}: revision {} should not specify `{}` as it doesn't need `--target`", |
83 | | - file, rev, LLVM_COMPONENTS_HEADER |
84 | | - ); |
85 | | - *bad = true; |
86 | | - } |
87 | | - (Some(_), Some(_)) => { |
88 | | - // FIXME: check specified components against the target architectures we |
89 | | - // gathered. |
90 | | - } |
91 | 65 | } |
92 | 66 | } |
93 | | - }, |
94 | | - ); |
| 67 | + }); |
| 68 | + for (rev, RevisionInfo { target_arch, llvm_components }) in &header_map { |
| 69 | + let rev = rev.unwrap_or("[unspecified]"); |
| 70 | + match (target_arch, llvm_components) { |
| 71 | + (None, None) => {} |
| 72 | + (Some(_), None) => { |
| 73 | + eprintln!( |
| 74 | + "{}: revision {} should specify `{}` as it has `--target` set", |
| 75 | + file, rev, LLVM_COMPONENTS_HEADER |
| 76 | + ); |
| 77 | + *bad = true; |
| 78 | + } |
| 79 | + (None, Some(_)) => { |
| 80 | + eprintln!( |
| 81 | + "{}: revision {} should not specify `{}` as it doesn't need `--target`", |
| 82 | + file, rev, LLVM_COMPONENTS_HEADER |
| 83 | + ); |
| 84 | + *bad = true; |
| 85 | + } |
| 86 | + (Some(_), Some(_)) => { |
| 87 | + // FIXME: check specified components against the target architectures we |
| 88 | + // gathered. |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + }); |
95 | 93 | } |
0 commit comments