2024-08-26 05:20:32 -05:00
|
|
|
//! This checks the output of some `--print` options when output to a file (instead of stdout)
|
|
|
|
|
|
|
|
// ignore-tidy-linelength
|
|
|
|
//@ needs-llvm-components: aarch64 arm avr bpf csky hexagon loongarch m68k mips msp430 nvptx powerpc riscv sparc systemz webassembly x86
|
|
|
|
// FIXME(jieyouxu): there has to be a better way to do this, without the needs-llvm-components it
|
|
|
|
// will fail on LLVM built without all of the components listed above. If adding a new target that
|
|
|
|
// relies on a llvm component not listed above, it will need to be added to the required llvm
|
|
|
|
// components above.
|
2024-04-28 07:44:30 -05:00
|
|
|
|
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 07:44:30 -05:00
|
|
|
|
2024-07-17 16:54:06 -05:00
|
|
|
rustc().target(args.target).print(&format!("{}={}", args.option, tmp_path.display())).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);
|
|
|
|
}
|