]> git.lizzy.rs Git - rust.git/commitdiff
Use package root as `cargo check` working directory
authorBrendan Cully <brendan@cully.org>
Thu, 13 May 2021 02:50:52 +0000 (19:50 -0700)
committerBrendan Cully <brendan@cully.org>
Thu, 13 May 2021 02:50:52 +0000 (19:50 -0700)
Cargo commands are affected by the `.cargo/config` files above
their working directory. If cargo is invoked from above the directory
holding `Cargo.toml`, it may not pick up important settings like
registry replacements, causing it to behave differently or even fail.

Most cargo invocations are currently setting their working directories
to the directory containing `Cargo.toml`, but a couple of paths remain
in which cargo is invoked from the default workspace root instead.

This change fixes that, resolving some cargo check failures that I
experienced in a multi-root workspace in which packages used different
registries.

crates/flycheck/src/lib.rs
crates/project_model/src/build_data.rs

index 1682d8bde23548f38073682be12b6cd00dfdea5b..93cf6a3d68bf1764a580104f5c4e6bd851935a87 100644 (file)
@@ -215,6 +215,7 @@ fn check_command(&self) -> Command {
             } => {
                 let mut cmd = Command::new(toolchain::cargo());
                 cmd.arg(command);
+                cmd.current_dir(&self.workspace_root);
                 cmd.args(&["--workspace", "--message-format=json", "--manifest-path"])
                     .arg(self.workspace_root.join("Cargo.toml"));
 
index 7b88dca6306ac8fef882c970ea586f4c44687047..3aa546980cd4644f17586bbbc6d860dfe9a62a47 100644 (file)
@@ -143,6 +143,7 @@ fn collect(
             cmd.env("RA_RUSTC_WRAPPER", "1");
         }
 
+        cmd.current_dir(cargo_toml.parent().unwrap());
         cmd.args(&["check", "--quiet", "--workspace", "--message-format=json", "--manifest-path"])
             .arg(cargo_toml.as_ref());