Change new workspace root finding error message
Not finding a parent Cargo.toml file should have a different error message than the environment variable being empty.
This commit is contained in:
parent
59be30205a
commit
ae8c78c5e5
|
@ -124,18 +124,28 @@ pub fn main_with_args(command_name: &str, args: impl IntoIterator<Item = String>
|
||||||
pub fn chdir_workspace_root() -> Result<()> {
|
pub fn chdir_workspace_root() -> Result<()> {
|
||||||
let xtask_project_dir = std::env::var("CARGO_MANIFEST_DIR")
|
let xtask_project_dir = std::env::var("CARGO_MANIFEST_DIR")
|
||||||
.context("'$CARGO_MANIFEST_DIR' was not set, are you running this binary directly?")?;
|
.context("'$CARGO_MANIFEST_DIR' was not set, are you running this binary directly?")?;
|
||||||
let mut current_dir = Path::new(&xtask_project_dir);
|
let project_root = Path::new(&xtask_project_dir).parent().context(
|
||||||
loop {
|
"'$CARGO_MANIFEST_DIR' has an unexpected value, are you running this binary directly?",
|
||||||
let maybe_project_root = current_dir.parent().context(
|
)?;
|
||||||
"'$CARGO_MANIFEST_DIR' has an unexpected value, are you running this binary directly?",
|
|
||||||
)?;
|
// If `project_root` is not actually the project's root because this xtask binary's `Cargo.toml`
|
||||||
if maybe_project_root.join("Cargo.toml").exists() {
|
// file is in a sub-subdirectory, then we'll walk up the directory stack until we hopefully find
|
||||||
std::env::set_current_dir(maybe_project_root)
|
// it.
|
||||||
.context("Could not change to project root directory")?;
|
let project_root = if project_root.join("Cargo.toml").exists() {
|
||||||
return Ok(());
|
project_root
|
||||||
|
} else {
|
||||||
|
let mut project_root_candidate = project_root;
|
||||||
|
loop {
|
||||||
|
project_root_candidate = project_root_candidate
|
||||||
|
.parent()
|
||||||
|
.context("Reached the file system root without finding a parent Cargo.toml file")?;
|
||||||
|
if project_root_candidate.join("Cargo.toml").exists() {
|
||||||
|
break project_root_candidate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
current_dir = maybe_project_root;
|
};
|
||||||
}
|
|
||||||
|
std::env::set_current_dir(project_root).context("Could not change to project root directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build one or more packages using the provided `cargo build` arguments. This should be caleld
|
/// Build one or more packages using the provided `cargo build` arguments. This should be caleld
|
||||||
|
|
Loading…
Reference in a new issue