Extract a split_flags helper in header directive parsing

This commit is contained in:
Zalathar 2024-01-04 11:08:01 +11:00
parent aa4bf0bbf0
commit 9ab8c632ee

View File

@ -321,16 +321,23 @@ impl TestProps {
|r| r, |r| r,
); );
if let Some(flags) = config.parse_name_value_directive(ln, COMPILE_FLAGS) { fn split_flags(flags: &str) -> Vec<String> {
self.compile_flags.extend( // Individual flags can be single-quoted to preserve spaces; see
flags // <https://github.com/rust-lang/rust/pull/115948/commits/957c5db6>.
.split("'") flags
.enumerate() .split("'")
.flat_map(|(i, f)| { .enumerate()
.flat_map(
|(i, f)| {
if i % 2 == 1 { vec![f] } else { f.split_whitespace().collect() } if i % 2 == 1 { vec![f] } else { f.split_whitespace().collect() }
}) },
.map(|s| s.to_owned()), )
); .map(move |s| s.to_owned())
.collect::<Vec<_>>()
}
if let Some(flags) = config.parse_name_value_directive(ln, COMPILE_FLAGS) {
self.compile_flags.extend(split_flags(&flags));
} }
if config.parse_name_value_directive(ln, INCORRECT_COMPILER_FLAGS).is_some() { if config.parse_name_value_directive(ln, INCORRECT_COMPILER_FLAGS).is_some() {
panic!("`compiler-flags` directive should be spelled `compile-flags`"); panic!("`compiler-flags` directive should be spelled `compile-flags`");