|
| 1 | +//@ edition: 2021 |
| 2 | +//@ run-pass |
| 3 | +//@ run-flags: {{sysroot-base}} {{target-linker}} |
| 4 | +//@ ignore-stage1 (requires matching sysroot built with in-tree compiler) |
| 5 | + |
| 6 | +// Regression test for <https://github.com/rust-lang/rust/issues/19371>. |
| 7 | +// |
| 8 | +// This test ensures that `compile_input` can be called twice in one task |
| 9 | +// without causing a panic. |
| 10 | + |
1 | 11 | #![feature(rustc_private)] |
2 | 12 |
|
3 | 13 | extern crate rustc_driver; |
4 | 14 | extern crate rustc_interface; |
5 | 15 | extern crate rustc_session; |
6 | 16 | extern crate rustc_span; |
7 | 17 |
|
| 18 | +use std::path::{Path, PathBuf}; |
| 19 | + |
8 | 20 | use rustc_interface::interface; |
9 | 21 | use rustc_session::config::{Input, Options, OutFileName, OutputType, OutputTypes}; |
10 | 22 | use rustc_span::FileName; |
11 | 23 |
|
12 | | -use std::path::PathBuf; |
13 | | - |
14 | 24 | fn main() { |
15 | 25 | let src = r#" |
16 | 26 | fn main() {} |
17 | 27 | "#; |
18 | 28 |
|
19 | 29 | let args: Vec<String> = std::env::args().collect(); |
20 | 30 |
|
21 | | - if args.len() < 4 { |
22 | | - panic!("expected rustc path"); |
| 31 | + if args.len() < 2 { |
| 32 | + panic!("expected sysroot (and optional linker)"); |
23 | 33 | } |
24 | 34 |
|
25 | | - let tmpdir = PathBuf::from(&args[1]); |
26 | | - |
27 | | - let mut sysroot = PathBuf::from(&args[3]); |
28 | | - sysroot.pop(); |
29 | | - sysroot.pop(); |
| 35 | + let sysroot = PathBuf::from(&args[1]); |
| 36 | + let linker = args.get(2).map(PathBuf::from); |
30 | 37 |
|
31 | | - compile(src.to_string(), tmpdir.join("out"), sysroot.clone()); |
| 38 | + // compiletest sets the current dir to `output_base_dir` when running. |
| 39 | + let tmpdir = std::env::current_dir().unwrap().join("tmp"); |
| 40 | + std::fs::create_dir_all(&tmpdir).unwrap(); |
32 | 41 |
|
33 | | - compile(src.to_string(), tmpdir.join("out"), sysroot.clone()); |
| 42 | + compile(src.to_string(), tmpdir.join("out"), sysroot.clone(), linker.as_deref()); |
| 43 | + compile(src.to_string(), tmpdir.join("out"), sysroot.clone(), linker.as_deref()); |
34 | 44 | } |
35 | 45 |
|
36 | | -fn compile(code: String, output: PathBuf, sysroot: PathBuf) { |
| 46 | +fn compile(code: String, output: PathBuf, sysroot: PathBuf, linker: Option<&Path>) { |
37 | 47 | let mut opts = Options::default(); |
38 | 48 | opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]); |
39 | 49 | opts.maybe_sysroot = Some(sysroot); |
40 | 50 |
|
41 | | - if let Ok(linker) = std::env::var("RUSTC_LINKER") { |
42 | | - opts.cg.linker = Some(linker.into()); |
| 51 | + if let Some(linker) = linker { |
| 52 | + opts.cg.linker = Some(linker.to_owned()); |
43 | 53 | } |
44 | 54 |
|
45 | 55 | let name = FileName::anon_source_code(&code); |
|
0 commit comments