Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 5b79fcf

Browse files
committed
Inject error-format at late stage
This sets the JSON flags at inside the Cargo hook rather than RUSTFLAGS to avoid trashing fingerprints.
1 parent ec5eb94 commit 5b79fcf

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/build/cargo.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use vfs::Vfs;
2626
use std::collections::{BTreeMap, HashMap, HashSet};
2727
use std::env;
2828
use std::ffi::OsString;
29+
use std::fmt::Write;
2930
use std::fs::{read_dir, remove_file};
3031
use std::path::{Path, PathBuf};
3132
use std::process::Command;
@@ -347,7 +348,9 @@ impl Executor for RlsExecutor {
347348
self.is_primary_crate(id)
348349
}
349350

350-
fn exec(&self, cargo_cmd: ProcessBuilder, id: &PackageId, target: &Target) -> CargoResult<()> {
351+
fn exec(&self, mut cargo_cmd: ProcessBuilder, id: &PackageId, target: &Target) -> CargoResult<()> {
352+
// Use JSON output so that we can parse the rustc output.
353+
cargo_cmd.arg("--error-format=json");
351354
// Delete any stale data. We try and remove any json files with
352355
// the same crate name as Cargo would emit. This includes files
353356
// with the same crate name but different hashes, e.g., those
@@ -617,18 +620,15 @@ impl CargoOptions {
617620
}
618621

619622
fn prepare_cargo_rustflags(config: &Config) -> String {
620-
let mut flags = "--error-format=json ".to_owned();
623+
let mut flags = env::var("RUSTFLAGS").unwrap_or_else(|_| String::new());
621624

622-
if let Some(ref sysroot) = config.sysroot {
623-
flags.push_str(&format!(" --sysroot {}", sysroot));
625+
if let Some(config_flags) = &config.rustflags {
626+
write!(flags, " {}", config_flags.as_str()).unwrap();
624627
}
625628

626-
flags = format!(
627-
"{} {} {}",
628-
env::var("RUSTFLAGS").unwrap_or_else(|_| String::new()),
629-
config.rustflags.as_ref().map(|s| s.as_str()).unwrap_or(""),
630-
flags
631-
);
629+
if let Some(sysroot) = &config.sysroot {
630+
write!(flags, " --sysroot {}", sysroot).unwrap();
631+
}
632632

633633
dedup_flags(&flags)
634634
}
@@ -709,7 +709,6 @@ fn current_sysroot() -> Option<String> {
709709
}
710710
}
711711

712-
713712
/// `flag_str` is a string of command line args for Rust. This function removes any
714713
/// duplicate flags.
715714
fn dedup_flags(flag_str: &str) -> String {

0 commit comments

Comments
 (0)