-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #8825 - Aaron1011:feature/report-future-incompat, r=ehuss
Implement future incompatibility report support cc rust-lang/rust#71249 This implements the Cargo side of 'Cargo report future-incompat' Based on feedback from alexcrichton and est31, I'm implemented this a flag `--future-compat-report` on `cargo check/build/rustc`, rather than a separate `cargo describe-future-incompatibilities` command. This allows us to avoid writing additional information to disk (beyond the pre-existing recording of rustc command outputs). This PR contains: * Gating of all functionality behind `-Z report-future-incompat`. Without this flag, all user output is unchanged. * Passing `-Z emit-future-incompat-report` to rustc when `-Z report-future-incompat` is enabled * Parsing the rustc JSON future incompat report, and displaying it it a user-readable format. * Emitting a warning at the end of a build if any crates had future-incompat reports * A `--future-incompat-report` flag, which shows the full report for each affected crate. * Tests for all of the above. At the moment, we can use the `array_into_iter` to write a test. However, we might eventually get to a point where rustc is not currently emitting future-incompat reports for any lints. What would we want the cargo tests to do in this situation? This functionality didn't require any significant internal changes to Cargo, with one exception: we now process captured command output for all units, not just ones where we want to display warnings. This may result in a slightly longer time to run `cargo build/check/rustc` from a full cache. since we do slightly more work for each upstream dependency. Doing this seems unavoidable with the current architecture, since we need to process captured command outputs to detect any future-incompat-report messages that were emitted.
- Loading branch information
Showing
15 changed files
with
444 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/bin/cargo/commands/describe_future_incompatibilities.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use crate::command_prelude::*; | ||
use anyhow::anyhow; | ||
use cargo::core::compiler::future_incompat::{OnDiskReport, FUTURE_INCOMPAT_FILE}; | ||
use cargo::drop_eprint; | ||
use cargo::util::CargoResultExt; | ||
use std::io::Read; | ||
|
||
pub fn cli() -> App { | ||
subcommand("describe-future-incompatibilities") | ||
.arg( | ||
opt( | ||
"id", | ||
"identifier of the report [generated by a Cargo command invocation", | ||
) | ||
.value_name("id") | ||
.required(true), | ||
) | ||
.about("Reports any crates which will eventually stop compiling") | ||
} | ||
|
||
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { | ||
if !config.nightly_features_allowed { | ||
return Err(anyhow!( | ||
"`cargo describe-future-incompatibilities` can only be used on the nightly channel" | ||
) | ||
.into()); | ||
} | ||
|
||
let ws = args.workspace(config)?; | ||
let report_file = ws.target_dir().open_ro( | ||
FUTURE_INCOMPAT_FILE, | ||
ws.config(), | ||
"Future incompatible report", | ||
)?; | ||
|
||
let mut file_contents = String::new(); | ||
report_file | ||
.file() | ||
.read_to_string(&mut file_contents) | ||
.chain_err(|| "failed to read report")?; | ||
let on_disk_report: OnDiskReport = | ||
serde_json::from_str(&file_contents).chain_err(|| "failed to load report")?; | ||
|
||
let id = args.value_of("id").unwrap(); | ||
if id != on_disk_report.id { | ||
return Err(anyhow!( | ||
"Expected an id of `{}`, but `{}` was provided on the command line. \ | ||
Your report may have been overwritten by a different one.", | ||
on_disk_report.id, | ||
id | ||
) | ||
.into()); | ||
} | ||
|
||
drop_eprint!(config, "{}", on_disk_report.report); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// The future incompatibility report, emitted by the compiler as a JSON message. | ||
#[derive(serde::Deserialize)] | ||
pub struct FutureIncompatReport { | ||
pub future_incompat_report: Vec<FutureBreakageItem>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct FutureBreakageItem { | ||
/// The date at which this lint will become an error. | ||
/// Currently unused | ||
pub future_breakage_date: Option<String>, | ||
/// The original diagnostic emitted by the compiler | ||
pub diagnostic: Diagnostic, | ||
} | ||
|
||
/// A diagnostic emitted by the compiler as a JSON message. | ||
/// We only care about the 'rendered' field | ||
#[derive(Serialize, Deserialize)] | ||
pub struct Diagnostic { | ||
pub rendered: String, | ||
} | ||
|
||
/// The filename in the top-level `target` directory where we store | ||
/// the report | ||
pub const FUTURE_INCOMPAT_FILE: &str = ".future-incompat-report.json"; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct OnDiskReport { | ||
// A Cargo-generated id used to detect when a report has been overwritten | ||
pub id: String, | ||
// Cannot be a &str, since Serde needs | ||
// to be able to un-escape the JSON | ||
pub report: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.