-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Implement future incompatibility report support #8825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 4 commits into
rust-lang:master
from
Aaron1011:feature/report-future-incompat
Mar 5, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.