Skip to content

Commit bcfbd74

Browse files
committed
Extract some discovery code for debuginfo tests into submodules
1 parent e9f3603 commit bcfbd74

File tree

6 files changed

+93
-29
lines changed

6 files changed

+93
-29
lines changed

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::core::builder::{
2929
};
3030
use crate::core::config::TargetSelection;
3131
use crate::core::config::flags::{Subcommand, get_completion, top_level_help};
32+
use crate::core::debuggers;
3233
use crate::utils::build_stamp::{self, BuildStamp};
3334
use crate::utils::exec::{BootstrapCommand, command};
3435
use crate::utils::helpers::{
@@ -38,8 +39,6 @@ use crate::utils::helpers::{
3839
use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
3940
use crate::{CLang, CodegenBackendKind, DocTests, GitRepo, Mode, PathSet, envify};
4041

41-
const ADB_TEST_DIR: &str = "/data/local/tmp/work";
42-
4342
/// Runs `cargo test` on various internal tools used by bootstrap.
4443
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
4544
pub struct CrateBootstrap {
@@ -2082,39 +2081,24 @@ Please disable assertions with `rust.debug-assertions = false`.
20822081
// modes, even though they should only be needed in "debuginfo" mode,
20832082
// because the GDB-discovery code in compiletest currently assumes that
20842083
// `--android-cross-path` is always set for Android targets.
2085-
cmd.arg("--adb-path").arg("adb");
2086-
cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
2087-
if target.contains("android") && !builder.config.dry_run() {
2088-
// Assume that cc for this target comes from the android sysroot
2089-
cmd.arg("--android-cross-path")
2090-
.arg(builder.cc(target).parent().unwrap().parent().unwrap());
2091-
} else {
2092-
cmd.arg("--android-cross-path").arg("");
2084+
if let Some(debuggers::Android { adb_path, adb_test_dir, android_cross_path }) =
2085+
debuggers::discover_android(builder, target)
2086+
{
2087+
cmd.arg("--adb-path").arg(adb_path);
2088+
cmd.arg("--adb-test-dir").arg(adb_test_dir);
2089+
cmd.arg("--android-cross-path").arg(android_cross_path);
20932090
}
20942091

20952092
if mode == "debuginfo" {
2096-
if let Some(ref gdb) = builder.config.gdb {
2093+
if let Some(debuggers::Gdb { gdb }) = debuggers::discover_gdb(builder) {
20972094
cmd.arg("--gdb").arg(gdb);
20982095
}
20992096

2100-
let lldb_exe = builder.config.lldb.clone().unwrap_or_else(|| PathBuf::from("lldb"));
2101-
let lldb_version = command(&lldb_exe)
2102-
.allow_failure()
2103-
.arg("--version")
2104-
.run_capture(builder)
2105-
.stdout_if_ok()
2106-
.and_then(|v| if v.trim().is_empty() { None } else { Some(v) });
2107-
if let Some(ref vers) = lldb_version {
2108-
cmd.arg("--lldb-version").arg(vers);
2109-
let lldb_python_dir = command(&lldb_exe)
2110-
.allow_failure()
2111-
.arg("-P")
2112-
.run_capture_stdout(builder)
2113-
.stdout_if_ok()
2114-
.map(|p| p.lines().next().expect("lldb Python dir not found").to_string());
2115-
if let Some(ref dir) = lldb_python_dir {
2116-
cmd.arg("--lldb-python-dir").arg(dir);
2117-
}
2097+
if let Some(debuggers::Lldb { lldb_version, lldb_python_dir }) =
2098+
debuggers::discover_lldb(builder)
2099+
{
2100+
cmd.arg("--lldb-version").arg(lldb_version);
2101+
cmd.arg("--lldb-python-dir").arg(lldb_python_dir);
21182102
}
21192103
}
21202104

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::path::PathBuf;
2+
3+
use crate::core::builder::Builder;
4+
use crate::core::config::TargetSelection;
5+
6+
pub(crate) struct Android {
7+
pub(crate) adb_path: &'static str,
8+
pub(crate) adb_test_dir: &'static str,
9+
pub(crate) android_cross_path: PathBuf,
10+
}
11+
12+
pub(crate) fn discover_android(builder: &Builder<'_>, target: TargetSelection) -> Option<Android> {
13+
let adb_path = "adb";
14+
// See <https://github.com/rust-lang/rust/pull/102755>.
15+
let adb_test_dir = "/data/local/tmp/work";
16+
17+
let android_cross_path = if target.contains("android") && !builder.config.dry_run() {
18+
builder.cc(target).parent().unwrap().parent().unwrap().to_owned()
19+
} else {
20+
PathBuf::new()
21+
};
22+
23+
Some(Android { adb_path, adb_test_dir, android_cross_path })
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::path::Path;
2+
3+
use crate::core::builder::Builder;
4+
5+
pub(crate) struct Gdb<'a> {
6+
pub(crate) gdb: &'a Path,
7+
}
8+
9+
pub(crate) fn discover_gdb<'a>(builder: &'a Builder<'_>) -> Option<Gdb<'a>> {
10+
let gdb = builder.config.gdb.as_deref()?;
11+
12+
Some(Gdb { gdb })
13+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::path::PathBuf;
2+
3+
use crate::core::builder::Builder;
4+
use crate::utils::exec::command;
5+
6+
pub(crate) struct Lldb {
7+
pub(crate) lldb_version: String,
8+
pub(crate) lldb_python_dir: String,
9+
}
10+
11+
pub(crate) fn discover_lldb(builder: &Builder<'_>) -> Option<Lldb> {
12+
// FIXME(#148361): We probably should not be picking up whatever arbitrary
13+
// lldb happens to be in the user's path, and instead require some kind of
14+
// explicit opt-in or configuration.
15+
let lldb_exe = builder.config.lldb.clone().unwrap_or_else(|| PathBuf::from("lldb"));
16+
17+
let lldb_version = command(&lldb_exe)
18+
.allow_failure()
19+
.arg("--version")
20+
.run_capture(builder)
21+
.stdout_if_ok()
22+
.and_then(|v| if v.trim().is_empty() { None } else { Some(v) })?;
23+
24+
let lldb_python_dir = command(&lldb_exe)
25+
.allow_failure()
26+
.arg("-P")
27+
.run_capture_stdout(builder)
28+
.stdout_if_ok()
29+
.map(|p| p.lines().next().expect("lldb Python dir not found").to_string())?;
30+
31+
Some(Lldb { lldb_version, lldb_python_dir })
32+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! Code for discovering debuggers and debugger-related configuration, so that
2+
//! it can be passed to compiletest when running debuginfo tests.
3+
4+
pub(crate) use self::android::{Android, discover_android};
5+
pub(crate) use self::gdb::{Gdb, discover_gdb};
6+
pub(crate) use self::lldb::{Lldb, discover_lldb};
7+
8+
mod android;
9+
mod gdb;
10+
mod lldb;

src/bootstrap/src/core/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub(crate) mod build_steps;
22
pub(crate) mod builder;
33
pub(crate) mod config;
4+
pub(crate) mod debuggers;
45
pub(crate) mod download;
56
pub(crate) mod metadata;
67
pub(crate) mod sanity;

0 commit comments

Comments
 (0)