Skip to content

Commit a2aa967

Browse files
committed
compiletest: support auxiliaries with auxiliaries
To test behaviour that depends on the extern options of intermediate crates, compiletest auxiliaries must have their own auxiliaries. Auxiliary compilation previously did not trigger compilation of any auxiliaries in the auxiliary's headers. In addition, those auxiliaries would need to be in an `auxiliary/auxiliary` directory, which is unnecessary and makes some crate graphs harder to write tests for, such as when A depends on B and C, and B depends on C. For a test `tests/ui/$path/root.rs`, with the following crate graph: ``` root |-- grandparent `-- parent `-- grandparent ``` then the intermediate outputs from compiletest will be: ``` build/$target/test/ui/$path/ |-- auxiliary | |-- libgrandparent.dylib | |-- libparent.dylib | |-- grandparent | | |-- grandparent.err | | `-- grandparent.out | `-- parent | |-- parent.err | `-- parent.out |-- libroot.rmeta |-- root.err `-- root.out ``` Signed-off-by: David Wood <david@davidtw.co>
1 parent 29f87ad commit a2aa967

File tree

4 files changed

+44
-23
lines changed

4 files changed

+44
-23
lines changed

src/tools/compiletest/src/runtest.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ impl<'test> TestCx<'test> {
19361936
fn document(&self, out_dir: &Path) -> ProcRes {
19371937
if self.props.build_aux_docs {
19381938
for rel_ab in &self.props.aux_builds {
1939-
let aux_testpaths = self.compute_aux_test_paths(rel_ab);
1939+
let aux_testpaths = self.compute_aux_test_paths(&self.testpaths, rel_ab);
19401940
let aux_props =
19411941
self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config);
19421942
let aux_cx = TestCx {
@@ -2092,24 +2092,18 @@ impl<'test> TestCx<'test> {
20922092
proc_res
20932093
}
20942094

2095-
/// For each `aux-build: foo/bar` annotation, we check to find the
2096-
/// file in an `auxiliary` directory relative to the test itself.
2097-
fn compute_aux_test_paths(&self, rel_ab: &str) -> TestPaths {
2098-
let test_ab = self
2099-
.testpaths
2100-
.file
2101-
.parent()
2102-
.expect("test file path has no parent")
2103-
.join("auxiliary")
2104-
.join(rel_ab);
2095+
/// For each `aux-build: foo/bar` annotation, we check to find the file in an `auxiliary`
2096+
/// directory relative to the test itself (not any intermediate auxiliaries).
2097+
fn compute_aux_test_paths(&self, of: &TestPaths, rel_ab: &str) -> TestPaths {
2098+
let test_ab =
2099+
of.file.parent().expect("test file path has no parent").join("auxiliary").join(rel_ab);
21052100
if !test_ab.exists() {
21062101
self.fatal(&format!("aux-build `{}` source not found", test_ab.display()))
21072102
}
21082103

21092104
TestPaths {
21102105
file: test_ab,
2111-
relative_dir: self
2112-
.testpaths
2106+
relative_dir: of
21132107
.relative_dir
21142108
.join(self.output_testname_unique())
21152109
.join("auxiliary")
@@ -2135,30 +2129,34 @@ impl<'test> TestCx<'test> {
21352129
self.config.target.contains("vxworks") && !self.is_vxworks_pure_static()
21362130
}
21372131

2138-
fn build_all_auxiliary(&self, rustc: &mut Command) -> PathBuf {
2132+
fn aux_output_dir(&self) -> PathBuf {
21392133
let aux_dir = self.aux_output_dir_name();
21402134

21412135
if !self.props.aux_builds.is_empty() {
21422136
let _ = fs::remove_dir_all(&aux_dir);
21432137
create_dir_all(&aux_dir).unwrap();
21442138
}
21452139

2140+
aux_dir
2141+
}
2142+
2143+
fn build_all_auxiliary(&self, of: &TestPaths, aux_dir: &Path, rustc: &mut Command) {
21462144
for rel_ab in &self.props.aux_builds {
2147-
self.build_auxiliary(rel_ab, &aux_dir);
2145+
self.build_auxiliary(of, rel_ab, &aux_dir);
21482146
}
21492147

21502148
for (aux_name, aux_path) in &self.props.aux_crates {
2151-
let is_dylib = self.build_auxiliary(&aux_path, &aux_dir);
2149+
let is_dylib = self.build_auxiliary(of, &aux_path, &aux_dir);
21522150
let lib_name =
21532151
get_lib_name(&aux_path.trim_end_matches(".rs").replace('-', "_"), is_dylib);
21542152
rustc.arg("--extern").arg(format!("{}={}/{}", aux_name, aux_dir.display(), lib_name));
21552153
}
2156-
2157-
aux_dir
21582154
}
21592155

21602156
fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) -> ProcRes {
2161-
let aux_dir = self.build_all_auxiliary(&mut rustc);
2157+
let aux_dir = self.aux_output_dir();
2158+
self.build_all_auxiliary(&self.testpaths, &aux_dir, &mut rustc);
2159+
21622160
self.props.unset_rustc_env.iter().fold(&mut rustc, Command::env_remove);
21632161
rustc.envs(self.props.rustc_env.clone());
21642162
self.compose_and_run(
@@ -2172,10 +2170,10 @@ impl<'test> TestCx<'test> {
21722170
/// Builds an aux dependency.
21732171
///
21742172
/// Returns whether or not it is a dylib.
2175-
fn build_auxiliary(&self, source_path: &str, aux_dir: &Path) -> bool {
2176-
let aux_testpaths = self.compute_aux_test_paths(source_path);
2173+
fn build_auxiliary(&self, of: &TestPaths, source_path: &str, aux_dir: &Path) -> bool {
2174+
let aux_testpaths = self.compute_aux_test_paths(of, source_path);
21772175
let aux_props = self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config);
2178-
let aux_output = TargetLocation::ThisDirectory(self.aux_output_dir_name());
2176+
let aux_output = TargetLocation::ThisDirectory(aux_dir.to_path_buf());
21792177
let aux_cx = TestCx {
21802178
config: self.config,
21812179
props: &aux_props,
@@ -2193,6 +2191,7 @@ impl<'test> TestCx<'test> {
21932191
LinkToAux::No,
21942192
Vec::new(),
21952193
);
2194+
aux_cx.build_all_auxiliary(of, aux_dir, &mut aux_rustc);
21962195

21972196
for key in &aux_props.unset_rustc_env {
21982197
aux_rustc.env_remove(key);
@@ -3034,7 +3033,8 @@ impl<'test> TestCx<'test> {
30343033
LinkToAux::Yes,
30353034
Vec::new(),
30363035
);
3037-
new_rustdoc.build_all_auxiliary(&mut rustc);
3036+
let aux_dir = new_rustdoc.aux_output_dir();
3037+
new_rustdoc.build_all_auxiliary(&new_rustdoc.testpaths, &aux_dir, &mut rustc);
30383038

30393039
let proc_res = new_rustdoc.document(&compare_dir);
30403040
if !proc_res.status.success() {
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ aux-crate: aux_aux_foo=aux_aux_foo.rs
2+
//@ aux-crate: aux_aux_bar=aux_aux_bar.rs
3+
//@ edition: 2021
4+
//@ compile-flags: --crate-type lib
5+
//@ check-pass
6+
7+
use aux_aux_foo::Bar as IndirectBar;
8+
use aux_aux_bar::Bar as DirectBar;
9+
10+
fn foo(x: IndirectBar) {}
11+
12+
fn main() {
13+
foo(DirectBar);
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//@ edition: 2021
2+
3+
pub struct Bar;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ aux-crate: aux_aux_bar=aux_aux_bar.rs
2+
//@ edition: 2021
3+
4+
pub use aux_aux_bar::Bar;

0 commit comments

Comments
 (0)