Skip to content

Commit 3b1295c

Browse files
committed
External flist: proper splitting
Removes empty lines and commented lines, splits on whitespace afterwards Splits incdirs and defines on additional `+` in string
1 parent 3612ec4 commit 3b1295c

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/config.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,22 @@ impl Validate for PartialSources {
683683
})
684684
})
685685
.collect::<Result<Vec<String>>>()?;
686+
let lines = lines
687+
.iter()
688+
.filter_map(|line| {
689+
let line = line.trim();
690+
if line.is_empty() || line.starts_with('#') || line.starts_with("//") {
691+
None
692+
} else {
693+
Some(
694+
line.split_whitespace()
695+
.map(|s| s.to_string())
696+
.collect::<Vec<_>>(),
697+
)
698+
}
699+
})
700+
.flatten()
701+
.collect();
686702
Ok((filename.parent().unwrap().to_path_buf(), lines))
687703
})
688704
.collect();
@@ -703,6 +719,7 @@ impl Validate for PartialSources {
703719
None
704720
}
705721
})
722+
.flat_map(|s| s.split('+').map(|s| s.to_string()).collect::<Vec<_>>())
706723
.map(|dir| dir.prefix_paths(&flist_dir))
707724
.collect::<Result<_>>()?,
708725
),
@@ -711,19 +728,23 @@ impl Validate for PartialSources {
711728
.clone()
712729
.into_iter()
713730
.filter_map(|file| {
714-
if let Some(stripped) = file.strip_prefix("+define+") {
715-
if let Some(eq_idx) = stripped.find("=") {
716-
Some((
717-
stripped[..eq_idx].to_string(),
718-
Some(stripped[eq_idx + 1..].to_string()),
719-
))
720-
} else {
721-
Some((stripped.to_string(), None))
722-
}
731+
if file.starts_with("+define+") {
732+
Some(file.trim_start_matches("+define+").to_string())
723733
} else {
724734
None
725735
}
726736
})
737+
.flat_map(|s| s.split('+').map(|s| s.to_string()).collect::<Vec<_>>())
738+
.map(|file| {
739+
if let Some(eq_idx) = file.find("=") {
740+
(
741+
file[..eq_idx].to_string(),
742+
Some(file[eq_idx + 1..].to_string()),
743+
)
744+
} else {
745+
(file.to_string(), None)
746+
}
747+
})
727748
.collect(),
728749
),
729750
files: flist

0 commit comments

Comments
 (0)