nom_kconfig/entry/source/
orsource.rs1use nom::{branch::alt, bytes::complete::tag, sequence::delimited, IResult, Parser};
5
6use crate::{
7 entry::{
8 source::{expand_source_files, parse_filepath, parse_source_kconfig, JoinPathMode},
9 Source,
10 },
11 kconfig::Kconfig,
12 util::{ws, wsi},
13 KconfigInput,
14};
15
16pub type OrSource = Source;
17
18pub fn parse_orsource(input: KconfigInput) -> IResult<KconfigInput, OrSource> {
19 let (input, _) = ws(tag("orsource")).parse(input)?;
20 let (mut input, file) = wsi(alt((
21 delimited(tag("\""), parse_filepath, tag("\"")),
22 parse_filepath,
23 )))
24 .parse(input)?;
25 let expanded_files = expand_source_files(input.clone(), file, JoinPathMode::Relative)?;
26 let mut sources = vec![];
27
28 for expanded_file in expanded_files {
29 let source_kconfig_file = input.extra.new_source_file(expanded_file);
30 if !source_kconfig_file.full_path().exists() {
31 sources.push(Kconfig {
32 file: file.to_string(),
33 ..Default::default()
34 });
35 continue;
36 }
37 let (variables, source) = parse_source_kconfig(input.clone(), source_kconfig_file)?;
38 input.extra.add_local_vars(variables);
39 sources.push(source);
40 }
41
42 Ok((input, OrSource { kconfigs: sources }))
43}