Resolve relative --config paths in xtask

Problem: relative .toml config paths don't resolve
when cargo is invoked from a subdirectory like kernel/.

Solution: convert relative paths to absolute against
the project root in the cargo() helper.
This commit is contained in:
yoda 2026-03-18 15:32:45 +00:00 committed by Sylvain Bellemare
parent e548696757
commit fa7e34d87a
No known key found for this signature in database
GPG key ID: C38AE0ECCAB7D5C8
2 changed files with 20 additions and 3 deletions

View file

@ -1518,13 +1518,27 @@ impl Builder {
pub fn cargo(configs: &[String]) -> Command {
let mut cmd = Command::new(env::var("CARGO").unwrap_or_else(|_| "cargo".to_string()));
for path in configs {
cmd.args(["--config", path]);
// Resolve relative paths against the project root so they stay valid
// when cargo is invoked from a subdirectory.
let abs_path = if Path::new(path).is_relative() {
project_root().join(path).to_string_lossy().into_owned()
} else {
path.to_owned()
};
cmd.args(["--config", &abs_path]);
}
cmd
}
pub fn project_root() -> PathBuf {
Path::new(&std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set — this binary must be run via cargo")).ancestors().nth(1).unwrap().to_path_buf()
Path::new(
&std::env::var("CARGO_MANIFEST_DIR")
.expect("CARGO_MANIFEST_DIR not set — this binary must be run via cargo"),
)
.ancestors()
.nth(1)
.unwrap()
.to_path_buf()
}
use std::fs::File;

View file

@ -401,7 +401,10 @@ pub(crate) fn wycheproof_import(cargo_configs: &[String]) -> Result<(), crate::D
Ok(())
}
pub(crate) fn track_language_changes(last_lang: &str, cargo_configs: &[String]) -> Result<(), crate::DynError> {
pub(crate) fn track_language_changes(
last_lang: &str,
cargo_configs: &[String],
) -> Result<(), crate::DynError> {
let last_config = "target/LAST_LANG";
let mut contents = String::new();