Skip to content

Commit

Permalink
Auto merge of #10165 - Aaron1011:stabilize-future-incompat, r=ehuss
Browse files Browse the repository at this point in the history
Stabilize future-incompat-report

Depends on rust-lang/rust#91535
  • Loading branch information
bors committed Dec 6, 2021
2 parents cf474a5 + 673b15d commit 263b169
Show file tree
Hide file tree
Showing 35 changed files with 371 additions and 112 deletions.
4 changes: 0 additions & 4 deletions src/bin/cargo/commands/report.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::command_prelude::*;
use anyhow::anyhow;
use cargo::core::compiler::future_incompat::{OnDiskReports, REPORT_PREAMBLE};
use cargo::drop_println;

Expand All @@ -24,9 +23,6 @@ pub fn cli() -> App {
}

pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
if !config.nightly_features_allowed {
return Err(anyhow!("`cargo report` can only be used on the nightly channel").into());
}
match args.subcommand() {
("future-incompatibilities", Some(args)) => report_future_incompatibilies(config, args),
(cmd, _) => panic!("unexpected command `{}`", cmd),
Expand Down
12 changes: 12 additions & 0 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub struct TargetInfo {
pub rustdocflags: Vec<String>,
/// Whether or not rustc supports the `-Csplit-debuginfo` flag.
pub supports_split_debuginfo: bool,
/// Whether or not rustc supports the `--json future-incompat` flag.
pub supports_json_future_incompat: bool,
}

/// Kind of each file generated by a Unit, part of `FileType`.
Expand Down Expand Up @@ -179,6 +181,15 @@ impl TargetInfo {
)
.is_ok();

let supports_json_future_incompat = rustc
.cached_output(
process
.clone()
.args(&["--error-format", "json", "--json", "future-incompat"]),
extra_fingerprint,
)
.is_ok();

process.arg("--print=sysroot");
process.arg("--print=cfg");

Expand Down Expand Up @@ -253,6 +264,7 @@ impl TargetInfo {
)?,
cfg,
supports_split_debuginfo,
supports_json_future_incompat,
})
}

Expand Down
3 changes: 0 additions & 3 deletions src/cargo/core/compiler/future_incompat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,6 @@ pub fn save_and_display_report(
bcx: &BuildContext<'_, '_>,
per_package_future_incompat_reports: &[FutureIncompatReportPackage],
) {
if !bcx.config.cli_unstable().future_incompat_report {
return;
}
let should_display_message = match bcx.config.future_incompat_config() {
Ok(config) => config.should_display_message(),
Err(e) => {
Expand Down
25 changes: 18 additions & 7 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
}

add_error_format_and_color(cx, &mut rustdoc, false);
add_error_format_and_color(cx, &mut rustdoc, unit, false);
add_allow_features(cx, &mut rustdoc);

if let Some(args) = cx.bcx.extra_args_for(unit) {
Expand Down Expand Up @@ -790,14 +790,29 @@ fn add_allow_features(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder) {
/// intercepting messages like rmeta artifacts, etc. rustc includes a
/// "rendered" field in the JSON message with the message properly formatted,
/// which Cargo will extract and display to the user.
fn add_error_format_and_color(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder, pipelined: bool) {
fn add_error_format_and_color(
cx: &Context<'_, '_>,
cmd: &mut ProcessBuilder,
unit: &Unit,
pipelined: bool,
) {
cmd.arg("--error-format=json");
let mut json = String::from("--json=diagnostic-rendered-ansi");
if pipelined {
// Pipelining needs to know when rmeta files are finished. Tell rustc
// to emit a message that cargo will intercept.
json.push_str(",artifacts");
}
if cx
.bcx
.target_data
.info(unit.kind)
.supports_json_future_incompat
{
// Emit a future-incompat report (when supported by rustc), so we can report
// future-incompat dependencies to the user
json.push_str(",future-incompat");
}

match cx.bcx.build_config.message_format {
MessageFormat::Short | MessageFormat::Json { short: true, .. } => {
Expand Down Expand Up @@ -858,7 +873,7 @@ fn build_base_args(
edition.cmd_edition_arg(cmd);

add_path_args(bcx.ws, unit, cmd);
add_error_format_and_color(cx, cmd, cx.rmeta_required(unit));
add_error_format_and_color(cx, cmd, unit, cx.rmeta_required(unit));
add_allow_features(cx, cmd);

let mut contains_dy_lib = false;
Expand Down Expand Up @@ -1022,10 +1037,6 @@ fn build_base_args(
.env("RUSTC_BOOTSTRAP", "1");
}

if bcx.config.cli_unstable().future_incompat_report {
cmd.arg("-Z").arg("emit-future-incompat-report");
}

// Add `CARGO_BIN_` environment variables for building tests.
if unit.target.is_test() || unit.target.is_bench() {
for bin_target in unit
Expand Down
8 changes: 6 additions & 2 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@ unstable_cli_options!(
doctest_in_workspace: bool = ("Compile doctests with paths relative to the workspace root"),
doctest_xcompile: bool = ("Compile and run doctests for non-host target using runner config"),
dual_proc_macros: bool = ("Build proc-macros for both the host and the target"),
future_incompat_report: bool = ("Enable creation of a future-incompat report for all dependencies"),
features: Option<Vec<String>> = (HIDDEN),
jobserver_per_rustc: bool = (HIDDEN),
minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum"),
Expand Down Expand Up @@ -705,6 +704,9 @@ const STABILIZED_NAMED_PROFILES: &str = "The named-profiles feature is now alway
See https://doc.rust-lang.org/nightly/cargo/reference/profiles.html#custom-profiles \
for more information";

const STABILIZED_FUTURE_INCOMPAT_REPORT: &str =
"The future-incompat-report feature is now always enabled.";

fn deserialize_build_std<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
where
D: serde::Deserializer<'de>,
Expand Down Expand Up @@ -894,7 +896,9 @@ impl CliUnstable {
"extra-link-arg" => stabilized_warn(k, "1.56", STABILIZED_EXTRA_LINK_ARG),
"configurable-env" => stabilized_warn(k, "1.56", STABILIZED_CONFIGURABLE_ENV),
"patch-in-config" => stabilized_warn(k, "1.56", STABILIZED_PATCH_IN_CONFIG),
"future-incompat-report" => self.future_incompat_report = parse_empty(k, v)?,
"future-incompat-report" => {
stabilized_warn(k, "1.59.0", STABILIZED_FUTURE_INCOMPAT_REPORT)
}
_ => bail!("unknown `-Z` flag specified: {}", k),
}

Expand Down
13 changes: 1 addition & 12 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub trait AppExt: Sized {
fn arg_future_incompat_report(self) -> Self {
self._arg(opt(
"future-incompat-report",
"Outputs a future incompatibility report at the end of the build (unstable)",
"Outputs a future incompatibility report at the end of the build",
))
}
}
Expand Down Expand Up @@ -512,17 +512,6 @@ pub trait ArgMatchesExt {
.cli_unstable()
.fail_if_stable_opt("--unit-graph", 8002)?;
}
if build_config.future_incompat_report {
config
.cli_unstable()
.fail_if_stable_opt("--future-incompat-report", 9241)?;

if !config.cli_unstable().future_incompat_report {
anyhow::bail!(
"Usage of `--future-incompat-report` requires `-Z future-incompat-report`"
)
}
}

let opts = CompileOptions {
build_config,
Expand Down
1 change: 1 addition & 0 deletions src/doc/man/cargo-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ See <https://github.com/rust-lang/cargo/issues/5579> for more information.

{{#options}}
{{> options-jobs }}
{{> options-future-incompat }}
{{/options}}

{{> section-environment }}
Expand Down
1 change: 1 addition & 0 deletions src/doc/man/cargo-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ they have `required-features` that are missing.

{{#options}}
{{> options-jobs }}
{{> options-future-incompat }}
{{/options}}

{{> section-environment }}
Expand Down
42 changes: 42 additions & 0 deletions src/doc/man/cargo-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# cargo-report(1)

## NAME

cargo-report - Generate and display various kinds of reports

## SYNOPSIS

`cargo report` _type_ [_options_]

### DESCRIPTION

Displays a report of the given _type_ - currently, only `future-incompat` is supported

## OPTIONS

{{#options}}

{{#option "`--id` _id_" }}
Show the report with the specified Cargo-generated id
{{/option}}

{{#option "`-p` _spec_..." "`--package` _spec_..." }}
Only display a report for the specified package
{{/option}}

{{/options}}

## EXAMPLES

1. Display the latest future-incompat report:

cargo report future-incompat

2. Display the latest future-incompat report for a specific package:

cargo report future-incompat --package my-dep:0.0.1

## SEE ALSO
[Future incompat report](../reference/future-incompat-report.html)

{{man "cargo" 1}}
1 change: 1 addition & 0 deletions src/doc/man/cargo-rustc.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ See the [the reference](../reference/profiles.html) for more details on profiles

{{#options}}
{{> options-jobs }}
{{> options-future-incompat }}
{{/options}}

{{> section-environment }}
Expand Down
1 change: 1 addition & 0 deletions src/doc/man/cargo-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ includes an option to control the number of threads used:
{{#options}}

{{> options-jobs }}
{{> options-future-incompat }}

{{/options}}

Expand Down
6 changes: 6 additions & 0 deletions src/doc/man/generated_txt/cargo-build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ OPTIONS
<https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
the number of CPUs.

--future-incompat-report
Displays a future-incompat report for any future-incompatible
warnings produced during execution of this command

See cargo-report(1)

ENVIRONMENT
See the reference
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>
Expand Down
6 changes: 6 additions & 0 deletions src/doc/man/generated_txt/cargo-check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ OPTIONS
<https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
the number of CPUs.

--future-incompat-report
Displays a future-incompat report for any future-incompatible
warnings produced during execution of this command

See cargo-report(1)

ENVIRONMENT
See the reference
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>
Expand Down
34 changes: 34 additions & 0 deletions src/doc/man/generated_txt/cargo-report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CARGO-REPORT(1)

NAME
cargo-report - Generate and display various kinds of reports

SYNOPSIS
cargo report type [options]

DESCRIPTION
Displays a report of the given type - currently, only future-incompat is
supported

OPTIONS
--id id
Show the report with the specified Cargo-generated id

-p spec..., --package spec...
Only display a report for the specified package

EXAMPLES
1. Display the latest future-incompat report:

cargo report future-incompat

2. Display the latest future-incompat report for a specific package:

cargo report future-incompat --package my-dep:0.0.1

SEE ALSO
Future incompat report
<https://doc.rust-lang.org/cargo/reference/future-incompat-report.html>

cargo(1)

6 changes: 6 additions & 0 deletions src/doc/man/generated_txt/cargo-rustc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ OPTIONS
<https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
the number of CPUs.

--future-incompat-report
Displays a future-incompat report for any future-incompatible
warnings produced during execution of this command

See cargo-report(1)

ENVIRONMENT
See the reference
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>
Expand Down
6 changes: 6 additions & 0 deletions src/doc/man/generated_txt/cargo-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ OPTIONS
<https://doc.rust-lang.org/cargo/reference/config.html>. Defaults to
the number of CPUs.

--future-incompat-report
Displays a future-incompat report for any future-incompatible
warnings produced during execution of this command

See cargo-report(1)

ENVIRONMENT
See the reference
<https://doc.rust-lang.org/cargo/reference/environment-variables.html>
Expand Down
6 changes: 6 additions & 0 deletions src/doc/man/includes/options-future-incompat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{#option "`--future-incompat-report`"}}
Displays a future-incompat report for any future-incompatible warnings
produced during execution of this command

See {{man "cargo-report" 1}}
{{/option}}
2 changes: 2 additions & 0 deletions src/doc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* [Registries](reference/registries.md)
* [Dependency Resolution](reference/resolver.md)
* [SemVer Compatibility](reference/semver.md)
* [Future incompat report](reference/future-incompat-report.md)
* [Unstable Features](reference/unstable.md)

* [Cargo Commands](commands/index.md)
Expand All @@ -57,6 +58,7 @@
* [cargo rustc](commands/cargo-rustc.md)
* [cargo rustdoc](commands/cargo-rustdoc.md)
* [cargo test](commands/cargo-test.md)
* [cargo report](commands/cargo-report.md)
* [Manifest Commands](commands/manifest-commands.md)
* [cargo generate-lockfile](commands/cargo-generate-lockfile.md)
* [cargo locate-project](commands/cargo-locate-project.md)
Expand Down
1 change: 1 addition & 0 deletions src/doc/src/commands/build-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
* [cargo rustc](cargo-rustc.md)
* [cargo rustdoc](cargo-rustdoc.md)
* [cargo test](cargo-test.md)
* [cargo report](cargo-report.md)
6 changes: 6 additions & 0 deletions src/doc/src/commands/cargo-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ for more information about how toolchain overrides work.</dd>
the number of CPUs.</dd>


<dt class="option-term" id="option-cargo-build---future-incompat-report"><a class="option-anchor" href="#option-cargo-build---future-incompat-report"></a><code>--future-incompat-report</code></dt>
<dd class="option-desc">Displays a future-incompat report for any future-incompatible warnings
produced during execution of this command</p>
<p>See <a href="cargo-report.html">cargo-report(1)</a></dd>


</dl>

## ENVIRONMENT
Expand Down
6 changes: 6 additions & 0 deletions src/doc/src/commands/cargo-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ for more information about how toolchain overrides work.</dd>
the number of CPUs.</dd>


<dt class="option-term" id="option-cargo-check---future-incompat-report"><a class="option-anchor" href="#option-cargo-check---future-incompat-report"></a><code>--future-incompat-report</code></dt>
<dd class="option-desc">Displays a future-incompat report for any future-incompatible warnings
produced during execution of this command</p>
<p>See <a href="cargo-report.html">cargo-report(1)</a></dd>


</dl>

## ENVIRONMENT
Expand Down
Loading

0 comments on commit 263b169

Please sign in to comment.