Skip to content

Commit

Permalink
Allow {{rust-src-base}} in test headers
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeuw committed Nov 20, 2023
1 parent febce52 commit a013915
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashSet;
use std::env;
use std::fs::File;
use std::fs::canonicalize;
use std::io::prelude::*;
use std::io::BufReader;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -795,6 +796,7 @@ 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 RUST_SRC_BASE: &str = "{{rust-src-base}}";

if value.contains(CWD) {
let cwd = env::current_dir().unwrap();
Expand All @@ -809,6 +811,12 @@ fn expand_variables(mut value: String, config: &Config) -> String {
value = value.replace(BUILD_BASE, &config.build_base.to_string_lossy());
}

if value.contains(RUST_SRC_BASE) {
let src = config.sysroot_base.join("lib/rustlib/src/rust");
let canonical = canonicalize(&src).unwrap();
value = value.replace(RUST_SRC_BASE, &canonical.to_string_lossy());
}

value
}

Expand Down

0 comments on commit a013915

Please sign in to comment.