Skip to content

Commit

Permalink
don't fallback or allow warnings/errors in CI or with env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilgardis committed Jan 31, 2024
1 parent 8965488 commit 7d196d5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
2 changes: 2 additions & 0 deletions cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.x86-64-unknown-linux-gnu]
env.passthrough = ["lol"]
8 changes: 2 additions & 6 deletions src/bin/cross.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
};

use cross::{
cargo, cli, config, rustc,
cargo, cli, rustc,
shell::{self, Verbosity},
OutputExt, Subcommand,
};
Expand All @@ -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<String> = env::args().skip(1).collect();
msg_info.note("Falling back to `cargo` on the host.")?;
Expand Down
7 changes: 5 additions & 2 deletions src/docker/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) fn run(
paths: DockerPaths,
args: &[String],
msg_info: &mut MessageInfo,
) -> Result<ExitStatus> {
) -> Result<Option<ExitStatus>> {
let engine = &options.engine;
let toolchain_dirs = paths.directories.toolchain_directories();
let package_dirs = paths.directories.package_directories();
Expand Down Expand Up @@ -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)
Expand All @@ -162,5 +165,5 @@ pub(crate) fn run(
ChildContainer::exit_static();
}

status
status.map(Some)
}
5 changes: 4 additions & 1 deletion src/docker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crate::Subcommand>,
msg_info: &mut MessageInfo,
) -> Result<ExitStatus> {
) -> Result<Option<ExitStatus>> {
if cfg!(target_os = "windows") && options.in_docker() {
msg_info.fatal(
"running cross insider a container running windows is currently unsupported",
Expand Down
8 changes: 6 additions & 2 deletions src/docker/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ pub(crate) fn run(
args: &[String],
subcommand: Option<crate::Subcommand>,
msg_info: &mut MessageInfo,
) -> Result<ExitStatus> {
) -> Result<Option<ExitStatus>> {
let engine = &options.engine;
let target = &options.target;
let toolchain_dirs = paths.directories.toolchain_directories();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1010,5 +1014,5 @@ symlink_recurse \"${{prefix}}\"

ChildContainer::finish_static(is_tty, msg_info);

status
status.map(Some)
}
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,21 +624,31 @@ pub fn run(
false,
);

if msg_info.should_fail() {
return Ok(None);
}

install_interpreter_if_needed(
&args,
host_version_meta,
&target,
&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)?;
Expand Down
9 changes: 9 additions & 0 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7d196d5

Please sign in to comment.