Rollup merge of #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 #125973, this test appears to be testing something vaguely useful and breakable, which is why I didn't just delete it.
This commit is contained in:
commit
1c17449ae3
@ -1268,6 +1268,8 @@ fn expand_variables(mut value: String, config: &Config) -> String {
|
|||||||
const CWD: &str = "{{cwd}}";
|
const CWD: &str = "{{cwd}}";
|
||||||
const SRC_BASE: &str = "{{src-base}}";
|
const SRC_BASE: &str = "{{src-base}}";
|
||||||
const BUILD_BASE: &str = "{{build-base}}";
|
const BUILD_BASE: &str = "{{build-base}}";
|
||||||
|
const SYSROOT_BASE: &str = "{{sysroot-base}}";
|
||||||
|
const TARGET_LINKER: &str = "{{target-linker}}";
|
||||||
|
|
||||||
if value.contains(CWD) {
|
if value.contains(CWD) {
|
||||||
let cwd = env::current_dir().unwrap();
|
let cwd = env::current_dir().unwrap();
|
||||||
@ -1282,6 +1284,14 @@ fn expand_variables(mut value: String, config: &Config) -> String {
|
|||||||
value = value.replace(BUILD_BASE, &config.build_base.to_string_lossy());
|
value = value.replace(BUILD_BASE, &config.build_base.to_string_lossy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if value.contains(SYSROOT_BASE) {
|
||||||
|
value = value.replace(SYSROOT_BASE, &config.sysroot_base.to_string_lossy());
|
||||||
|
}
|
||||||
|
|
||||||
|
if value.contains(TARGET_LINKER) {
|
||||||
|
value = value.replace(TARGET_LINKER, config.target_linker.as_deref().unwrap_or(""));
|
||||||
|
}
|
||||||
|
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
include ../../run-make/tools.mk
|
|
||||||
|
|
||||||
# This test ensures that rustc compile_input can be called twice in one task
|
|
||||||
# without causing a panic.
|
|
||||||
# The program needs the path to rustc to get sysroot.
|
|
||||||
|
|
||||||
all:
|
|
||||||
$(RUSTC) foo.rs
|
|
||||||
$(call RUN,foo $(TMPDIR) $(RUSTC))
|
|
@ -1,3 +1,13 @@
|
|||||||
|
//@ edition: 2021
|
||||||
|
//@ run-pass
|
||||||
|
//@ run-flags: {{sysroot-base}} {{target-linker}}
|
||||||
|
//@ ignore-stage1 (requires matching sysroot built with in-tree compiler)
|
||||||
|
|
||||||
|
// Regression test for <https://github.com/rust-lang/rust/issues/19371>.
|
||||||
|
//
|
||||||
|
// This test ensures that `compile_input` can be called twice in one task
|
||||||
|
// without causing a panic.
|
||||||
|
|
||||||
#![feature(rustc_private)]
|
#![feature(rustc_private)]
|
||||||
|
|
||||||
extern crate rustc_driver;
|
extern crate rustc_driver;
|
||||||
@ -5,12 +15,12 @@
|
|||||||
extern crate rustc_session;
|
extern crate rustc_session;
|
||||||
extern crate rustc_span;
|
extern crate rustc_span;
|
||||||
|
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use rustc_interface::interface;
|
use rustc_interface::interface;
|
||||||
use rustc_session::config::{Input, Options, OutFileName, OutputType, OutputTypes};
|
use rustc_session::config::{Input, Options, OutFileName, OutputType, OutputTypes};
|
||||||
use rustc_span::FileName;
|
use rustc_span::FileName;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let src = r#"
|
let src = r#"
|
||||||
fn main() {}
|
fn main() {}
|
||||||
@ -18,28 +28,28 @@ fn main() {}
|
|||||||
|
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
|
||||||
if args.len() < 4 {
|
if args.len() < 2 {
|
||||||
panic!("expected rustc path");
|
panic!("expected sysroot (and optional linker)");
|
||||||
}
|
}
|
||||||
|
|
||||||
let tmpdir = PathBuf::from(&args[1]);
|
let sysroot = PathBuf::from(&args[1]);
|
||||||
|
let linker = args.get(2).map(PathBuf::from);
|
||||||
|
|
||||||
let mut sysroot = PathBuf::from(&args[3]);
|
// compiletest sets the current dir to `output_base_dir` when running.
|
||||||
sysroot.pop();
|
let tmpdir = std::env::current_dir().unwrap().join("tmp");
|
||||||
sysroot.pop();
|
std::fs::create_dir_all(&tmpdir).unwrap();
|
||||||
|
|
||||||
compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
|
compile(src.to_string(), tmpdir.join("out"), sysroot.clone(), linker.as_deref());
|
||||||
|
compile(src.to_string(), tmpdir.join("out"), sysroot.clone(), linker.as_deref());
|
||||||
compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
|
fn compile(code: String, output: PathBuf, sysroot: PathBuf, linker: Option<&Path>) {
|
||||||
let mut opts = Options::default();
|
let mut opts = Options::default();
|
||||||
opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
|
opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
|
||||||
opts.maybe_sysroot = Some(sysroot);
|
opts.maybe_sysroot = Some(sysroot);
|
||||||
|
|
||||||
if let Ok(linker) = std::env::var("RUSTC_LINKER") {
|
if let Some(linker) = linker {
|
||||||
opts.cg.linker = Some(linker.into());
|
opts.cg.linker = Some(linker.to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = FileName::anon_source_code(&code);
|
let name = FileName::anon_source_code(&code);
|
Loading…
Reference in New Issue
Block a user