Use named struct arguments instead of comment named args

This commit is contained in:
Urgau 2024-04-28 17:17:18 +02:00
parent 607497d57c
commit 006c94cfa1
2 changed files with 74 additions and 67 deletions

View File

@ -14,36 +14,42 @@ use std::iter::FromIterator;
use run_make_support::{rustc, tmp_dir};
fn main() {
check(
/*target*/ "x86_64-pc-windows-gnu",
/*includes*/ &["windows", "target_arch=\"x86_64\""],
/*disallow*/ &["unix"],
);
check(
/*target*/ "i686-pc-windows-msvc",
/*includes*/ &["windows", "target_env=\"msvc\""],
/*disallow*/ &["unix"],
);
check(
/*target*/ "i686-apple-darwin",
/*includes*/ &["unix", "target_os=\"macos\"", "target_vendor=\"apple\""],
/*disallow*/ &["windows"],
);
check(
/*target*/ "i686-unknown-linux-gnu",
/*includes*/ &["unix", "target_env=\"gnu\""],
/*disallow*/ &["windows"],
);
check(
/*target*/ "arm-unknown-linux-gnueabihf",
/*includes*/ &["unix", "target_abi=\"eabihf\""],
/*disallow*/ &["windows"],
);
struct PrintCfg {
target: &'static str,
includes: &'static [&'static str],
disallow: &'static [&'static str],
}
fn check(target: &str, includes: &[&str], disallow: &[&str]) {
fn _inner(output: &str, includes: &[&str], disallow: &[&str]) {
fn main() {
check(PrintCfg {
target: "x86_64-pc-windows-gnu",
includes: &["windows", "target_arch=\"x86_64\""],
disallow: &["unix"],
});
check(PrintCfg {
target: "i686-pc-windows-msvc",
includes: &["windows", "target_env=\"msvc\""],
disallow: &["unix"],
});
check(PrintCfg {
target: "i686-apple-darwin",
includes: &["unix", "target_os=\"macos\"", "target_vendor=\"apple\""],
disallow: &["windows"],
});
check(PrintCfg {
target: "i686-unknown-linux-gnu",
includes: &["unix", "target_env=\"gnu\""],
disallow: &["windows"],
});
check(PrintCfg {
target: "arm-unknown-linux-gnueabihf",
includes: &["unix", "target_abi=\"eabihf\""],
disallow: &["windows"],
});
}
fn check(PrintCfg { target, includes, disallow }: PrintCfg) {
fn check_(output: &str, includes: &[&str], disallow: &[&str]) {
let mut found = HashSet::<String>::new();
let mut recorded = HashSet::<String>::new();
@ -82,7 +88,7 @@ fn check(target: &str, includes: &[&str], disallow: &[&str]) {
let stdout = String::from_utf8(output.stdout).unwrap();
_inner(&stdout, includes, disallow);
check_(&stdout, includes, disallow);
}
// --print=cfg=PATH
@ -95,6 +101,6 @@ fn check(target: &str, includes: &[&str], disallow: &[&str]) {
let output = std::fs::read_to_string(&tmp_path).unwrap();
_inner(&output, includes, disallow);
check_(&output, includes, disallow);
}
}

View File

@ -7,31 +7,37 @@ use std::ffi::OsString;
use run_make_support::{rustc, target, tmp_dir};
fn main() {
// Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs
check(
/*target*/ &target(),
/*option*/ "relocation-models",
/*includes*/ &["dynamic-no-pic"],
);
// Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs
check(
/*target*/ "wasm32-unknown-unknown",
/*option*/ "target-features",
/*includes*/ &["reference-types"],
);
// Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp
check(
/*target*/ "wasm32-unknown-unknown",
/*option*/ "target-cpus",
/*includes*/ &["generic"],
);
struct Option<'a> {
target: &'a str,
option: &'static str,
includes: &'static [&'static str],
}
fn check(target: &str, option: &str, includes: &[&str]) {
fn _inner(output: &str, includes: &[&str]) {
fn main() {
// Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs
check(Option {
target: &target(),
option: "relocation-models",
includes: &["dynamic-no-pic"],
});
// Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs
check(Option {
target: "wasm32-unknown-unknown",
option: "target-features",
includes: &["reference-types"],
});
// Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp
check(Option {
target: "wasm32-unknown-unknown",
option: "target-cpus",
includes: &["generic"],
});
}
fn check(args: Option) {
fn check_(output: &str, includes: &[&str]) {
for i in includes {
assert!(output.contains(i), "output doesn't contains: {}", i);
}
@ -39,29 +45,24 @@ fn check(target: &str, option: &str, includes: &[&str]) {
// --print={option}
let stdout = {
let output = rustc().target(target).print(option).run();
let output = rustc().target(args.target).print(args.option).run();
let stdout = String::from_utf8(output.stdout).unwrap();
_inner(&stdout, includes);
stdout
String::from_utf8(output.stdout).unwrap()
};
// --print={option}=PATH
let output = {
let tmp_path = tmp_dir().join(format!("{option}.txt"));
let mut print_arg = OsString::from(format!("--print={option}="));
let tmp_path = tmp_dir().join(format!("{}.txt", args.option));
let mut print_arg = OsString::from(format!("--print={}=", args.option));
print_arg.push(tmp_path.as_os_str());
let _output = rustc().target(target).arg(print_arg).run();
let _output = rustc().target(args.target).arg(print_arg).run();
let output = std::fs::read_to_string(&tmp_path).unwrap();
_inner(&output, includes);
output
std::fs::read_to_string(&tmp_path).unwrap()
};
check_(&stdout, args.includes);
check_(&output, args.includes);
assert_eq!(&stdout, &output);
}