Skip to content

Commit faf2596

Browse files
authored
Unrolled build for rust-lang#126008
Rollup merge of rust-lang#126008 - Zalathar:fulldeps-19371, r=jieyouxu Port `tests/run-make-fulldeps/issue-19371` to ui-fulldeps This test can run as an ordinary `tests/ui-fulldeps` test, with the help of some additional header variable substitutions to supply a sysroot and linker. --- Unlike rust-lang#125973, this test appears to be testing something vaguely useful and breakable, which is why I didn't just delete it.
2 parents 7ebd2bd + 54b2e86 commit faf2596

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

src/tools/compiletest/src/header.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,8 @@ fn expand_variables(mut value: String, config: &Config) -> String {
12681268
const CWD: &str = "{{cwd}}";
12691269
const SRC_BASE: &str = "{{src-base}}";
12701270
const BUILD_BASE: &str = "{{build-base}}";
1271+
const SYSROOT_BASE: &str = "{{sysroot-base}}";
1272+
const TARGET_LINKER: &str = "{{target-linker}}";
12711273

12721274
if value.contains(CWD) {
12731275
let cwd = env::current_dir().unwrap();
@@ -1282,6 +1284,14 @@ fn expand_variables(mut value: String, config: &Config) -> String {
12821284
value = value.replace(BUILD_BASE, &config.build_base.to_string_lossy());
12831285
}
12841286

1287+
if value.contains(SYSROOT_BASE) {
1288+
value = value.replace(SYSROOT_BASE, &config.sysroot_base.to_string_lossy());
1289+
}
1290+
1291+
if value.contains(TARGET_LINKER) {
1292+
value = value.replace(TARGET_LINKER, config.target_linker.as_deref().unwrap_or(""));
1293+
}
1294+
12851295
value
12861296
}
12871297

tests/run-make-fulldeps/issue-19371/Makefile

-9
This file was deleted.

tests/run-make-fulldeps/issue-19371/foo.rs tests/ui-fulldeps/run-compiler-twice.rs

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,55 @@
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+
111
#![feature(rustc_private)]
212

313
extern crate rustc_driver;
414
extern crate rustc_interface;
515
extern crate rustc_session;
616
extern crate rustc_span;
717

18+
use std::path::{Path, PathBuf};
19+
820
use rustc_interface::interface;
921
use rustc_session::config::{Input, Options, OutFileName, OutputType, OutputTypes};
1022
use rustc_span::FileName;
1123

12-
use std::path::PathBuf;
13-
1424
fn main() {
1525
let src = r#"
1626
fn main() {}
1727
"#;
1828

1929
let args: Vec<String> = std::env::args().collect();
2030

21-
if args.len() < 4 {
22-
panic!("expected rustc path");
31+
if args.len() < 2 {
32+
panic!("expected sysroot (and optional linker)");
2333
}
2434

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);
3037

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();
3241

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());
3444
}
3545

36-
fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
46+
fn compile(code: String, output: PathBuf, sysroot: PathBuf, linker: Option<&Path>) {
3747
let mut opts = Options::default();
3848
opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
3949
opts.maybe_sysroot = Some(sysroot);
4050

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());
4353
}
4454

4555
let name = FileName::anon_source_code(&code);

0 commit comments

Comments
 (0)