2024-04-28 07:44:30 -05:00
|
|
|
//! This checks the output of some `--print` options when
|
|
|
|
//! output to a file (instead of stdout)
|
|
|
|
|
|
|
|
use std::ffi::OsString;
|
2024-06-06 14:34:34 -05:00
|
|
|
use std::path::PathBuf;
|
2024-04-28 07:44:30 -05:00
|
|
|
|
2024-07-17 08:31:38 -05:00
|
|
|
use run_make_support::{rfs, rustc, target};
|
2024-04-28 07:44:30 -05:00
|
|
|
|
2024-04-28 10:17:18 -05:00
|
|
|
struct Option<'a> {
|
|
|
|
target: &'a str,
|
|
|
|
option: &'static str,
|
|
|
|
includes: &'static [&'static str],
|
|
|
|
}
|
|
|
|
|
2024-04-28 07:44:30 -05:00
|
|
|
fn main() {
|
|
|
|
// Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs
|
2024-05-02 05:37:13 -05:00
|
|
|
check(Option { target: &target(), option: "relocation-models", includes: &["dynamic-no-pic"] });
|
2024-04-28 07:44:30 -05:00
|
|
|
|
|
|
|
// Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs
|
2024-04-28 10:17:18 -05:00
|
|
|
check(Option {
|
|
|
|
target: "wasm32-unknown-unknown",
|
|
|
|
option: "target-features",
|
|
|
|
includes: &["reference-types"],
|
|
|
|
});
|
2024-04-28 07:44:30 -05:00
|
|
|
|
|
|
|
// Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp
|
2024-04-28 10:17:18 -05:00
|
|
|
check(Option {
|
|
|
|
target: "wasm32-unknown-unknown",
|
|
|
|
option: "target-cpus",
|
|
|
|
includes: &["generic"],
|
|
|
|
});
|
2024-04-28 07:44:30 -05:00
|
|
|
}
|
|
|
|
|
2024-04-28 10:17:18 -05:00
|
|
|
fn check(args: Option) {
|
|
|
|
fn check_(output: &str, includes: &[&str]) {
|
2024-04-28 07:44:30 -05:00
|
|
|
for i in includes {
|
|
|
|
assert!(output.contains(i), "output doesn't contains: {}", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --print={option}
|
2024-06-07 08:23:10 -05:00
|
|
|
let stdout = rustc().target(args.target).print(args.option).run().stdout_utf8();
|
2024-04-28 07:44:30 -05:00
|
|
|
|
|
|
|
// --print={option}=PATH
|
|
|
|
let output = {
|
2024-06-06 14:34:34 -05:00
|
|
|
let tmp_path = PathBuf::from(format!("{}.txt", args.option));
|
2024-04-28 10:17:18 -05:00
|
|
|
let mut print_arg = OsString::from(format!("--print={}=", args.option));
|
2024-04-28 07:44:30 -05:00
|
|
|
print_arg.push(tmp_path.as_os_str());
|
|
|
|
|
2024-06-07 08:23:10 -05:00
|
|
|
rustc().target(args.target).arg(print_arg).run();
|
2024-04-28 07:44:30 -05:00
|
|
|
|
2024-07-17 07:42:06 -05:00
|
|
|
rfs::read_to_string(&tmp_path)
|
2024-04-28 07:44:30 -05:00
|
|
|
};
|
|
|
|
|
2024-04-28 10:17:18 -05:00
|
|
|
check_(&stdout, args.includes);
|
|
|
|
check_(&output, args.includes);
|
|
|
|
|
2024-04-28 07:44:30 -05:00
|
|
|
assert_eq!(&stdout, &output);
|
|
|
|
}
|