Skip to content
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

Ignore broken console output in some situations. #8236

Merged
merged 3 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cargo::core::features;
use cargo::{self, CliResult, Config};
use cargo::{self, drop_print, drop_println, CliResult, Config};
use clap::{AppSettings, Arg, ArgMatches};

use super::commands;
Expand All @@ -25,7 +25,8 @@ pub fn main(config: &mut Config) -> CliResult {
};

if args.value_of("unstable-features") == Some("help") {
println!(
drop_println!(
config,
"
Available unstable (nightly-only) flags:

Expand All @@ -40,15 +41,17 @@ Available unstable (nightly-only) flags:
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
);
if !features::nightly_features_allowed() {
println!(
drop_println!(
config,
"\nUnstable flags are only available on the nightly channel \
of Cargo, but this is the `{}` channel.\n\
{}",
features::channel(),
features::SEE_CHANNELS
);
}
println!(
drop_println!(
config,
"\nSee https://doc.rust-lang.org/nightly/cargo/reference/unstable.html \
for more information about these flags."
);
Expand All @@ -58,7 +61,7 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
let is_verbose = args.occurrences_of("verbose") > 0;
if args.is_present("version") {
let version = get_version_string(is_verbose);
print!("{}", version);
drop_print!(config, "{}", version);
return Ok(());
}

Expand All @@ -69,19 +72,19 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
}

if args.is_present("list") {
println!("Installed Commands:");
drop_println!(config, "Installed Commands:");
for command in list_commands(config) {
match command {
CommandInfo::BuiltIn { name, about } => {
let summary = about.unwrap_or_default();
let summary = summary.lines().next().unwrap_or(&summary); // display only the first line
println!(" {:<20} {}", name, summary)
drop_println!(config, " {:<20} {}", name, summary);
}
CommandInfo::External { name, path } => {
if is_verbose {
println!(" {:<20} {}", name, path.display())
drop_println!(config, " {:<20} {}", name, path.display());
} else {
println!(" {}", name)
drop_println!(config, " {}", name);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/bin/cargo/commands/locate_project.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::command_prelude::*;

use cargo::print_json;
use serde::Serialize;

pub fn cli() -> App {
Expand Down Expand Up @@ -30,6 +28,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {

let location = ProjectLocation { root };

print_json(&location);
config.shell().print_json(&location);
Ok(())
}
4 changes: 1 addition & 3 deletions src/bin/cargo/commands/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::command_prelude::*;

use cargo::ops::{self, OutputMetadataOptions};
use cargo::print_json;

pub fn cli() -> App {
subcommand("metadata")
Expand Down Expand Up @@ -54,6 +52,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
};

let result = ops::output_metadata(&ws, &options)?;
print_json(&result);
config.shell().print_json(&result);
Ok(())
}
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/pkgid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let ws = args.workspace(config)?;
let spec = args.value_of("spec").or_else(|| args.value_of("package"));
let spec = ops::pkgid(&ws, spec)?;
println!("{}", spec);
cargo::drop_println!(config, "{}", spec);
Ok(())
}
4 changes: 1 addition & 3 deletions src/bin/cargo/commands/read_manifest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::command_prelude::*;

use cargo::print_json;

pub fn cli() -> App {
subcommand("read-manifest")
.about(
Expand All @@ -17,6 +15,6 @@ Deprecated, use `cargo metadata --no-deps` instead.\

pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let ws = args.workspace(config)?;
print_json(&ws.current()?);
config.shell().print_json(&ws.current()?);
Ok(())
}
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
if args.is_present("version") {
let verbose = args.occurrences_of("verbose") > 0;
let version = cli::get_version_string(verbose);
print!("{}", version);
cargo::drop_print!(config, "{}", version);
return Ok(());
}
let prefix = if args.is_present("no-indent") {
Expand Down
14 changes: 4 additions & 10 deletions src/bin/cargo/commands/verify_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::command_prelude::*;
use std::collections::HashMap;
use std::process;

use cargo::print_json;

pub fn cli() -> App {
subcommand("verify-project")
.about("Check correctness of crate manifest")
Expand All @@ -13,19 +11,15 @@ pub fn cli() -> App {
}

pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
fn fail(reason: &str, value: &str) -> ! {
if let Err(e) = args.workspace(config) {
let mut h = HashMap::new();
h.insert(reason.to_string(), value.to_string());
print_json(&h);
h.insert("invalid".to_string(), e.to_string());
config.shell().print_json(&h);
process::exit(1)
}

if let Err(e) = args.workspace(config) {
fail("invalid", &e.to_string())
}

let mut h = HashMap::new();
h.insert("success".to_string(), "true".to_string());
print_json(&h);
config.shell().print_json(&h);
Ok(())
}
7 changes: 3 additions & 4 deletions src/bin/cargo/commands/version.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use crate::command_prelude::*;

use crate::cli;
use crate::command_prelude::*;

pub fn cli() -> App {
subcommand("version")
.about("Show version information")
.arg(opt("quiet", "No output printed to stdout").short("q"))
}

pub fn exec(_config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let verbose = args.occurrences_of("verbose") > 0;
let version = cli::get_version_string(verbose);
print!("{}", version);
cargo::drop_print!(config, "{}", version);
Ok(())
}
6 changes: 3 additions & 3 deletions src/cargo/core/compiler/build_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde::Serialize;
use super::context::OutputFile;
use super::{CompileKind, CompileMode, Context, Unit};
use crate::core::TargetKind;
use crate::util::{internal, CargoResult, ProcessBuilder};
use crate::util::{internal, CargoResult, Config, ProcessBuilder};

#[derive(Debug, Serialize)]
struct Invocation {
Expand Down Expand Up @@ -146,9 +146,9 @@ impl BuildPlan {
self.plan.inputs = inputs;
}

pub fn output_plan(self) {
pub fn output_plan(self, config: &Config) {
let encoded = serde_json::to_string(&self.plan).unwrap();
println!("{}", encoded);
crate::drop_println!(config, "{}", encoded);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {

if build_plan {
plan.set_inputs(self.build_plan_inputs()?);
plan.output_plan();
plan.output_plan(self.bcx.config);
}

// Collect the result of the build into `self.compilation`.
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ impl<'cfg> DrainState<'cfg> {
plan.update(&module_name, &cmd, &filenames)?;
}
Message::Stdout(out) => {
cx.bcx.config.shell().stdout_println(out);
writeln!(cx.bcx.config.shell().out(), "{}", out)?;
}
Message::Stderr(err) => {
let mut shell = cx.bcx.config.shell();
Expand Down Expand Up @@ -700,7 +700,7 @@ impl<'cfg> DrainState<'cfg> {
success: error.is_none(),
}
.to_json_string();
cx.bcx.config.shell().stdout_println(msg);
writeln!(cx.bcx.config.shell().out(), "{}", msg)?;
}

if let Some(e) = error {
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn compile<'cfg>(
&unit.target,
cx.files().message_cache_path(unit),
cx.bcx.build_config.message_format,
cx.bcx.config.shell().supports_color(),
cx.bcx.config.shell().err_supports_color(),
)
} else {
Work::noop()
Expand Down Expand Up @@ -1109,7 +1109,7 @@ struct OutputOptions {
impl OutputOptions {
fn new(cx: &Context<'_, '_>, unit: &Unit) -> OutputOptions {
let look_for_metadata_directive = cx.rmeta_required(unit);
let color = cx.bcx.config.shell().supports_color();
let color = cx.bcx.config.shell().err_supports_color();
let path = cx.files().message_cache_path(unit);
// Remove old cache, ignore ENOENT, which is the common case.
drop(fs::remove_file(&path));
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/timings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl<'cfg> Timings<'cfg> {
rmeta_time: unit_time.rmeta_time,
}
.to_json_string();
self.config.shell().stdout_println(msg);
crate::drop_println!(self.config, "{}", msg);
}
self.unit_times.push(unit_time);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/unit_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ pub fn emit_serialized_unit_graph(root_units: &[Unit], unit_graph: &UnitGraph) -
let stdout = std::io::stdout();
let mut lock = stdout.lock();
serde_json::to_writer(&mut lock, &s)?;
writeln!(lock)?;
drop(writeln!(lock));
Ok(())
}
2 changes: 1 addition & 1 deletion src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ impl Manifest {
pub fn print_teapot(&self, config: &Config) {
if let Some(teapot) = self.im_a_teapot {
if config.cli_unstable().print_im_a_teapot {
println!("im-a-teapot = {}", teapot);
crate::drop_println!(config, "im-a-teapot = {}", teapot);
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/cargo/core/resolver/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,13 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
for ((pkg_id, dep_kind), features) in &self.activated_features {
let r_features = self.resolve.features(*pkg_id);
if !r_features.iter().eq(features.iter()) {
eprintln!(
crate::drop_eprintln!(
self.ws.config(),
"{}/{:?} features mismatch\nresolve: {:?}\nnew: {:?}\n",
pkg_id, dep_kind, r_features, features
pkg_id,
dep_kind,
r_features,
features
);
found = true;
}
Expand Down
Loading