Skip to content

Commit 5440839

Browse files
committed
Refactor creation of a published artifact out of bench_published_artifact
1 parent e275af4 commit 5440839

File tree

2 files changed

+54
-52
lines changed

2 files changed

+54
-52
lines changed

collector/src/bin/collector.rs

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ use collector::compile::execute::profiler::{ProfileProcessor, Profiler};
3030
use collector::runtime::{
3131
bench_runtime, runtime_benchmark_dir, BenchmarkFilter, CargoIsolationMode,
3232
};
33-
use collector::toolchain::{get_local_toolchain, Sysroot, Toolchain};
33+
use collector::toolchain::{
34+
create_toolchain_from_published_version, get_local_toolchain, Sysroot, Toolchain,
35+
};
3436

3537
fn n_normal_benchmarks_remaining(n: usize) -> String {
3638
let suffix = if n == 1 { "" } else { "s" };
@@ -827,13 +829,8 @@ fn main_result() -> anyhow::Result<i32> {
827829

828830
match next {
829831
NextArtifact::Release(tag) => {
830-
bench_published_artifact(
831-
tag,
832-
pool,
833-
&mut rt,
834-
&target_triple,
835-
&compile_benchmark_dir,
836-
)?;
832+
let toolchain = create_toolchain_from_published_version(&tag, &target_triple)?;
833+
bench_published_artifact(&toolchain, pool, &mut rt, &compile_benchmark_dir)?;
837834

838835
client.post(format!("{}/perf/onpush", site_url)).send()?;
839836
}
@@ -885,13 +882,8 @@ fn main_result() -> anyhow::Result<i32> {
885882

886883
Commands::BenchPublished { toolchain, db } => {
887884
let pool = database::Pool::open(&db.db);
888-
bench_published_artifact(
889-
toolchain,
890-
pool,
891-
&mut rt,
892-
&target_triple,
893-
&compile_benchmark_dir,
894-
)?;
885+
let toolchain = create_toolchain_from_published_version(&toolchain, &target_triple)?;
886+
bench_published_artifact(&toolchain, pool, &mut rt, &compile_benchmark_dir)?;
895887
Ok(0)
896888
}
897889

@@ -1052,53 +1044,27 @@ async fn init_compile_collector(
10521044
}
10531045

10541046
fn bench_published_artifact(
1055-
toolchain: String,
1047+
toolchain: &Toolchain,
10561048
pool: Pool,
10571049
rt: &mut Runtime,
1058-
target_triple: &str,
10591050
benchmark_dir: &Path,
10601051
) -> anyhow::Result<()> {
1061-
let status = Command::new("rustup")
1062-
.args(["install", "--profile=minimal", &toolchain])
1063-
.status()
1064-
.context("rustup install")?;
1065-
if !status.success() {
1066-
anyhow::bail!("failed to install toolchain for {}", toolchain);
1067-
}
1068-
1069-
let profiles = if collector::version_supports_doc(&toolchain) {
1052+
let profiles = if collector::version_supports_doc(&toolchain.id) {
10701053
Profile::all()
10711054
} else {
10721055
Profile::all_non_doc()
10731056
};
1074-
let scenarios = if collector::version_supports_incremental(&toolchain) {
1057+
let scenarios = if collector::version_supports_incremental(&toolchain.id) {
10751058
Scenario::all()
10761059
} else {
10771060
Scenario::all_non_incr()
10781061
};
10791062

1080-
let which = |tool| {
1081-
String::from_utf8(
1082-
Command::new("rustup")
1083-
.arg("which")
1084-
.arg("--toolchain")
1085-
.arg(&toolchain)
1086-
.arg(tool)
1087-
.output()
1088-
.context(format!("rustup which {}", tool))?
1089-
.stdout,
1090-
)
1091-
.context("utf8")
1092-
};
1093-
let rustc = which("rustc")?;
1094-
let rustdoc = which("rustdoc")?;
1095-
let cargo = which("cargo")?;
1096-
10971063
// Exclude benchmarks that don't work with a stable compiler.
10981064
let mut benchmarks = get_compile_benchmarks(benchmark_dir, None, None, None)?;
10991065
benchmarks.retain(|b| b.category().is_stable());
11001066

1101-
let artifact_id = ArtifactId::Tag(toolchain.clone());
1067+
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
11021068
let (conn, collector) = rt.block_on(init_compile_collector(
11031069
&pool,
11041070
&benchmarks,
@@ -1110,13 +1076,7 @@ fn bench_published_artifact(
11101076
conn,
11111077
&profiles,
11121078
&scenarios,
1113-
&Toolchain {
1114-
rustc: PathBuf::from(rustc.trim()),
1115-
rustdoc: Some(PathBuf::from(rustdoc.trim())),
1116-
cargo: PathBuf::from(cargo.trim()),
1117-
id: toolchain,
1118-
triple: target_triple.to_string(),
1119-
},
1079+
toolchain,
11201080
&benchmarks,
11211081
Some(3),
11221082
/* is_self_profile */ false,

collector/src/toolchain.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,45 @@ pub fn get_local_toolchain(
382382
triple: target_triple,
383383
})
384384
}
385+
386+
/// Creates a toolchain from a *published* toolchain downloaded by rustup.
387+
pub fn create_toolchain_from_published_version(
388+
toolchain: &str,
389+
target_triple: &str,
390+
) -> anyhow::Result<Toolchain> {
391+
let status = Command::new("rustup")
392+
.args(["install", "--profile=minimal", toolchain])
393+
.status()
394+
.context("rustup install")?;
395+
if !status.success() {
396+
return Err(anyhow::anyhow!(
397+
"failed to install toolchain for {toolchain}",
398+
));
399+
}
400+
401+
let which = |tool| -> anyhow::Result<PathBuf> {
402+
let path = String::from_utf8(
403+
Command::new("rustup")
404+
.arg("which")
405+
.arg("--toolchain")
406+
.arg(toolchain)
407+
.arg(tool)
408+
.output()
409+
.context(format!("rustup which {tool}"))?
410+
.stdout,
411+
)
412+
.context("utf8")?;
413+
Ok(PathBuf::from(path.trim()))
414+
};
415+
let rustc = which("rustc")?;
416+
let rustdoc = which("rustdoc")?;
417+
let cargo = which("cargo")?;
418+
419+
Ok(Toolchain {
420+
rustc,
421+
rustdoc: Some(rustdoc),
422+
cargo,
423+
id: toolchain.to_string(),
424+
triple: target_triple.to_string(),
425+
})
426+
}

0 commit comments

Comments
 (0)