about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-06-05 18:21:15 +0200
committerGitHub <noreply@github.com>2024-06-05 18:21:15 +0200
commit1c17449ae39ee2d3ab5f7a056db4a23d7f0629b4 (patch)
tree9e89d93f36d9bdcb8562ab35c81028990bd68dc3 /tests
parent33c02c37129777a985c8a712e59a29862a8f21c9 (diff)
parent54b2e86db7f522294254ae5e4572feba28e0b929 (diff)
downloadrust-1c17449ae39ee2d3ab5f7a056db4a23d7f0629b4.tar.gz
rust-1c17449ae39ee2d3ab5f7a056db4a23d7f0629b4.zip
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/run-make-fulldeps/issue-19371/Makefile9
-rw-r--r--tests/ui-fulldeps/run-compiler-twice.rs (renamed from tests/run-make-fulldeps/issue-19371/foo.rs)38
2 files changed, 24 insertions, 23 deletions
diff --git a/tests/run-make-fulldeps/issue-19371/Makefile b/tests/run-make-fulldeps/issue-19371/Makefile
deleted file mode 100644
index edec68f0862..00000000000
--- a/tests/run-make-fulldeps/issue-19371/Makefile
+++ /dev/null
@@ -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))
diff --git a/tests/run-make-fulldeps/issue-19371/foo.rs b/tests/ui-fulldeps/run-compiler-twice.rs
index 327c99a02c6..02748626723 100644
--- a/tests/run-make-fulldeps/issue-19371/foo.rs
+++ b/tests/ui-fulldeps/run-compiler-twice.rs
@@ -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)]
 
 extern crate rustc_driver;
@@ -5,12 +15,12 @@ extern crate rustc_interface;
 extern crate rustc_session;
 extern crate rustc_span;
 
+use std::path::{Path, PathBuf};
+
 use rustc_interface::interface;
 use rustc_session::config::{Input, Options, OutFileName, OutputType, OutputTypes};
 use rustc_span::FileName;
 
-use std::path::PathBuf;
-
 fn main() {
     let src = r#"
     fn main() {}
@@ -18,28 +28,28 @@ fn main() {
 
     let args: Vec<String> = std::env::args().collect();
 
-    if args.len() < 4 {
-        panic!("expected rustc path");
+    if args.len() < 2 {
+        panic!("expected sysroot (and optional linker)");
     }
 
-    let tmpdir = PathBuf::from(&args[1]);
-
-    let mut sysroot = PathBuf::from(&args[3]);
-    sysroot.pop();
-    sysroot.pop();
+    let sysroot = PathBuf::from(&args[1]);
+    let linker = args.get(2).map(PathBuf::from);
 
-    compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
+    // compiletest sets the current dir to `output_base_dir` when running.
+    let tmpdir = std::env::current_dir().unwrap().join("tmp");
+    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());
 }
 
-fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
+fn compile(code: String, output: PathBuf, sysroot: PathBuf, linker: Option<&Path>) {
     let mut opts = Options::default();
     opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
     opts.maybe_sysroot = Some(sysroot);
 
-    if let Ok(linker) = std::env::var("RUSTC_LINKER") {
-        opts.cg.linker = Some(linker.into());
+    if let Some(linker) = linker {
+        opts.cg.linker = Some(linker.to_owned());
     }
 
     let name = FileName::anon_source_code(&code);