Skip to content

Commit

Permalink
Merge #204
Browse files Browse the repository at this point in the history
204: cargo: Pass the toolchain to all instances of MetadataCommand r=xFrednet a=NathanFrasier

Closes #188

Tested using rust-toolchain 1.65.0

Co-authored-by: Nathan Frasier <nathanfrasier.nf@gmail.com>
  • Loading branch information
bors[bot] and NathanFrasier authored Jul 28, 2023
2 parents dd8ba60 + f8fda81 commit e8d0c70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 2 additions & 5 deletions cargo-marker/src/backend/lints/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::{
path::{Path, PathBuf},
};

use cargo_metadata::{Metadata, MetadataCommand};
use cargo_metadata::Metadata;

use crate::{backend::Config, config::LintDependencyEntry, ExitStatus};

Expand Down Expand Up @@ -141,10 +141,7 @@ fn call_cargo_fetch(manifest: &Path, config: &Config) -> Result<(), ExitStatus>
}

fn call_cargo_metadata(manifest: &PathBuf, config: &Config) -> Result<Metadata, ExitStatus> {
let res = MetadataCommand::new()
.cargo_path(&config.toolchain.cargo_path)
.manifest_path(manifest)
.exec();
let res = config.toolchain.cargo_metadata_command().manifest_path(manifest).exec();

// FIXME(xFrednet): Handle errors properly.
res.map_err(|_| ExitStatus::LintCrateFetchFailed)
Expand Down
13 changes: 11 additions & 2 deletions cargo-marker/src/backend/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,19 @@ impl Toolchain {
cmd
}

pub fn cargo_metadata_command(&self) -> MetadataCommand {
let mut command = MetadataCommand::new();
command.cargo_path(&self.cargo_path);
if let Some(toolchain) = self.toolchain.as_ref() {
command.env("RUSTUP_TOOLCHAIN", toolchain);
}
command
}

pub fn find_target_dir(&self) -> Result<PathBuf, ExitStatus> {
// FIXME(xFrednet): Handle errors properly.
let metadata = MetadataCommand::new()
.cargo_path(&self.cargo_path)
let metadata = self
.cargo_metadata_command()
.exec()
.map_err(|_| ExitStatus::NoTargetDir)?;

Expand Down

0 comments on commit e8d0c70

Please sign in to comment.