Skip to content

Commit 70676dc

Browse files
fix: resolve working_directory relative to config file, not CWD
When running `codspeed run` with config targets, the `working-directory` option is now resolved relative to the config file's directory instead of the current working directory. When no `working-directory` is set, it defaults to the config file's directory. For `codspeed run -- command` and `codspeed exec`, the config's `working-directory` is explicitly ignored — only the `--working-directory` CLI flag is used. A warning is emitted if `--working-directory` is passed in config targets mode.
1 parent 6ff891c commit 70676dc

File tree

5 files changed

+465
-3
lines changed

5 files changed

+465
-3
lines changed

Cargo.lock

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ test-with = { version = "0.15", default-features = false, features = [] }
8383
rstest = { version = "0.25.0", default-features = false }
8484
rstest_reuse = "0.7.0"
8585
shell-quote = "0.7.2"
86+
assert_cmd = "2.0.16"
87+
predicates = "3.1.4"
8688

8789
[workspace]
8890
members = [

src/cli/run/mod.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ pub async fn run(
181181

182182
match run_target {
183183
RunTarget::SingleCommand(args) => {
184+
// SingleCommand: working_directory comes from --working-directory CLI flag only.
185+
// Config file's working-directory is NOT used.
184186
let command = args.command.join(" ");
185187
let config = build_orchestrator_config(
186188
args,
@@ -190,6 +192,7 @@ pub async fn run(
190192
}],
191193
PollResultsOptions::for_run(output_json),
192194
)?;
195+
193196
let orchestrator =
194197
executor::Orchestrator::new(config, codspeed_config, api_client).await?;
195198

@@ -206,10 +209,44 @@ pub async fn run(
206209
targets,
207210
default_walltime,
208211
} => {
212+
// ConfigTargets: working_directory is resolved relative to config file dir.
213+
// If --working-directory CLI flag is passed, ignore it with a warning.
214+
if args.shared.working_directory.is_some() {
215+
// Intentionally using eprintln! because logger has not been initialized yet.
216+
eprintln!(
217+
"Warning: The --working-directory flag is ignored when running targets from the config file. \
218+
Use the `working-directory` option in the config file instead."
219+
);
220+
}
221+
222+
// Resolve working_directory relative to config file directory
223+
let resolved_working_directory =
224+
if let Some(config_dir) = discovered_config.and_then(|d| d.config_dir()) {
225+
let root_wd = project_config
226+
.and_then(|c| c.options.as_ref())
227+
.and_then(|o| o.working_directory.as_ref());
228+
229+
match root_wd {
230+
Some(wd) => {
231+
let wd_path = Path::new(wd);
232+
if wd_path.is_absolute() {
233+
Some(wd.clone())
234+
} else {
235+
Some(config_dir.join(wd).to_string_lossy().into_owned())
236+
}
237+
}
238+
None => Some(config_dir.to_string_lossy().into_owned()),
239+
}
240+
} else {
241+
None
242+
};
243+
209244
let benchmark_targets =
210245
super::exec::multi_targets::build_benchmark_targets(targets, default_walltime)?;
211-
let config =
246+
let mut config =
212247
build_orchestrator_config(args, benchmark_targets, PollResultsOptions::for_exec())?;
248+
config.working_directory = resolved_working_directory;
249+
213250
super::exec::execute_config(config, api_client, codspeed_config, setup_cache_dir)
214251
.await?;
215252
}

src/project_config/discover.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const CONFIG_FILENAMES: &[&str] = &[
1313

1414
/// A project configuration paired with the path it was loaded from.
1515
#[derive(Debug)]
16-
#[allow(dead_code)]
1716
pub struct DiscoveredProjectConfig {
1817
pub config: ProjectConfig,
1918
pub path: PathBuf,
@@ -64,7 +63,6 @@ impl DiscoveredProjectConfig {
6463
}
6564

6665
/// Returns the directory containing the config file.
67-
#[allow(dead_code)]
6866
pub fn config_dir(&self) -> Option<PathBuf> {
6967
let canonical_path = self
7068
.path

0 commit comments

Comments
 (0)