Skip to content

Commit d294f64

Browse files
authored
Merge pull request #152 from oli-obk/aux_builds
Fix aux builds in case of non-default `target` dir paths
2 parents f822e2b + 02aadc4 commit d294f64

File tree

14 files changed

+214
-58
lines changed

14 files changed

+214
-58
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ui_test"
3-
version = "0.17.0"
3+
version = "0.18.0"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "A test framework for testing rustc diagnostics output"

src/config.rs

+1-25
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub use color_eyre;
55
use color_eyre::eyre::Result;
66
use std::{
77
ffi::OsString,
8-
path::{Component, Path, PathBuf, Prefix},
8+
path::{Path, PathBuf},
99
};
1010

1111
mod args;
@@ -218,30 +218,6 @@ impl Config {
218218
.iter()
219219
.any(|arch| self.target.as_ref().unwrap().contains(arch))
220220
}
221-
222-
/// Remove the common prefix of this path and the `root_dir`.
223-
pub(crate) fn strip_path_prefix<'a>(
224-
&self,
225-
path: &'a Path,
226-
) -> impl Iterator<Item = Component<'a>> {
227-
let mut components = path.components();
228-
for c in self.out_dir.components() {
229-
let deverbatimize = |c| match c {
230-
Component::Prefix(prefix) => Err(match prefix.kind() {
231-
Prefix::VerbatimUNC(a, b) => Prefix::UNC(a, b),
232-
Prefix::VerbatimDisk(d) => Prefix::Disk(d),
233-
other => other,
234-
}),
235-
c => Ok(c),
236-
};
237-
let c2 = components.next();
238-
if Some(deverbatimize(c)) == c2.map(deverbatimize) {
239-
continue;
240-
}
241-
return c2.into_iter().chain(components);
242-
}
243-
None.into_iter().chain(components)
244-
}
245221
}
246222

247223
#[derive(Debug, Clone)]

src/dependencies.rs

+5
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ impl<'a> BuildManager<'a> {
244244
command: Command::new(format!("{what:?}")),
245245
errors: vec![],
246246
stderr: b"previous build failed".to_vec(),
247+
stdout: vec![],
247248
});
248249
}
249250
let mut lock = self.cache.write().unwrap();
@@ -254,6 +255,7 @@ impl<'a> BuildManager<'a> {
254255
command: Command::new(format!("{what:?}")),
255256
errors: vec![],
256257
stderr: b"previous build failed".to_vec(),
258+
stdout: vec![],
257259
});
258260
}
259261
entry.get().clone()
@@ -280,6 +282,7 @@ impl<'a> BuildManager<'a> {
280282
command: Command::new(format!("{what:?}")),
281283
errors: vec![],
282284
stderr: format!("{e:?}").into_bytes(),
285+
stdout: vec![],
283286
});
284287
Err(())
285288
}
@@ -299,6 +302,7 @@ impl<'a> BuildManager<'a> {
299302
command: Command::new(what.description()),
300303
errors: vec![],
301304
stderr: vec![],
305+
stdout: vec![],
302306
}),
303307
);
304308
res
@@ -309,6 +313,7 @@ impl<'a> BuildManager<'a> {
309313
command: Command::new(what.description()),
310314
errors: vec![],
311315
stderr: b"previous build failed".to_vec(),
316+
stdout: vec![],
312317
})
313318
})
314319
}

src/lib.rs

+64-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::borrow::Cow;
2222
use std::collections::{HashSet, VecDeque};
2323
use std::ffi::OsString;
2424
use std::num::NonZeroUsize;
25-
use std::path::{Path, PathBuf};
25+
use std::path::{Component, Path, PathBuf, Prefix};
2626
use std::process::{Command, ExitStatus};
2727
use std::thread;
2828

@@ -205,6 +205,8 @@ pub struct Errored {
205205
errors: Vec<Error>,
206206
/// The full stderr of the test run.
207207
stderr: Vec<u8>,
208+
/// The full stdout of the test run.
209+
stdout: Vec<u8>,
208210
}
209211

210212
struct TestRun {
@@ -290,6 +292,7 @@ pub fn run_tests_generic(
290292
.unwrap(),
291293
)],
292294
stderr: vec![],
295+
stdout: vec![],
293296
}),
294297
status,
295298
})?;
@@ -332,10 +335,11 @@ pub fn run_tests_generic(
332335
command,
333336
errors,
334337
stderr,
338+
stdout,
335339
},
336340
) in &failures
337341
{
338-
let _guard = status.failed_test(command, stderr);
342+
let _guard = status.failed_test(command, stderr, stdout);
339343
failure_emitter.test_failure(status, errors);
340344
}
341345

@@ -434,6 +438,7 @@ fn parse_comments(file_contents: &[u8]) -> Result<Comments, Errored> {
434438
command: Command::new("parse comments"),
435439
errors,
436440
stderr: vec![],
441+
stdout: vec![],
437442
}),
438443
}
439444
}
@@ -476,7 +481,12 @@ fn build_aux(
476481
config: &Config,
477482
build_manager: &BuildManager<'_>,
478483
) -> std::result::Result<Vec<OsString>, Errored> {
479-
let file_contents = std::fs::read(aux_file).unwrap();
484+
let file_contents = std::fs::read(aux_file).map_err(|err| Errored {
485+
command: Command::new(format!("reading aux file `{}`", aux_file.display())),
486+
errors: vec![],
487+
stderr: err.to_string().into_bytes(),
488+
stdout: vec![],
489+
})?;
480490
let comments = parse_comments(&file_contents)?;
481491
assert_eq!(
482492
comments.revisions, None,
@@ -509,7 +519,7 @@ fn build_aux(
509519

510520
// Put aux builds into a separate directory per path so that multiple aux files
511521
// from different directories (but with the same file name) don't collide.
512-
let relative = config.strip_path_prefix(aux_file.parent().unwrap());
522+
let relative = strip_path_prefix(aux_file.parent().unwrap(), &config.out_dir);
513523

514524
config.out_dir.extend(relative);
515525

@@ -537,6 +547,7 @@ fn build_aux(
537547
command: aux_cmd,
538548
errors: vec![error],
539549
stderr: rustc_stderr::process(aux_file, &output.stderr).rendered,
550+
stdout: output.stdout,
540551
});
541552
}
542553

@@ -601,14 +612,17 @@ impl dyn TestStatus {
601612
"test panicked: stderr:\n{stderr}\nstdout:\n{stdout}",
602613
))],
603614
stderr: vec![],
615+
stdout: vec![],
604616
});
605617
}
606618
}
607619
}
608620
check_test_result(
609-
cmd, *mode, path, config, revision, comments, status, stdout, &stderr,
621+
cmd, *mode, path, config, revision, comments, status, &stdout, &stderr,
622+
)?;
623+
run_rustfix(
624+
&stderr, &stdout, path, comments, revision, config, *mode, extra_args,
610625
)?;
611-
run_rustfix(&stderr, path, comments, revision, config, *mode, extra_args)?;
612626
Ok(TestOk::Ok)
613627
}
614628

@@ -647,9 +661,19 @@ fn build_aux_files(
647661
build_manager
648662
.build(
649663
Build::Aux {
650-
aux_file: config
651-
.strip_path_prefix(&aux_file.canonicalize().unwrap())
652-
.collect(),
664+
aux_file: strip_path_prefix(
665+
&aux_file.canonicalize().map_err(|err| Errored {
666+
command: Command::new(format!(
667+
"canonicalizing path `{}`",
668+
aux_file.display()
669+
)),
670+
errors: vec![],
671+
stderr: err.to_string().into_bytes(),
672+
stdout: vec![],
673+
})?,
674+
&std::env::current_dir().unwrap(),
675+
)
676+
.collect(),
653677
},
654678
config,
655679
)
@@ -658,6 +682,7 @@ fn build_aux_files(
658682
command,
659683
errors,
660684
stderr,
685+
stdout,
661686
}| Errored {
662687
command,
663688
errors: vec![Error::Aux {
@@ -666,6 +691,7 @@ fn build_aux_files(
666691
line,
667692
}],
668693
stderr,
694+
stdout,
669695
},
670696
)?,
671697
);
@@ -714,12 +740,14 @@ fn run_test_binary(
714740
command: exe,
715741
errors,
716742
stderr: vec![],
743+
stdout: vec![],
717744
})
718745
}
719746
}
720747

721748
fn run_rustfix(
722749
stderr: &[u8],
750+
stdout: &[u8],
723751
path: &Path,
724752
comments: &Comments,
725753
revision: &str,
@@ -773,6 +801,7 @@ fn run_rustfix(
773801
command: Command::new(format!("rustfix {}", path.display())),
774802
errors: vec![Error::Rustfix(err)],
775803
stderr: stderr.into(),
804+
stdout: stdout.into(),
776805
})?;
777806

778807
let edition = comments.edition(revision, config)?;
@@ -836,6 +865,7 @@ fn run_rustfix(
836865
command: Command::new(format!("checking {}", path.display())),
837866
errors,
838867
stderr: vec![],
868+
stdout: vec![],
839869
});
840870
}
841871

@@ -864,6 +894,7 @@ fn run_rustfix(
864894
status: output.status,
865895
}],
866896
stderr: rustc_stderr::process(&rustfix_path, &output.stderr).rendered,
897+
stdout: output.stdout,
867898
})
868899
}
869900
}
@@ -884,7 +915,7 @@ fn check_test_result(
884915
revision: &str,
885916
comments: &Comments,
886917
status: ExitStatus,
887-
stdout: Vec<u8>,
918+
stdout: &[u8],
888919
stderr: &[u8],
889920
) -> Result<(), Errored> {
890921
let mut errors = vec![];
@@ -897,7 +928,7 @@ fn check_test_result(
897928
revision,
898929
config,
899930
comments,
900-
&stdout,
931+
stdout,
901932
&diagnostics.rendered,
902933
);
903934
// Check error annotations in the source against output
@@ -917,6 +948,7 @@ fn check_test_result(
917948
command,
918949
errors,
919950
stderr: diagnostics.rendered,
951+
stdout: stdout.into(),
920952
})
921953
}
922954
}
@@ -1202,3 +1234,24 @@ fn normalize(
12021234
}
12031235
text
12041236
}
1237+
/// Remove the common prefix of this path and the `root_dir`.
1238+
fn strip_path_prefix<'a>(path: &'a Path, prefix: &Path) -> impl Iterator<Item = Component<'a>> {
1239+
let mut components = path.components();
1240+
for c in prefix.components() {
1241+
// Windows has some funky paths. This is probably wrong, but works well in practice.
1242+
let deverbatimize = |c| match c {
1243+
Component::Prefix(prefix) => Err(match prefix.kind() {
1244+
Prefix::VerbatimUNC(a, b) => Prefix::UNC(a, b),
1245+
Prefix::VerbatimDisk(d) => Prefix::Disk(d),
1246+
other => other,
1247+
}),
1248+
c => Ok(c),
1249+
};
1250+
let c2 = components.next();
1251+
if Some(deverbatimize(c)) == c2.map(deverbatimize) {
1252+
continue;
1253+
}
1254+
return c2.into_iter().chain(components);
1255+
}
1256+
None.into_iter().chain(components)
1257+
}

src/parser.rs

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ impl Comments {
6464
lines: errors,
6565
}],
6666
stderr: vec![],
67+
stdout: vec![],
6768
})
6869
}
6970
}

0 commit comments

Comments
 (0)