-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Pass the current shell width to rustc #7315
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ pub use self::layout::is_bad_artifact_name; | |
use self::output_depinfo::output_depinfo; | ||
use self::unit_dependencies::UnitDep; | ||
pub use crate::core::compiler::unit::{Unit, UnitInterner}; | ||
use crate::core::features::nightly_features_allowed; | ||
use crate::core::manifest::TargetSourcePath; | ||
use crate::core::profiles::{Lto, PanicStrategy, Profile}; | ||
use crate::core::Feature; | ||
|
@@ -714,6 +715,14 @@ fn add_error_format_and_color( | |
} else { | ||
let mut color = true; | ||
match cx.bcx.build_config.message_format { | ||
MessageFormat::Human if nightly_features_allowed() => { | ||
if let (Some(width), _) | (_, Some(width)) = ( | ||
cx.bcx.config.cli_unstable().terminal_width, | ||
cx.bcx.config.shell().accurate_err_width(), | ||
) { | ||
cmd.arg(format!("-Zterminal-width={}", width)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason this isn't included in the pipeline path? Does it not affect the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the |
||
} | ||
} | ||
MessageFormat::Human => (), | ||
MessageFormat::Json { | ||
ansi, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,14 @@ impl Shell { | |
} | ||
} | ||
|
||
/// Returns the width of the terminal in spaces, if any. Always `None` in Windows. | ||
pub fn accurate_err_width(&self) -> Option<usize> { | ||
match self.err { | ||
ShellOut::Stream { tty: true, .. } => imp::accurate_stderr_width(), | ||
_ => None, | ||
} | ||
} | ||
|
||
/// Returns `true` if stderr is a tty. | ||
pub fn is_err_tty(&self) -> bool { | ||
match self.err { | ||
|
@@ -383,6 +391,10 @@ mod imp { | |
|
||
use super::Shell; | ||
|
||
pub fn accurate_stderr_width() -> Option<usize> { | ||
stderr_width() | ||
} | ||
|
||
pub fn stderr_width() -> Option<usize> { | ||
unsafe { | ||
let mut winsize: libc::winsize = mem::zeroed(); | ||
|
@@ -414,6 +426,10 @@ mod imp { | |
mod imp { | ||
pub(super) use super::default_err_erase_line as err_erase_line; | ||
|
||
pub fn accurate_stderr_width() -> Option<usize> { | ||
None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems a bit unfortunate to unconditionally disable on Windows. Perhaps |
||
} | ||
|
||
pub fn stderr_width() -> Option<usize> { | ||
None | ||
} | ||
|
@@ -431,6 +447,10 @@ mod imp { | |
|
||
pub(super) use super::default_err_erase_line as err_erase_line; | ||
|
||
pub fn accurate_stderr_width() -> Option<usize> { | ||
None | ||
} | ||
|
||
pub fn stderr_width() -> Option<usize> { | ||
unsafe { | ||
let stdout = GetStdHandle(STD_ERROR_HANDLE); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this changed it to unconditionally enable it on nightly. We haven't really done that before, but I don't really have an objection to it. We have problems with figuring out how to get people to test unstable flags, so unconditionally enabling it on nightly might be a good idea, since it is just a visual change. I'd like to hear from other cargo members, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late repsponse, but I think I'd prefer if this still needed to be opted-in to if that's ok, because otherwise if
-Zterminal-width
changes it'd break all nightly users by default until we can ship a fixThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough.