Skip to content

Commit

Permalink
Merge branch 'master' into patch-in-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Gjengset committed Mar 8, 2021
2 parents 6995e1d + e78f1c8 commit 6bc97fc
Show file tree
Hide file tree
Showing 33 changed files with 589 additions and 44 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ im-rc = "15.0.0"
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`
# for more information.
rustc-workspace-hack = "1.0.0"
rand = "0.8.3"

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = { version = "0.9.0", features = ["mac_os_10_7_support"] }
Expand Down
2 changes: 2 additions & 0 deletions crates/cargo-test-support/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ use std::path::{Path, PathBuf};
/// has been installed. Example usage:
///
/// assert_has_installed_exe(cargo_home(), "foo");
#[track_caller]
pub fn assert_has_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) {
assert!(check_has_installed_exe(path, name));
}

#[track_caller]
pub fn assert_has_not_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) {
assert!(!check_has_installed_exe(path, name));
}
Expand Down
2 changes: 2 additions & 0 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ impl Execs {
self
}

#[track_caller]
pub fn run(&mut self) {
self.ran = true;
let p = (&self.process_builder).clone().unwrap();
Expand All @@ -740,6 +741,7 @@ impl Execs {
}
}

#[track_caller]
pub fn run_output(&mut self, output: &Output) {
self.ran = true;
if let Err(e) = self.match_output(output) {
Expand Down
2 changes: 2 additions & 0 deletions crates/resolver-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,12 +969,14 @@ fn meta_test_multiple_versions_strategy() {
}

/// Assert `xs` contains `elems`
#[track_caller]
pub fn assert_contains<A: PartialEq>(xs: &[A], elems: &[A]) {
for elem in elems {
assert!(xs.contains(elem));
}
}

#[track_caller]
pub fn assert_same<A: PartialEq>(a: &[A], b: &[A]) {
assert_eq!(a.len(), b.len());
assert_contains(b, a);
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn cli() -> App {
.arg_message_format()
.arg_build_plan()
.arg_unit_graph()
.arg_future_incompat_report()
.after_help("Run `cargo help build` for more detailed information.\n")
}

Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub fn cli() -> App {
.arg_ignore_rust_version()
.arg_message_format()
.arg_unit_graph()
.arg_future_incompat_report()
.after_help("Run `cargo help check` for more detailed information.\n")
}

Expand Down
57 changes: 57 additions & 0 deletions src/bin/cargo/commands/describe_future_incompatibilities.rs
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(())
}
3 changes: 3 additions & 0 deletions src/bin/cargo/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub fn builtin() -> Vec<App> {
build::cli(),
check::cli(),
clean::cli(),
describe_future_incompatibilities::cli(),
doc::cli(),
fetch::cli(),
fix::cli(),
Expand Down Expand Up @@ -44,6 +45,7 @@ pub fn builtin_exec(cmd: &str) -> Option<fn(&mut Config, &ArgMatches<'_>) -> Cli
"build" => build::exec,
"check" => check::exec,
"clean" => clean::exec,
"describe-future-incompatibilities" => describe_future_incompatibilities::exec,
"doc" => doc::exec,
"fetch" => fetch::exec,
"fix" => fix::exec,
Expand Down Expand Up @@ -82,6 +84,7 @@ pub mod bench;
pub mod build;
pub mod check;
pub mod clean;
pub mod describe_future_incompatibilities;
pub mod doc;
pub mod fetch;
pub mod fix;
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub fn cli() -> App {
.arg_message_format()
.arg_unit_graph()
.arg_ignore_rust_version()
.arg_future_incompat_report()
.after_help("Run `cargo help rustc` for more detailed information.\n")
}

Expand Down
3 changes: 3 additions & 0 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct BuildConfig {
// Note that, although the cmd-line flag name is `out-dir`, in code we use
// `export_dir`, to avoid confusion with out dir at `target/debug/deps`.
pub export_dir: Option<PathBuf>,
/// `true` to output a future incompatibility report at the end of the build
pub future_incompat_report: bool,
}

impl BuildConfig {
Expand Down Expand Up @@ -80,6 +82,7 @@ impl BuildConfig {
primary_unit_rustc: None,
rustfix_diagnostic_server: RefCell::new(None),
export_dir: None,
future_incompat_report: false,
})
}

Expand Down
36 changes: 36 additions & 0 deletions src/cargo/core/compiler/future_incompat.rs
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,
}
Loading

0 comments on commit 6bc97fc

Please sign in to comment.