Skip to content

Commit f1ba23a

Browse files
feat: make codspeed target path different depending on measurement mode
1 parent e99360d commit f1ba23a

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

crates/cargo-codspeed/src/build.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl BuildOptions<'_> {
2626
&self,
2727
metadata: &Metadata,
2828
quiet: bool,
29-
measurement_mode: MeasurementMode,
29+
measurement_mode: &MeasurementMode,
3030
) -> Result<Vec<BuiltBench>> {
3131
let workspace_packages = metadata.workspace_packages();
3232

@@ -106,7 +106,7 @@ impl BuildOptions<'_> {
106106

107107
/// Generates a subcommand to build the benchmarks by invoking cargo and forwarding the filters
108108
/// This command explicitly ignores the `self.benches`: all benches are built
109-
fn build_command(&self, measurement_mode: MeasurementMode) -> Command {
109+
fn build_command(&self, measurement_mode: &MeasurementMode) -> Command {
110110
let mut cargo = Command::new("cargo");
111111
cargo.args(["build", "--benches"]);
112112

@@ -115,7 +115,7 @@ impl BuildOptions<'_> {
115115
rust_flags.push_str(" -C debuginfo=2");
116116

117117
// Add the codspeed cfg flag if instrumentation mode is enabled
118-
if measurement_mode == MeasurementMode::Instrumentation {
118+
if *measurement_mode == MeasurementMode::Instrumentation {
119119
rust_flags.push_str(" --cfg codspeed");
120120
}
121121
cargo.env("RUSTFLAGS", rust_flags);
@@ -165,7 +165,7 @@ pub fn build_benches(
165165
features: &features,
166166
profile: &profile,
167167
}
168-
.build(metadata, quiet, measurement_mode)?;
168+
.build(metadata, quiet, &measurement_mode)?;
169169

170170
if built_benches.is_empty() {
171171
bail!(
@@ -174,7 +174,7 @@ pub fn build_benches(
174174
);
175175
}
176176

177-
let codspeed_target_dir = get_codspeed_target_dir(metadata);
177+
let codspeed_target_dir = get_codspeed_target_dir(metadata, &measurement_mode);
178178
let built_bench_count = built_benches.len();
179179

180180
// Create and clear packages codspeed target directories

crates/cargo-codspeed/src/helpers.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
use crate::prelude::*;
1+
use crate::{measurement_mode::MeasurementMode, prelude::*};
22
use cargo_metadata::Metadata;
33
use std::path::{Path, PathBuf};
44

5-
pub fn get_codspeed_target_dir(metadata: &Metadata) -> PathBuf {
6-
metadata.target_directory.join("codspeed").into()
5+
pub fn get_codspeed_target_dir(metadata: &Metadata, measurement_mode: &MeasurementMode) -> PathBuf {
6+
let target_dir: PathBuf = metadata.target_directory.join("codspeed").into();
7+
8+
target_dir.join(measurement_mode)
79
}
810

911
pub fn clear_dir<P>(dir: P) -> Result<()>

crates/cargo-codspeed/src/measurement_mode.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clap::ValueEnum;
22
use serde::Serialize;
3-
use std::env;
3+
use std::{env, path::Path};
44

55
#[derive(Debug, Clone, ValueEnum, Serialize, PartialEq, Eq)]
66
#[serde(rename_all = "lowercase")]
@@ -18,3 +18,12 @@ impl Default for MeasurementMode {
1818
}
1919
}
2020
}
21+
22+
impl AsRef<Path> for MeasurementMode {
23+
fn as_ref(&self) -> &Path {
24+
match self {
25+
MeasurementMode::Walltime => Path::new("walltime"),
26+
MeasurementMode::Instrumentation => Path::new("instrumentation"),
27+
}
28+
}
29+
}

crates/cargo-codspeed/src/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn run_benches(
9999
filters: Filters,
100100
measurement_mode: MeasurementMode,
101101
) -> Result<()> {
102-
let codspeed_target_dir = get_codspeed_target_dir(metadata);
102+
let codspeed_target_dir = get_codspeed_target_dir(metadata, &measurement_mode);
103103
let workspace_root = metadata.workspace_root.as_std_path();
104104
if measurement_mode == MeasurementMode::Walltime {
105105
clear_raw_walltime_data(workspace_root)?;

0 commit comments

Comments
 (0)