Skip to main content

nom_kconfig/entry/source/
rsource.rs

1use crate::entry::source::JoinPathMode;
2use crate::{entry::Source, util::ws, KconfigInput};
3use nom::{bytes::complete::tag, IResult, Parser};
4
5use nom::{branch::alt, sequence::delimited};
6
7use crate::{
8    entry::source::{expand_source_files, parse_filepath, parse_source_kconfig},
9    util::wsi,
10};
11
12pub type RSource = Source;
13
14#[allow(dead_code)]
15pub fn parse_rsource(input: KconfigInput) -> IResult<KconfigInput, RSource> {
16    let (input, _) = ws(tag("rsource")).parse(input)?;
17    let (mut input, file) = wsi(alt((
18        delimited(tag("\""), parse_filepath, tag("\"")),
19        parse_filepath,
20    )))
21    .parse(input)?;
22
23    let expanded_files = expand_source_files(input.clone(), file, JoinPathMode::Relative)?;
24    let mut sources = vec![];
25
26    for expanded_file in expanded_files {
27        let source_kconfig_file = input.extra.new_source_file(expanded_file);
28        let (variables, source) = parse_source_kconfig(input.clone(), source_kconfig_file)?;
29        input.extra.add_local_vars(variables);
30        sources.push(source);
31    }
32
33    Ok((input, RSource { kconfigs: sources }))
34}
35
36#[cfg(test)]
37use std::path::PathBuf;
38
39#[test]
40#[ignore]
41fn test_parse_rsource() {
42    use crate::KconfigFile;
43
44    let res = parse_rsource(KconfigInput::new_extra(
45        r#"rsource "boards/*.defconfig""#,
46        KconfigFile {
47            root_dir: PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests"),
48            ..Default::default()
49        },
50    ));
51    assert!(res.is_err())
52}