Skip to content

Commit 8965488

Browse files
committed
panic in CI or with CROSS_NO_WARNINGS=1 if there are warnings
1 parent db4761b commit 8965488

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ walkdir = { version = "2.3.2", optional = true }
4848
tempfile = "3.3.0"
4949
owo-colors = { version = "3.5.0", features = ["supports-colors"] }
5050
semver = "1.0.16"
51+
is_ci = "1.1.1"
5152

5253
[target.'cfg(not(windows))'.dependencies]
5354
nix = { version = "0.26.2", default-features = false, features = ["user"] }

src/bin/cross.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
};
77

88
use cross::{
9-
cargo, cli, rustc,
9+
cargo, cli, config, rustc,
1010
shell::{self, Verbosity},
1111
OutputExt, Subcommand,
1212
};
@@ -21,7 +21,11 @@ pub fn main() -> cross::Result<()> {
2121
let mut msg_info = shell::MessageInfo::create(args.verbose, args.quiet, args.color.as_deref())?;
2222
let status = match cross::run(args, target_list, &mut msg_info)? {
2323
Some(status) => status,
24-
None => {
24+
None if env::var("CROSS_NO_WARNINGS")
25+
.map(|env| config::bool_from_envvar(&env))
26+
.unwrap_or_else(|_| is_ci::uncached())
27+
&& !msg_info.has_warned =>
28+
{
2529
// if we fallback to the host cargo, use the same invocation that was made to cross
2630
let argv: Vec<String> = env::args().skip(1).collect();
2731
msg_info.note("Falling back to `cargo` on the host.")?;
@@ -42,6 +46,11 @@ pub fn main() -> cross::Result<()> {
4246
_ => cargo::run(&argv, &mut msg_info)?,
4347
}
4448
}
49+
None => {
50+
msg_info.error("Errors encountered before cross compilation, aborting.")?;
51+
msg_info.note("Disable this with `CROSS_NO_WARNINGS=0`")?;
52+
std::process::exit(1);
53+
}
4554
};
4655
let code = status
4756
.code()

src/shell.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pub struct MessageInfo {
140140
pub stdout_needs_erase: bool,
141141
pub stderr_needs_erase: bool,
142142
pub cross_debug: bool,
143+
pub has_warned: bool,
143144
}
144145

145146
impl MessageInfo {
@@ -153,6 +154,7 @@ impl MessageInfo {
153154
.as_deref()
154155
.map(bool_from_envvar)
155156
.unwrap_or_default(),
157+
has_warned: false,
156158
}
157159
}
158160

@@ -231,13 +233,15 @@ impl MessageInfo {
231233
/// prints a red 'error' message.
232234
#[track_caller]
233235
pub fn error<T: fmt::Display>(&mut self, message: T) -> Result<()> {
236+
self.has_warned = true;
234237
self.stderr_check_erase()?;
235238
status!(@stderr cross_prefix!("error"), Some(&message), red, self)
236239
}
237240

238241
/// prints an amber 'warning' message.
239242
#[track_caller]
240243
pub fn warn<T: fmt::Display>(&mut self, message: T) -> Result<()> {
244+
self.has_warned = true;
241245
match self.verbosity {
242246
Verbosity::Quiet => Ok(()),
243247
_ => status!(@stderr

0 commit comments

Comments
 (0)