From 7d196d5e7b7122e40b42a8661fcc15556cd5f625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Fri, 24 Mar 2023 20:27:18 +0100 Subject: [PATCH] don't fallback or allow warnings/errors in CI or with env var --- cross.toml | 2 ++ src/bin/cross.rs | 8 ++------ src/docker/local.rs | 7 +++++-- src/docker/mod.rs | 5 ++++- src/docker/remote.rs | 8 ++++++-- src/lib.rs | 14 ++++++++++++-- src/shell.rs | 9 +++++++++ 7 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 cross.toml diff --git a/cross.toml b/cross.toml new file mode 100644 index 000000000..34b2950cd --- /dev/null +++ b/cross.toml @@ -0,0 +1,2 @@ +[target.x86-64-unknown-linux-gnu] +env.passthrough = ["lol"] diff --git a/src/bin/cross.rs b/src/bin/cross.rs index c20bdc146..ba66146fb 100644 --- a/src/bin/cross.rs +++ b/src/bin/cross.rs @@ -6,7 +6,7 @@ use std::{ }; use cross::{ - cargo, cli, config, rustc, + cargo, cli, rustc, shell::{self, Verbosity}, OutputExt, Subcommand, }; @@ -21,11 +21,7 @@ pub fn main() -> cross::Result<()> { let mut msg_info = shell::MessageInfo::create(args.verbose, args.quiet, args.color.as_deref())?; let status = match cross::run(args, target_list, &mut msg_info)? { Some(status) => status, - None if env::var("CROSS_NO_WARNINGS") - .map(|env| config::bool_from_envvar(&env)) - .unwrap_or_else(|_| is_ci::uncached()) - && !msg_info.has_warned => - { + None if !msg_info.should_fail() => { // if we fallback to the host cargo, use the same invocation that was made to cross let argv: Vec = env::args().skip(1).collect(); msg_info.note("Falling back to `cargo` on the host.")?; diff --git a/src/docker/local.rs b/src/docker/local.rs index 8acf67a8e..e4f634dcc 100644 --- a/src/docker/local.rs +++ b/src/docker/local.rs @@ -31,7 +31,7 @@ pub(crate) fn run( paths: DockerPaths, args: &[String], msg_info: &mut MessageInfo, -) -> Result { +) -> Result> { let engine = &options.engine; let toolchain_dirs = paths.directories.toolchain_directories(); let package_dirs = paths.directories.package_directories(); @@ -147,6 +147,9 @@ pub(crate) fn run( } ChildContainer::create(engine.clone(), container_id)?; + if msg_info.should_fail() { + return Ok(None); + } let status = docker .arg(&image_name) .add_build_command(toolchain_dirs, &cmd) @@ -162,5 +165,5 @@ pub(crate) fn run( ChildContainer::exit_static(); } - status + status.map(Some) } diff --git a/src/docker/mod.rs b/src/docker/mod.rs index 7be9790e4..f61798aec 100644 --- a/src/docker/mod.rs +++ b/src/docker/mod.rs @@ -41,13 +41,16 @@ pub fn image_name(target: &str, sub: Option<&str>, repository: &str, tag: &str) } } +// TODO: The Option here in the result should be removed and Result::Error replaced with a enum to properly signal error + +// Ok(None) means that the command failed, due to a warning or error, when `msg_info.should_fail() == true` pub fn run( options: DockerOptions, paths: DockerPaths, args: &[String], subcommand: Option, msg_info: &mut MessageInfo, -) -> Result { +) -> Result> { if cfg!(target_os = "windows") && options.in_docker() { msg_info.fatal( "running cross insider a container running windows is currently unsupported", diff --git a/src/docker/remote.rs b/src/docker/remote.rs index d920bdf56..b8c9ee803 100644 --- a/src/docker/remote.rs +++ b/src/docker/remote.rs @@ -670,7 +670,7 @@ pub(crate) fn run( args: &[String], subcommand: Option, msg_info: &mut MessageInfo, -) -> Result { +) -> Result> { let engine = &options.engine; let target = &options.target; let toolchain_dirs = paths.directories.toolchain_directories(); @@ -897,6 +897,10 @@ pub(crate) fn run( let mut cmd = options.command_variant.safe_command(); + if msg_info.should_fail() { + return Ok(None); + } + if !options.command_variant.is_shell() { // `clean` doesn't handle symlinks: it will just unlink the target // directory, so we should just substitute it our target directory @@ -1010,5 +1014,5 @@ symlink_recurse \"${{prefix}}\" ChildContainer::finish_static(is_tty, msg_info); - status + status.map(Some) } diff --git a/src/lib.rs b/src/lib.rs index 9e34d6887..82dfa2b87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -624,6 +624,10 @@ pub fn run( false, ); + if msg_info.should_fail() { + return Ok(None); + } + install_interpreter_if_needed( &args, host_version_meta, @@ -631,14 +635,20 @@ pub fn run( &options, msg_info, )?; - let status = docker::run( + let status = if let Some(status) = docker::run( options, paths, &filtered_args, args.subcommand.clone(), msg_info, ) - .wrap_err("could not run container")?; + .wrap_err("could not run container")? + { + status + } else { + return Ok(None); + }; + let needs_host = args.subcommand.map_or(false, |sc| sc.needs_host(is_remote)); if !status.success() { warn_on_failure(&target, &toolchain, msg_info)?; diff --git a/src/shell.rs b/src/shell.rs index 46a03ba63..8c88430c6 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -375,6 +375,15 @@ impl MessageInfo { Ok(()) } + + /// Returns true if we've previously warned or errored, and we're in CI or `CROSS_NO_WARNINGS` has been set. + /// + /// This is used so that unexpected warnings and errors cause ci to fail. + pub fn should_fail(&self) -> bool { + // FIXME: store env var + env::var("CROSS_NO_WARNINGS").map_or_else(|_| is_ci::cached(), |env| bool_from_envvar(&env)) + && self.has_warned + } } impl Default for MessageInfo {