Skip to content

Commit 60d3a2e

Browse files
move: break out file_spec module from FileSpec
1 parent 86da5fb commit 60d3a2e

2 files changed

Lines changed: 137 additions & 124 deletions

File tree

moz-webgpu-cts/src/file_spec.rs

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
use std::{fmt::Display, path::PathBuf};
2+
3+
use miette::Report;
4+
use wax::Glob;
5+
6+
use crate::AlreadyReportedToCommandline;
7+
8+
pub(crate) struct FileSpec {
9+
pub paths: Vec<PathBuf>,
10+
pub globs: Vec<String>,
11+
}
12+
13+
impl FileSpec {
14+
pub(crate) fn into_paths(
15+
self,
16+
what: impl Display,
17+
) -> Result<Vec<PathBuf>, AlreadyReportedToCommandline> {
18+
let Self { paths, globs } = self;
19+
20+
let globs = {
21+
let mut found_glob_parse_err = false;
22+
let globs = globs
23+
.into_iter()
24+
.filter_map(|glob| match Glob::diagnosed(&glob) {
25+
Ok((glob, _diagnostics)) => Some(glob.into_owned().partition()),
26+
Err(diagnostics) => {
27+
found_glob_parse_err = true;
28+
let error_reports = diagnostics
29+
.into_iter()
30+
.filter(|diag| {
31+
// N.B.: There should be at least one of these!
32+
diag.severity()
33+
.is_none_or(|sev| sev == miette::Severity::Error)
34+
})
35+
.map(Report::new_boxed);
36+
for report in error_reports {
37+
eprintln!("{report:?}");
38+
}
39+
None
40+
}
41+
})
42+
.collect::<Vec<_>>();
43+
44+
if found_glob_parse_err {
45+
log::error!("failed to parse one or more globs for {what}; bailing");
46+
return Err(AlreadyReportedToCommandline);
47+
}
48+
49+
globs
50+
};
51+
52+
let paths_from_globs = {
53+
let mut found_glob_walk_err = false;
54+
let files = globs
55+
.iter()
56+
.flat_map(|(base_path, glob)| {
57+
glob.walk(base_path)
58+
.filter_map(|entry| match entry {
59+
Ok(entry) => Some(entry.into_path()),
60+
Err(e) => {
61+
found_glob_walk_err = true;
62+
let ctx_msg = if let Some(path) = e.path() {
63+
format!(
64+
"failed to enumerate {what} from glob `{}` at path {}",
65+
glob,
66+
path.display()
67+
)
68+
} else {
69+
format!("failed to enumerate {what} from glob `{glob}`")
70+
};
71+
let e = Report::msg(e).wrap_err(ctx_msg);
72+
eprintln!("{e:?}");
73+
None
74+
}
75+
})
76+
.collect::<Vec<_>>() // OPT: Can we get rid of this somehow?
77+
})
78+
.collect::<Vec<_>>();
79+
80+
if found_glob_walk_err {
81+
log::error!(
82+
concat!(
83+
"failed to enumerate {} from globs, ",
84+
"see above for more details"
85+
),
86+
what
87+
);
88+
return Err(AlreadyReportedToCommandline);
89+
}
90+
91+
files
92+
};
93+
94+
if paths_from_globs.is_empty() && !globs.is_empty() {
95+
if paths.is_empty() {
96+
log::error!(
97+
concat!(
98+
"{} were specified exclusively via glob search, ",
99+
"but none were found; bailing"
100+
),
101+
what
102+
);
103+
return Err(AlreadyReportedToCommandline);
104+
} else {
105+
log::warn!(
106+
concat!(
107+
"{} were specified via path and glob search, ",
108+
"but none were found via glob; ",
109+
"continuing with direct paths"
110+
),
111+
what
112+
)
113+
}
114+
}
115+
116+
let exec_report_paths = paths
117+
.into_iter()
118+
.chain(paths_from_globs)
119+
.collect::<Vec<_>>();
120+
121+
log::trace!("working with the following {what}: {exec_report_paths:#?}");
122+
log::info!("working with {} {what}", exec_report_paths.len());
123+
124+
Ok(exec_report_paths)
125+
}
126+
}

moz-webgpu-cts/src/main.rs

Lines changed: 11 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
mod file_spec;
12
mod process_reports;
23
mod report;
34
mod wpt;
45

5-
use self::wpt::{
6-
metadata::{
7-
self,
8-
properties::{ExpandedPropertyValue, Expected},
9-
File, ImplementationStatus, Platform, Subtest, SubtestOutcome, Test, TestOutcome,
10-
TestProps,
6+
use self::{
7+
file_spec::FileSpec,
8+
wpt::{
9+
metadata::{
10+
self,
11+
properties::{ExpandedPropertyValue, Expected},
12+
File, ImplementationStatus, Platform, Subtest, SubtestOutcome, Test, TestOutcome,
13+
TestProps,
14+
},
15+
path::TestEntryPath,
1116
},
12-
path::TestEntryPath,
1317
};
1418

1519
use std::{
@@ -154,123 +158,6 @@ struct ExecReportSpec {
154158
report_globs: Vec<String>,
155159
}
156160

157-
struct FileSpec {
158-
paths: Vec<PathBuf>,
159-
globs: Vec<String>,
160-
}
161-
162-
impl FileSpec {
163-
fn into_paths(self, what: impl Display) -> Result<Vec<PathBuf>, AlreadyReportedToCommandline> {
164-
let Self { paths, globs } = self;
165-
166-
let globs = {
167-
let mut found_glob_parse_err = false;
168-
let globs = globs
169-
.into_iter()
170-
.filter_map(|glob| match Glob::diagnosed(&glob) {
171-
Ok((glob, _diagnostics)) => Some(glob.into_owned().partition()),
172-
Err(diagnostics) => {
173-
found_glob_parse_err = true;
174-
let error_reports = diagnostics
175-
.into_iter()
176-
.filter(|diag| {
177-
// N.B.: There should be at least one of these!
178-
diag.severity()
179-
.is_none_or(|sev| sev == miette::Severity::Error)
180-
})
181-
.map(Report::new_boxed);
182-
for report in error_reports {
183-
eprintln!("{report:?}");
184-
}
185-
None
186-
}
187-
})
188-
.collect::<Vec<_>>();
189-
190-
if found_glob_parse_err {
191-
log::error!("failed to parse one or more globs for {what}; bailing");
192-
return Err(AlreadyReportedToCommandline);
193-
}
194-
195-
globs
196-
};
197-
198-
let paths_from_globs = {
199-
let mut found_glob_walk_err = false;
200-
let files = globs
201-
.iter()
202-
.flat_map(|(base_path, glob)| {
203-
glob.walk(base_path)
204-
.filter_map(|entry| match entry {
205-
Ok(entry) => Some(entry.into_path()),
206-
Err(e) => {
207-
found_glob_walk_err = true;
208-
let ctx_msg = if let Some(path) = e.path() {
209-
format!(
210-
"failed to enumerate {what} from glob `{}` at path {}",
211-
glob,
212-
path.display()
213-
)
214-
} else {
215-
format!("failed to enumerate {what} from glob `{glob}`")
216-
};
217-
let e = Report::msg(e).wrap_err(ctx_msg);
218-
eprintln!("{e:?}");
219-
None
220-
}
221-
})
222-
.collect::<Vec<_>>() // OPT: Can we get rid of this somehow?
223-
})
224-
.collect::<Vec<_>>();
225-
226-
if found_glob_walk_err {
227-
log::error!(
228-
concat!(
229-
"failed to enumerate {} from globs, ",
230-
"see above for more details"
231-
),
232-
what
233-
);
234-
return Err(AlreadyReportedToCommandline);
235-
}
236-
237-
files
238-
};
239-
240-
if paths_from_globs.is_empty() && !globs.is_empty() {
241-
if paths.is_empty() {
242-
log::error!(
243-
concat!(
244-
"{} were specified exclusively via glob search, ",
245-
"but none were found; bailing"
246-
),
247-
what
248-
);
249-
return Err(AlreadyReportedToCommandline);
250-
} else {
251-
log::warn!(
252-
concat!(
253-
"{} were specified via path and glob search, ",
254-
"but none were found via glob; ",
255-
"continuing with direct paths"
256-
),
257-
what
258-
)
259-
}
260-
}
261-
262-
let exec_report_paths = paths
263-
.into_iter()
264-
.chain(paths_from_globs)
265-
.collect::<Vec<_>>();
266-
267-
log::trace!("working with the following {what}: {exec_report_paths:#?}");
268-
log::info!("working with {} {what}", exec_report_paths.len());
269-
270-
Ok(exec_report_paths)
271-
}
272-
}
273-
274161
impl ExecReportSpec {
275162
fn paths(self) -> Result<Vec<PathBuf>, AlreadyReportedToCommandline> {
276163
let Self {

0 commit comments

Comments
 (0)