-
Notifications
You must be signed in to change notification settings - Fork 12.1k
/
rmake.rs
68 lines (53 loc) · 1.77 KB
/
rmake.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! This checks the output of some `--print` options when
//! output to a file (instead of stdout)
extern crate run_make_support;
use std::ffi::OsString;
use run_make_support::{rustc, target, tmp_dir};
struct Option<'a> {
target: &'a str,
option: &'static str,
includes: &'static [&'static 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);
}
}
// --print={option}
let stdout = {
let output = rustc().target(args.target).print(args.option).run();
String::from_utf8(output.stdout).unwrap()
};
// --print={option}=PATH
let output = {
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(args.target).arg(print_arg).run();
std::fs::read_to_string(&tmp_path).unwrap()
};
check_(&stdout, args.includes);
check_(&output, args.includes);
assert_eq!(&stdout, &output);
}