Skip to content

Commit 78fd3b5

Browse files
committed
Extract auxiliary-crate properties to their own module/struct
1 parent ce697f9 commit 78fd3b5

File tree

3 files changed

+62
-40
lines changed

3 files changed

+62
-40
lines changed

src/tools/compiletest/src/header.rs

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ use std::process::Command;
99
use tracing::*;
1010

1111
use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
12+
use crate::header::auxiliary::{AuxProps, parse_and_update_aux};
1213
use crate::header::cfg::{MatchOutcome, parse_cfg_name_directive};
1314
use crate::header::needs::CachedNeedsConditions;
1415
use crate::util::static_regex;
1516
use crate::{extract_cdb_version, extract_gdb_version};
1617

18+
pub(crate) mod auxiliary;
1719
mod cfg;
1820
mod needs;
1921
#[cfg(test)]
@@ -98,18 +100,8 @@ pub struct TestProps {
98100
// If present, the name of a file that this test should match when
99101
// pretty-printed
100102
pub pp_exact: Option<PathBuf>,
101-
// Other crates that should be compiled (typically from the same
102-
// directory as the test, but for backwards compatibility reasons
103-
// we also check the auxiliary directory)
104-
pub aux_builds: Vec<String>,
105-
// Auxiliary crates that should be compiled as `#![crate_type = "bin"]`.
106-
pub aux_bins: Vec<String>,
107-
// Similar to `aux_builds`, but a list of NAME=somelib.rs of dependencies
108-
// to build and pass with the `--extern` flag.
109-
pub aux_crates: Vec<(String, String)>,
110-
/// Similar to `aux_builds`, but also passes the resulting dylib path to
111-
/// `-Zcodegen-backend`.
112-
pub aux_codegen_backend: Option<String>,
103+
/// Auxiliary crates that should be built and made available to this test.
104+
pub(crate) aux: AuxProps,
113105
// Environment settings to use for compiling
114106
pub rustc_env: Vec<(String, String)>,
115107
// Environment variables to unset prior to compiling.
@@ -276,10 +268,7 @@ impl TestProps {
276268
run_flags: vec![],
277269
doc_flags: vec![],
278270
pp_exact: None,
279-
aux_builds: vec![],
280-
aux_bins: vec![],
281-
aux_crates: vec![],
282-
aux_codegen_backend: None,
271+
aux: Default::default(),
283272
revisions: vec![],
284273
rustc_env: vec![
285274
("RUSTC_ICE".to_string(), "0".to_string()),
@@ -454,21 +443,10 @@ impl TestProps {
454443
PRETTY_COMPARE_ONLY,
455444
&mut self.pretty_compare_only,
456445
);
457-
config.push_name_value_directive(ln, AUX_BUILD, &mut self.aux_builds, |r| {
458-
r.trim().to_string()
459-
});
460-
config.push_name_value_directive(ln, AUX_BIN, &mut self.aux_bins, |r| {
461-
r.trim().to_string()
462-
});
463-
config.push_name_value_directive(
464-
ln,
465-
AUX_CRATE,
466-
&mut self.aux_crates,
467-
Config::parse_aux_crate,
468-
);
469-
if let Some(r) = config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND) {
470-
self.aux_codegen_backend = Some(r.trim().to_owned());
471-
}
446+
447+
// Call a helper method to deal with aux-related directives.
448+
parse_and_update_aux(config, ln, &mut self.aux);
449+
472450
config.push_name_value_directive(
473451
ln,
474452
EXEC_ENV,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.
3+
4+
use crate::common::Config;
5+
use crate::header::directives::{AUX_BIN, AUX_BUILD, AUX_CODEGEN_BACKEND, AUX_CRATE};
6+
7+
/// Properties parsed from `aux-*` test directives.
8+
#[derive(Clone, Debug, Default)]
9+
pub(crate) struct AuxProps {
10+
/// Other crates that should be built and made available to this test.
11+
/// These are filenames relative to `./auxiliary/` in the test's directory.
12+
pub(crate) builds: Vec<String>,
13+
/// Auxiliary crates that should be compiled as `#![crate_type = "bin"]`.
14+
pub(crate) bins: Vec<String>,
15+
/// Similar to `builds`, but a list of NAME=somelib.rs of dependencies
16+
/// to build and pass with the `--extern` flag.
17+
pub(crate) crates: Vec<(String, String)>,
18+
/// Similar to `builds`, but also uses the resulting dylib as a
19+
/// `-Zcodegen-backend` when compiling the test file.
20+
pub(crate) codegen_backend: Option<String>,
21+
}
22+
23+
/// If the given test directive line contains an `aux-*` directive, parse it
24+
/// and update [`AuxProps`] accordingly.
25+
pub(super) fn parse_and_update_aux(config: &Config, ln: &str, aux: &mut AuxProps) {
26+
if !ln.starts_with("aux-") {
27+
return;
28+
}
29+
30+
config.push_name_value_directive(ln, AUX_BUILD, &mut aux.builds, |r| r.trim().to_string());
31+
config.push_name_value_directive(ln, AUX_BIN, &mut aux.bins, |r| r.trim().to_string());
32+
config.push_name_value_directive(ln, AUX_CRATE, &mut aux.crates, parse_aux_crate);
33+
if let Some(r) = config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND) {
34+
aux.codegen_backend = Some(r.trim().to_owned());
35+
}
36+
}
37+
38+
fn parse_aux_crate(r: String) -> (String, String) {
39+
let mut parts = r.trim().splitn(2, '=');
40+
(
41+
parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(),
42+
parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(),
43+
)
44+
}

src/tools/compiletest/src/runtest.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -841,13 +841,13 @@ impl<'test> TestCx<'test> {
841841
/// Auxiliaries, no matter how deep, have the same root_out_dir and root_testpaths.
842842
fn document(&self, root_out_dir: &Path, root_testpaths: &TestPaths) -> ProcRes {
843843
if self.props.build_aux_docs {
844-
for rel_ab in &self.props.aux_builds {
844+
for rel_ab in &self.props.aux.builds {
845845
let aux_testpaths = self.compute_aux_test_paths(root_testpaths, rel_ab);
846-
let aux_props =
846+
let props_for_aux =
847847
self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config);
848848
let aux_cx = TestCx {
849849
config: self.config,
850-
props: &aux_props,
850+
props: &props_for_aux,
851851
testpaths: &aux_testpaths,
852852
revision: self.revision,
853853
};
@@ -1059,11 +1059,11 @@ impl<'test> TestCx<'test> {
10591059
fn aux_output_dir(&self) -> PathBuf {
10601060
let aux_dir = self.aux_output_dir_name();
10611061

1062-
if !self.props.aux_builds.is_empty() {
1062+
if !self.props.aux.builds.is_empty() {
10631063
remove_and_create_dir_all(&aux_dir);
10641064
}
10651065

1066-
if !self.props.aux_bins.is_empty() {
1066+
if !self.props.aux.bins.is_empty() {
10671067
let aux_bin_dir = self.aux_bin_output_dir_name();
10681068
remove_and_create_dir_all(&aux_dir);
10691069
remove_and_create_dir_all(&aux_bin_dir);
@@ -1073,15 +1073,15 @@ impl<'test> TestCx<'test> {
10731073
}
10741074

10751075
fn build_all_auxiliary(&self, of: &TestPaths, aux_dir: &Path, rustc: &mut Command) {
1076-
for rel_ab in &self.props.aux_builds {
1076+
for rel_ab in &self.props.aux.builds {
10771077
self.build_auxiliary(of, rel_ab, &aux_dir, false /* is_bin */);
10781078
}
10791079

1080-
for rel_ab in &self.props.aux_bins {
1080+
for rel_ab in &self.props.aux.bins {
10811081
self.build_auxiliary(of, rel_ab, &aux_dir, true /* is_bin */);
10821082
}
10831083

1084-
for (aux_name, aux_path) in &self.props.aux_crates {
1084+
for (aux_name, aux_path) in &self.props.aux.crates {
10851085
let aux_type = self.build_auxiliary(of, &aux_path, &aux_dir, false /* is_bin */);
10861086
let lib_name =
10871087
get_lib_name(&aux_path.trim_end_matches(".rs").replace('-', "_"), aux_type);
@@ -1097,7 +1097,7 @@ impl<'test> TestCx<'test> {
10971097

10981098
// Build any `//@ aux-codegen-backend`, and pass the resulting library
10991099
// to `-Zcodegen-backend` when compiling the test file.
1100-
if let Some(aux_file) = &self.props.aux_codegen_backend {
1100+
if let Some(aux_file) = &self.props.aux.codegen_backend {
11011101
let aux_type = self.build_auxiliary(of, aux_file, aux_dir, false);
11021102
if let Some(lib_name) = get_lib_name(aux_file.trim_end_matches(".rs"), aux_type) {
11031103
let lib_path = aux_dir.join(&lib_name);

0 commit comments

Comments
 (0)