Skip to content

Commit b38125c

Browse files
compiletest: Simplify handling of Clang-based tests.
1 parent ea4fb95 commit b38125c

File tree

6 files changed

+26
-109
lines changed

6 files changed

+26
-109
lines changed

src/bootstrap/test.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,13 +1106,11 @@ impl Step for Compiletest {
11061106
}).to_string()
11071107
})
11081108
};
1109-
let (lldb_exe, clang_exe) =
1110-
if builder.config.lldb_enabled && !target.contains("emscripten") {
1109+
let lldb_exe = if builder.config.lldb_enabled && !target.contains("emscripten") {
11111110
// Test against the lldb that was just built.
1112-
(builder.llvm_out(target).join("bin").join("lldb"),
1113-
builder.llvm_out(target).join("bin").join("clang"))
1111+
builder.llvm_out(target).join("bin").join("lldb")
11141112
} else {
1115-
(PathBuf::from("lldb"), PathBuf::from("clang"))
1113+
PathBuf::from("lldb")
11161114
};
11171115
let lldb_version = Command::new(&lldb_exe)
11181116
.arg("--version")
@@ -1127,19 +1125,14 @@ impl Step for Compiletest {
11271125
}
11281126
}
11291127

1130-
let clang_version = Command::new(&clang_exe)
1131-
.arg("--version")
1132-
.output()
1133-
.map(|output| { String::from_utf8_lossy(&output.stdout).to_string() })
1134-
.ok();
1135-
if let Some(ref vers) = clang_version {
1136-
cmd.arg("--clang-version").arg(vers);
1137-
}
1138-
11391128
if let Some(var) = env::var_os("RUSTBUILD_FORCE_CLANG_BASED_TESTS") {
1140-
match &var.to_string_lossy()[..] {
1129+
match &var.to_string_lossy().to_lowercase()[..] {
11411130
"1" | "yes" | "on" => {
1142-
cmd.arg("--force-clang-based-tests");
1131+
assert!(builder.config.lldb_enabled,
1132+
"RUSTBUILD_FORCE_CLANG_BASED_TESTS needs Clang/LLDB to \
1133+
be built.");
1134+
let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1135+
cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
11431136
}
11441137
"0" | "no" | "off" => {
11451138
// Nothing to do.

src/test/run-make-fulldeps/cross-lang-lto-clang/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ all: cpp-executable rust-executable
99

1010
cpp-executable:
1111
$(RUSTC) -Zcross-lang-lto=on -o $(TMPDIR)/librustlib-xlto.a -Copt-level=2 -Ccodegen-units=1 ./rustlib.rs
12-
clang -flto=thin -fuse-ld=lld -L $(TMPDIR) -lrustlib-xlto -o $(TMPDIR)/cmain ./cmain.c -O3
12+
$(CLANG) -flto=thin -fuse-ld=lld -L $(TMPDIR) -lrustlib-xlto -o $(TMPDIR)/cmain ./cmain.c -O3
1313
# Make sure we don't find a call instruction to the function we expect to
1414
# always be inlined.
1515
llvm-objdump -d $(TMPDIR)/cmain | $(CGREP) -v -e "call.*rust_always_inlined"
@@ -18,8 +18,8 @@ cpp-executable:
1818
llvm-objdump -d $(TMPDIR)/cmain | $(CGREP) -e "call.*rust_never_inlined"
1919

2020
rust-executable:
21-
clang ./clib.c -flto=thin -c -o $(TMPDIR)/clib.o -O2
21+
$(CLANG) ./clib.c -flto=thin -c -o $(TMPDIR)/clib.o -O2
2222
(cd $(TMPDIR); $(AR) crus ./libxyz.a ./clib.o)
23-
$(RUSTC) -Zcross-lang-lto=on -L$(TMPDIR) -Copt-level=2 -Clinker=clang -Clink-arg=-fuse-ld=lld ./main.rs -o $(TMPDIR)/rsmain
23+
$(RUSTC) -Zcross-lang-lto=on -L$(TMPDIR) -Copt-level=2 -Clinker=$(CLANG) -Clink-arg=-fuse-ld=lld ./main.rs -o $(TMPDIR)/rsmain
2424
llvm-objdump -d $(TMPDIR)/rsmain | $(CGREP) -e "call.*c_never_inlined"
2525
llvm-objdump -d $(TMPDIR)/rsmain | $(CGREP) -v -e "call.*c_always_inlined"

src/tools/compiletest/src/common.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ pub struct Config {
144144
/// (or, alternatively, to silently run them like regular run-pass tests).
145145
pub force_valgrind: bool,
146146

147-
/// Whether to fail if we don't have a clang version available that matches
148-
/// rustc's LLVM version.
149-
pub force_clang_based_tests: bool,
147+
/// The path to the Clang executable to run Clang-based tests with. If
148+
/// `None` then these tests will be ignored.
149+
pub run_clang_based_tests_with: Option<String>,
150150

151151
/// The directory containing the tests to run
152152
pub src_base: PathBuf,
@@ -209,9 +209,6 @@ pub struct Config {
209209
/// Is LLVM a system LLVM
210210
pub system_llvm: bool,
211211

212-
/// The version of Clang available to run-make tests (if any).
213-
pub clang_version: Option<String>,
214-
215212
/// Path to the android tools
216213
pub android_cross_path: PathBuf,
217214

src/tools/compiletest/src/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl EarlyProps {
112112
props.ignore = Ignore::Ignore;
113113
}
114114

115-
if !config.force_clang_based_tests &&
115+
if config.run_clang_based_tests_with.is_none() &&
116116
config.parse_needs_matching_clang(ln) {
117117
props.ignore = Ignore::Ignore;
118118
}

src/tools/compiletest/src/main.rs

Lines changed: 6 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,12 @@ pub mod util;
5050
fn main() {
5151
env_logger::init();
5252

53-
let mut config = parse_config(env::args().collect());
53+
let config = parse_config(env::args().collect());
5454

5555
if config.valgrind_path.is_none() && config.force_valgrind {
5656
panic!("Can't find Valgrind to run Valgrind tests");
5757
}
5858

59-
// Some run-make tests need a version of Clang available that matches
60-
// rustc's LLVM version. Since this isn't always the case, these tests are
61-
// opt-in.
62-
let clang_based_tests_possible = check_clang_based_tests_possible(&config);
63-
match (clang_based_tests_possible, config.force_clang_based_tests) {
64-
(Ok(_), true) |
65-
(Err(_), false) => {
66-
// Nothing to do
67-
}
68-
(Ok(_), false) => {
69-
// If a valid clang version is available, run the tests even if
70-
// they are not forced.
71-
config.force_clang_based_tests = true;
72-
}
73-
(Err(msg), true) => {
74-
// Tests are forced but we don't have a valid version of Clang.
75-
panic!("{}", msg)
76-
}
77-
}
78-
7959
log_config(&config);
8060
run_tests(&config);
8161
}
@@ -128,10 +108,11 @@ pub fn parse_config(args: Vec<String>) -> Config {
128108
"force-valgrind",
129109
"fail if Valgrind tests cannot be run under Valgrind",
130110
)
131-
.optflag(
111+
.optopt(
132112
"",
133-
"force-clang-based-tests",
134-
"fail if Clang-based run-make tests can't be run for some reason",
113+
"run-clang-based-tests-with",
114+
"path to Clang executable",
115+
"PATH",
135116
)
136117
.optopt(
137118
"",
@@ -214,12 +195,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
214195
"VERSION STRING",
215196
)
216197
.optflag("", "system-llvm", "is LLVM the system LLVM")
217-
.optopt(
218-
"",
219-
"clang-version",
220-
"the version of Clang available to run-make tests",
221-
"VERSION STRING",
222-
)
223198
.optopt(
224199
"",
225200
"android-cross-path",
@@ -329,7 +304,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
329304
docck_python: matches.opt_str("docck-python").unwrap(),
330305
valgrind_path: matches.opt_str("valgrind-path"),
331306
force_valgrind: matches.opt_present("force-valgrind"),
332-
force_clang_based_tests: matches.opt_present("force-clang-based-tests"),
307+
run_clang_based_tests_with: matches.opt_str("run-clang-based-tests-with"),
333308
llvm_filecheck: matches.opt_str("llvm-filecheck").map(|s| PathBuf::from(&s)),
334309
src_base,
335310
build_base: opt_path(matches, "build-base"),
@@ -355,7 +330,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
355330
lldb_native_rust,
356331
llvm_version: matches.opt_str("llvm-version"),
357332
system_llvm: matches.opt_present("system-llvm"),
358-
clang_version: matches.opt_str("clang-version"),
359333
android_cross_path: android_cross_path,
360334
adb_path: opt_str2(matches.opt_str("adb-path")),
361335
adb_test_dir: opt_str2(matches.opt_str("adb-test-dir")),
@@ -1064,54 +1038,3 @@ fn test_extract_gdb_version() {
10641038
7012050: "GNU gdb (GDB) 7.12.50.20161027-git",
10651039
}
10661040
}
1067-
1068-
1069-
fn check_clang_based_tests_possible(config: &Config) -> Result<(), String> {
1070-
1071-
let llvm_version = if let Some(llvm_version) = config.llvm_version.as_ref() {
1072-
llvm_version
1073-
} else {
1074-
return Err(format!("Running `compiletest` with `--force-clang-based-tests` \
1075-
requires `--llvm-version` to be specified."));
1076-
};
1077-
1078-
let clang_major_version = if let Some(ref version_string) = config.clang_version {
1079-
major_version_from_clang_version_string(version_string)?
1080-
} else {
1081-
return Err(format!("Clang is required for running tests \
1082-
(because of --force-clang-based-tests) \
1083-
but it does not seem to be available."));
1084-
};
1085-
1086-
let rustc_llvm_major_version = major_version_from_llvm_version_string(&llvm_version)?;
1087-
1088-
return if clang_major_version != rustc_llvm_major_version {
1089-
Err(format!("`--force-clang-based-tests` needs the major version of Clang \
1090-
and rustc's LLVM to be the same. Clang version is: {}, \
1091-
Rustc LLVM is: {}",
1092-
config.clang_version.clone().unwrap(),
1093-
llvm_version))
1094-
} else {
1095-
Ok(())
1096-
};
1097-
1098-
fn major_version_from_clang_version_string(clang_version: &str) -> Result<&str, String> {
1099-
let re = regex::Regex::new(r"clang version (\d)\.\d").unwrap();
1100-
if let Some(captures) = re.captures(clang_version) {
1101-
Ok(captures.get(1).unwrap().as_str())
1102-
} else {
1103-
Err(format!("Failed to parse major version from Clang version \
1104-
string '{}'.", clang_version))
1105-
}
1106-
}
1107-
1108-
fn major_version_from_llvm_version_string(llvm_version: &str) -> Result<&str, String> {
1109-
let re = regex::Regex::new(r"(\d)\.\d").unwrap();
1110-
if let Some(captures) = re.captures(llvm_version) {
1111-
Ok(captures.get(1).unwrap().as_str())
1112-
} else {
1113-
Err(format!("Failed to parse major version from LLVM version \
1114-
string '{}'.", llvm_version))
1115-
}
1116-
}
1117-
}

src/tools/compiletest/src/runtest.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,6 +2587,10 @@ impl<'test> TestCx<'test> {
25872587
cmd.env("RUSTC_LINKER", linker);
25882588
}
25892589

2590+
if let Some(ref clang) = self.config.run_clang_based_tests_with {
2591+
cmd.env("CLANG", clang);
2592+
}
2593+
25902594
// We don't want RUSTFLAGS set from the outside to interfere with
25912595
// compiler flags set in the test cases:
25922596
cmd.env_remove("RUSTFLAGS");

0 commit comments

Comments
 (0)