Skip to content

Commit

Permalink
Unrolled build for rust-lang#126256
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#126256 - ferrocene:lw-target-subst, r=albertlarsan68

Add {{target}} substitution to compiletest

In ferrocene we have ui tests testing the cli interface of the compiler, one of which tests the `--target` flag. To be able to run this on all targets we require a way to specify a valid target in the `compile-flags` directive that is target independent, as otherwise we can only run the test against the one target we choose to supply in the flags. See https://github.com/ferrocene/ferrocene/blob/383cbc80f4e85859a4055f121f15dac329908346/tests/ui/ferrocene/compiler-arguments/target/target.rs

We figured the project might be able to make use of this substitution as well in the future.

try-job: dist-x86_64-msvc
  • Loading branch information
rust-timer authored Jun 12, 2024
2 parents 02c7a59 + 1462f3d commit 5ed4256
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ fn expand_variables(mut value: String, config: &Config) -> String {
const BUILD_BASE: &str = "{{build-base}}";
const SYSROOT_BASE: &str = "{{sysroot-base}}";
const TARGET_LINKER: &str = "{{target-linker}}";
const TARGET: &str = "{{target}}";

if value.contains(CWD) {
let cwd = env::current_dir().unwrap();
Expand All @@ -1303,6 +1304,10 @@ fn expand_variables(mut value: String, config: &Config) -> String {
value = value.replace(TARGET_LINKER, config.target_linker.as_deref().unwrap_or(""));
}

if value.contains(TARGET) {
value = value.replace(TARGET, &config.target);
}

value
}

Expand Down
6 changes: 3 additions & 3 deletions src/tools/tidy/src/target_specific_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ pub fn check(path: &Path, bad: &mut bool) {
} else if directive.starts_with(COMPILE_FLAGS_HEADER) {
let compile_flags = &directive[COMPILE_FLAGS_HEADER.len()..];
if let Some((_, v)) = compile_flags.split_once("--target") {
if let Some((arch, _)) =
v.trim_start_matches(|c| c == ' ' || c == '=').split_once("-")
{
let v = v.trim_start_matches(|c| c == ' ' || c == '=');
let v = if v == "{{target}}" { Some((v, v)) } else { v.split_once("-") };
if let Some((arch, _)) = v {
let info = header_map.entry(revision).or_insert(RevisionInfo::default());
info.target_arch.replace(arch);
} else {
Expand Down

0 comments on commit 5ed4256

Please sign in to comment.