compiletest/directives/
auxiliary.rs1use std::iter;
5
6use super::directives::{AUX_BIN, AUX_BUILD, AUX_CODEGEN_BACKEND, AUX_CRATE, PROC_MACRO};
7use crate::common::Config;
8use crate::directives::DirectiveLine;
9
10#[derive(Clone, Debug, Default)]
12pub struct AuxCrate {
13 pub name: String,
16 pub path: String,
18}
19
20#[derive(Clone, Debug, Default)]
22pub(crate) struct AuxProps {
23 pub(crate) builds: Vec<String>,
26 pub(crate) bins: Vec<String>,
28 pub(crate) crates: Vec<AuxCrate>,
31 pub(crate) proc_macros: Vec<String>,
33 pub(crate) codegen_backend: Option<String>,
36}
37
38impl AuxProps {
39 pub(crate) fn all_aux_path_strings(&self) -> impl Iterator<Item = &str> {
42 let Self { builds, bins, crates, proc_macros, codegen_backend } = self;
43
44 iter::empty()
45 .chain(builds.iter().map(String::as_str))
46 .chain(bins.iter().map(String::as_str))
47 .chain(crates.iter().map(|c| c.path.as_str()))
48 .chain(proc_macros.iter().map(String::as_str))
49 .chain(codegen_backend.iter().map(String::as_str))
50 }
51}
52
53pub(super) fn parse_and_update_aux(
56 config: &Config,
57 directive_line: &DirectiveLine<'_>,
58 aux: &mut AuxProps,
59) {
60 if !(directive_line.name.starts_with("aux-") || directive_line.name == "proc-macro") {
61 return;
62 }
63
64 let ln = directive_line;
65
66 config.push_name_value_directive(ln, AUX_BUILD, &mut aux.builds, |r| r.trim().to_string());
67 config.push_name_value_directive(ln, AUX_BIN, &mut aux.bins, |r| r.trim().to_string());
68 config.push_name_value_directive(ln, AUX_CRATE, &mut aux.crates, parse_aux_crate);
69 config
70 .push_name_value_directive(ln, PROC_MACRO, &mut aux.proc_macros, |r| r.trim().to_string());
71 if let Some(r) = config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND) {
72 aux.codegen_backend = Some(r.trim().to_owned());
73 }
74}
75
76fn parse_aux_crate(r: String) -> AuxCrate {
77 let mut parts = r.trim().splitn(2, '=');
78 AuxCrate {
79 name: parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(),
80 path: parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(),
81 }
82}