-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #131541 - Zalathar:aux-props, r=jieyouxu
compiletest: Extract auxiliary-crate properties to their own module/struct This moves the values of the 4 different `aux-*` directives into their own sub-struct. That struct, along with its directive-parsing code, can then be shared by both `TestProps` and `EarlyProps`. The final patch also fixes an oversight in up-to-date checking, by including *all* auxiliary crates in the timestamp, not just ordinary `aux-build` ones.
- Loading branch information
Showing
5 changed files
with
87 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! Code for dealing with test directives that request an "auxiliary" crate to | ||
//! be built and made available to the test in some way. | ||
use std::iter; | ||
|
||
use crate::common::Config; | ||
use crate::header::directives::{AUX_BIN, AUX_BUILD, AUX_CODEGEN_BACKEND, AUX_CRATE}; | ||
|
||
/// Properties parsed from `aux-*` test directives. | ||
#[derive(Clone, Debug, Default)] | ||
pub(crate) struct AuxProps { | ||
/// Other crates that should be built and made available to this test. | ||
/// These are filenames relative to `./auxiliary/` in the test's directory. | ||
pub(crate) builds: Vec<String>, | ||
/// Auxiliary crates that should be compiled as `#![crate_type = "bin"]`. | ||
pub(crate) bins: Vec<String>, | ||
/// Similar to `builds`, but a list of NAME=somelib.rs of dependencies | ||
/// to build and pass with the `--extern` flag. | ||
pub(crate) crates: Vec<(String, String)>, | ||
/// Similar to `builds`, but also uses the resulting dylib as a | ||
/// `-Zcodegen-backend` when compiling the test file. | ||
pub(crate) codegen_backend: Option<String>, | ||
} | ||
|
||
impl AuxProps { | ||
/// Yields all of the paths (relative to `./auxiliary/`) that have been | ||
/// specified in `aux-*` directives for this test. | ||
pub(crate) fn all_aux_path_strings(&self) -> impl Iterator<Item = &str> { | ||
let Self { builds, bins, crates, codegen_backend } = self; | ||
|
||
iter::empty() | ||
.chain(builds.iter().map(String::as_str)) | ||
.chain(bins.iter().map(String::as_str)) | ||
.chain(crates.iter().map(|(_, path)| path.as_str())) | ||
.chain(codegen_backend.iter().map(String::as_str)) | ||
} | ||
} | ||
|
||
/// If the given test directive line contains an `aux-*` directive, parse it | ||
/// and update [`AuxProps`] accordingly. | ||
pub(super) fn parse_and_update_aux(config: &Config, ln: &str, aux: &mut AuxProps) { | ||
if !ln.starts_with("aux-") { | ||
return; | ||
} | ||
|
||
config.push_name_value_directive(ln, AUX_BUILD, &mut aux.builds, |r| r.trim().to_string()); | ||
config.push_name_value_directive(ln, AUX_BIN, &mut aux.bins, |r| r.trim().to_string()); | ||
config.push_name_value_directive(ln, AUX_CRATE, &mut aux.crates, parse_aux_crate); | ||
if let Some(r) = config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND) { | ||
aux.codegen_backend = Some(r.trim().to_owned()); | ||
} | ||
} | ||
|
||
fn parse_aux_crate(r: String) -> (String, String) { | ||
let mut parts = r.trim().splitn(2, '='); | ||
( | ||
parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(), | ||
parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,7 +242,8 @@ fn aux_build() { | |
//@ aux-build: b.rs | ||
" | ||
) | ||
.aux, | ||
.aux | ||
.builds, | ||
vec!["a.rs", "b.rs"], | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters