Skip to content

Commit 1cb64f7

Browse files
committed
don't fallback or allow warnings/errors in CI or with env var
1 parent 8965488 commit 1cb64f7

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

src/bin/cross.rs

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

88
use cross::{
9-
cargo, cli, config, rustc,
9+
cargo, cli, rustc,
1010
shell::{self, Verbosity},
1111
OutputExt, Subcommand,
1212
};
@@ -21,11 +21,7 @@ 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 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-
{
24+
None if !msg_info.should_fail() => {
2925
// if we fallback to the host cargo, use the same invocation that was made to cross
3026
let argv: Vec<String> = env::args().skip(1).collect();
3127
msg_info.note("Falling back to `cargo` on the host.")?;

src/docker/local.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(crate) fn run(
3131
paths: DockerPaths,
3232
args: &[String],
3333
msg_info: &mut MessageInfo,
34-
) -> Result<ExitStatus> {
34+
) -> Result<Option<ExitStatus>> {
3535
let engine = &options.engine;
3636
let toolchain_dirs = paths.directories.toolchain_directories();
3737
let package_dirs = paths.directories.package_directories();
@@ -147,6 +147,9 @@ pub(crate) fn run(
147147
}
148148

149149
ChildContainer::create(engine.clone(), container_id)?;
150+
if msg_info.should_fail() {
151+
return Ok(None);
152+
}
150153
let status = docker
151154
.arg(&image_name)
152155
.add_build_command(toolchain_dirs, &cmd)
@@ -162,5 +165,5 @@ pub(crate) fn run(
162165
ChildContainer::exit_static();
163166
}
164167

165-
status
168+
status.map(Some)
166169
}

src/docker/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ pub fn image_name(target: &str, sub: Option<&str>, repository: &str, tag: &str)
4141
}
4242
}
4343

44+
// TODO: The Option here in the result should be removed and Result::Error replaced with a enum to properly signal error
45+
46+
// Ok(None) means that the command failed, due to a warning or error, when `msg_info.should_fail() == true`
4447
pub fn run(
4548
options: DockerOptions,
4649
paths: DockerPaths,
4750
args: &[String],
4851
subcommand: Option<crate::Subcommand>,
4952
msg_info: &mut MessageInfo,
50-
) -> Result<ExitStatus> {
53+
) -> Result<Option<ExitStatus>> {
5154
if cfg!(target_os = "windows") && options.in_docker() {
5255
msg_info.fatal(
5356
"running cross insider a container running windows is currently unsupported",

src/docker/remote.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ pub(crate) fn run(
670670
args: &[String],
671671
subcommand: Option<crate::Subcommand>,
672672
msg_info: &mut MessageInfo,
673-
) -> Result<ExitStatus> {
673+
) -> Result<Option<ExitStatus>> {
674674
let engine = &options.engine;
675675
let target = &options.target;
676676
let toolchain_dirs = paths.directories.toolchain_directories();
@@ -897,6 +897,10 @@ pub(crate) fn run(
897897

898898
let mut cmd = options.command_variant.safe_command();
899899

900+
if msg_info.should_fail() {
901+
return Ok(None);
902+
}
903+
900904
if !options.command_variant.is_shell() {
901905
// `clean` doesn't handle symlinks: it will just unlink the target
902906
// directory, so we should just substitute it our target directory
@@ -1010,5 +1014,5 @@ symlink_recurse \"${{prefix}}\"
10101014

10111015
ChildContainer::finish_static(is_tty, msg_info);
10121016

1013-
status
1017+
status.map(Some)
10141018
}

src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,21 +624,31 @@ pub fn run(
624624
false,
625625
);
626626

627+
if msg_info.should_fail() {
628+
return Ok(None);
629+
}
630+
627631
install_interpreter_if_needed(
628632
&args,
629633
host_version_meta,
630634
&target,
631635
&options,
632636
msg_info,
633637
)?;
634-
let status = docker::run(
638+
let status = if let Some(status) = docker::run(
635639
options,
636640
paths,
637641
&filtered_args,
638642
args.subcommand.clone(),
639643
msg_info,
640644
)
641-
.wrap_err("could not run container")?;
645+
.wrap_err("could not run container")?
646+
{
647+
status
648+
} else {
649+
return Ok(None);
650+
};
651+
642652
let needs_host = args.subcommand.map_or(false, |sc| sc.needs_host(is_remote));
643653
if !status.success() {
644654
warn_on_failure(&target, &toolchain, msg_info)?;

src/shell.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,15 @@ impl MessageInfo {
375375

376376
Ok(())
377377
}
378+
379+
/// Returns true if we've previously warned or errored, and we're in CI or `CROSS_NO_WARNINGS` has been set.
380+
///
381+
/// This is used so that unexpected warnings and errors cause ci to fail.
382+
pub fn should_fail(&self) -> bool {
383+
// FIXME: store env var
384+
env::var("CROSS_NO_WARNINGS").map_or_else(|_| is_ci::cached(), |env| bool_from_envvar(&env))
385+
&& self.has_warned
386+
}
378387
}
379388

380389
impl Default for MessageInfo {

0 commit comments

Comments
 (0)