Skip to content

Commit 3861591

Browse files
committed
Rollup merge of #54645 - tromey:android-gdb-version, r=alexcrichton
Compute Android gdb version in compiletest compiletest has special code for running gdb for Android targets. In particular it computes a different path to gdb. However, this gdb is not used for the version test, which results in some tests being run when they should not be. You can see this in #54004. This patch moves the special case to analyze_gdb and a new helper function to decide whether the case applies. This causes the version check to work properly. Note that the bulk of the runtest.rs change is just reindentation caused by moving from a "match" to an "if" -- but there is a (small) change buried in there.
2 parents c1b2dc2 + e545dc9 commit 3861591

File tree

2 files changed

+225
-203
lines changed

2 files changed

+225
-203
lines changed

Diff for: src/tools/compiletest/src/main.rs

+35-9
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ pub fn parse_config(args: Vec<String>) -> Config {
278278
}
279279
}
280280

281-
let (gdb, gdb_version, gdb_native_rust) = analyze_gdb(matches.opt_str("gdb"));
281+
let target = opt_str2(matches.opt_str("target"));
282+
let android_cross_path = opt_path(matches, "android-cross-path");
283+
let (gdb, gdb_version, gdb_native_rust) = analyze_gdb(matches.opt_str("gdb"), &target,
284+
&android_cross_path);
282285

283286
let color = match matches.opt_str("color").as_ref().map(|x| &**x) {
284287
Some("auto") | None => ColorConfig::AutoColor,
@@ -318,15 +321,15 @@ pub fn parse_config(args: Vec<String>) -> Config {
318321
runtool: matches.opt_str("runtool"),
319322
host_rustcflags: matches.opt_str("host-rustcflags"),
320323
target_rustcflags: matches.opt_str("target-rustcflags"),
321-
target: opt_str2(matches.opt_str("target")),
324+
target: target,
322325
host: opt_str2(matches.opt_str("host")),
323326
gdb,
324327
gdb_version,
325328
gdb_native_rust,
326329
lldb_version: extract_lldb_version(matches.opt_str("lldb-version")),
327330
llvm_version: matches.opt_str("llvm-version"),
328331
system_llvm: matches.opt_present("system-llvm"),
329-
android_cross_path: opt_path(matches, "android-cross-path"),
332+
android_cross_path: android_cross_path,
330333
adb_path: opt_str2(matches.opt_str("adb-path")),
331334
adb_test_dir: opt_str2(matches.opt_str("adb-test-dir")),
332335
adb_device_status: opt_str2(matches.opt_str("target")).contains("android")
@@ -780,23 +783,46 @@ fn make_test_closure(
780783
}))
781784
}
782785

786+
/// Returns true if the given target is an Android target for the
787+
/// purposes of GDB testing.
788+
fn is_android_gdb_target(target: &String) -> bool {
789+
match &target[..] {
790+
"arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => true,
791+
_ => false,
792+
}
793+
}
794+
783795
/// Returns (Path to GDB, GDB Version, GDB has Rust Support)
784-
fn analyze_gdb(gdb: Option<String>) -> (Option<String>, Option<u32>, bool) {
796+
fn analyze_gdb(gdb: Option<String>, target: &String, android_cross_path: &PathBuf)
797+
-> (Option<String>, Option<u32>, bool) {
785798
#[cfg(not(windows))]
786799
const GDB_FALLBACK: &str = "gdb";
787800
#[cfg(windows)]
788801
const GDB_FALLBACK: &str = "gdb.exe";
789802

790803
const MIN_GDB_WITH_RUST: u32 = 7011010;
791804

805+
let fallback_gdb = || {
806+
if is_android_gdb_target(target) {
807+
let mut gdb_path = match android_cross_path.to_str() {
808+
Some(x) => x.to_owned(),
809+
None => panic!("cannot find android cross path"),
810+
};
811+
gdb_path.push_str("/bin/gdb");
812+
gdb_path
813+
} else {
814+
GDB_FALLBACK.to_owned()
815+
}
816+
};
817+
792818
let gdb = match gdb {
793-
None => GDB_FALLBACK,
794-
Some(ref s) if s.is_empty() => GDB_FALLBACK, // may be empty if configure found no gdb
795-
Some(ref s) => s,
819+
None => fallback_gdb(),
820+
Some(ref s) if s.is_empty() => fallback_gdb(), // may be empty if configure found no gdb
821+
Some(ref s) => s.to_owned(),
796822
};
797823

798824
let mut version_line = None;
799-
if let Ok(output) = Command::new(gdb).arg("--version").output() {
825+
if let Ok(output) = Command::new(&gdb).arg("--version").output() {
800826
if let Some(first_line) = String::from_utf8_lossy(&output.stdout).lines().next() {
801827
version_line = Some(first_line.to_string());
802828
}
@@ -809,7 +835,7 @@ fn analyze_gdb(gdb: Option<String>) -> (Option<String>, Option<u32>, bool) {
809835

810836
let gdb_native_rust = version.map_or(false, |v| v >= MIN_GDB_WITH_RUST);
811837

812-
(Some(gdb.to_owned()), version, gdb_native_rust)
838+
(Some(gdb), version, gdb_native_rust)
813839
}
814840

815841
fn extract_gdb_version(full_version_line: &str) -> Option<u32> {

0 commit comments

Comments
 (0)