1//! Code for dealing with test directives that request an "auxiliary" crate to
2//! be built and made available to the test in some way.
34use std::iter;
56use crate::common::Config;
7use crate::header::directives::{AUX_BIN, AUX_BUILD, AUX_CODEGEN_BACKEND, AUX_CRATE, PROC_MACRO};
89/// Properties parsed from `aux-*` test directives.
10#[derive(Clone, Debug, Default)]
11pub(crate) struct AuxProps {
12/// Other crates that should be built and made available to this test.
13 /// These are filenames relative to `./auxiliary/` in the test's directory.
14pub(crate) builds: Vec<String>,
15/// Auxiliary crates that should be compiled as `#![crate_type = "bin"]`.
16pub(crate) bins: Vec<String>,
17/// Similar to `builds`, but a list of NAME=somelib.rs of dependencies
18 /// to build and pass with the `--extern` flag.
19pub(crate) crates: Vec<(String, String)>,
20/// Same as `builds`, but for proc-macros.
21pub(crate) proc_macros: Vec<String>,
22/// Similar to `builds`, but also uses the resulting dylib as a
23 /// `-Zcodegen-backend` when compiling the test file.
24pub(crate) codegen_backend: Option<String>,
25}
2627impl AuxProps {
28/// Yields all of the paths (relative to `./auxiliary/`) that have been
29 /// specified in `aux-*` directives for this test.
30pub(crate) fn all_aux_path_strings(&self) -> impl Iterator<Item = &str> {
31let Self { builds, bins, crates, proc_macros, codegen_backend } = self;
3233 iter::empty()
34 .chain(builds.iter().map(String::as_str))
35 .chain(bins.iter().map(String::as_str))
36 .chain(crates.iter().map(|(_, path)| path.as_str()))
37 .chain(proc_macros.iter().map(String::as_str))
38 .chain(codegen_backend.iter().map(String::as_str))
39 }
40}
4142/// If the given test directive line contains an `aux-*` directive, parse it
43/// and update [`AuxProps`] accordingly.
44pub(super) fn parse_and_update_aux(config: &Config, ln: &str, aux: &mut AuxProps) {
45if !(ln.starts_with("aux-") || ln.starts_with("proc-macro")) {
46return;
47 }
4849 config.push_name_value_directive(ln, AUX_BUILD, &mut aux.builds, |r| r.trim().to_string());
50 config.push_name_value_directive(ln, AUX_BIN, &mut aux.bins, |r| r.trim().to_string());
51 config.push_name_value_directive(ln, AUX_CRATE, &mut aux.crates, parse_aux_crate);
52 config
53 .push_name_value_directive(ln, PROC_MACRO, &mut aux.proc_macros, |r| r.trim().to_string());
54if let Some(r) = config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND) {
55 aux.codegen_backend = Some(r.trim().to_owned());
56 }
57}
5859fn parse_aux_crate(r: String) -> (String, String) {
60let mut parts = r.trim().splitn(2, '=');
61 (
62 parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(),
63 parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(),
64 )
65}