Skip to content

Commit

Permalink
Port tests/run-make-fulldeps/issue-19371 to ui-fulldeps
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Jun 5, 2024
1 parent a330e49 commit 54b2e86
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
10 changes: 10 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,8 @@ fn expand_variables(mut value: String, config: &Config) -> String {
const CWD: &str = "{{cwd}}";
const SRC_BASE: &str = "{{src-base}}";
const BUILD_BASE: &str = "{{build-base}}";
const SYSROOT_BASE: &str = "{{sysroot-base}}";
const TARGET_LINKER: &str = "{{target-linker}}";

if value.contains(CWD) {
let cwd = env::current_dir().unwrap();
Expand All @@ -1281,6 +1283,14 @@ fn expand_variables(mut value: String, config: &Config) -> String {
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
}

Expand Down
9 changes: 0 additions & 9 deletions tests/run-make-fulldeps/issue-19371/Makefile

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
//@ 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;
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() {}
"#;

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);
Expand Down

0 comments on commit 54b2e86

Please sign in to comment.