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