Skip to content

Commit d17aff7

Browse files
Merge #791
791: more features for `build-docker-image` r=Alexhuszagh a=Emilgardis you can now specify * tag `--tag` * repository `--repository` * disable caching `--no-cache` * do a dry run `--dry-run` * disable fastfail `--no-fastfail` * run every target that exists in current CI `--from-ci` this also makes it so that if running `build-docker-image` on github actions with multiple targets, a summary will be shown signaling success or failure for the target(s) Co-authored-by: Emil Gardström <[email protected]>
2 parents 5fe2145 + 37c379b commit d17aff7

16 files changed

+252
-117
lines changed

.github/actions/cargo-install-upload-artifacts/action.yml

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ inputs:
88
runs:
99
using: composite
1010
steps:
11-
- name: Check if crate has binaries
11+
- name: Setup
1212
id: metadata
1313
run: |
1414
metadata="$(cargo metadata --format-version 1 --no-deps)"
1515
16-
package_name="$(jq -r '.packages[0].name' <<< "${metadata}")"
17-
has_binaries="$(jq '.packages[0].targets | any(.kind | contains(["bin"]))' <<< "${metadata}")"
16+
package_name="cross"
1817
echo "::set-output name=package-name::${package_name}"
19-
echo "::set-output name=has-binaries::${has_binaries}"
2018
2119
out_dir="$(mktemp -d)"
2220
artifacts_dir="$(mktemp -d)"
@@ -31,7 +29,6 @@ runs:
3129
shell: bash
3230

3331
- name: Build with all features
34-
if: ${{ fromJson(steps.metadata.outputs.has-binaries) }}
3532
uses: actions-rs/cargo@v1
3633
with:
3734
command: install
@@ -45,7 +42,6 @@ runs:
4542
use-cross: true
4643

4744
- name: Archive artifacts
48-
if: ${{ fromJson(steps.metadata.outputs.has-binaries) }}
4945
id: archive
5046
run: |
5147
set -x

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
6565
### Internal
6666

6767
- #787 - add installer for git hooks.
68-
- #786 - Migrate build script to rust: `cargo build-docker-image $TARGET`
68+
- #786, #791 - Migrate build script to rust: `cargo build-docker-image $TARGET`
6969
- #730 - make FreeBSD builds more resilient.
7070
- #670 - Use serde for deserialization of Cross.toml
7171
- Change rust edition to 2021 and bump MSRV for the cross binary to 1.58.1

Cargo.lock

+25-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ members = ["xtask"]
1818

1919
[dependencies]
2020
atty = "0.2"
21-
# Pinned until further action to migrate to newer clap, see https://github.com/clap-rs/clap/issues/3822#issuecomment-1154069623
22-
clap = { version = "~3.1", features = ["derive"] }
21+
clap = { version = "3.2.2", features = ["derive", "unstable-v4"] }
2322
color-eyre = "0.6"
2423
eyre = "0.6"
24+
thiserror = "1"
2525
home = "0.5"
2626
rustc_version = "0.4"
2727
toml = "0.5"

src/bin/cross-util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn remove_images(
166166
}
167167
command.args(images);
168168
if execute {
169-
command.run(verbose)
169+
command.run(verbose).map_err(Into::into)
170170
} else {
171171
println!("{:?}", command);
172172
Ok(())

src/cargo.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,14 @@ pub fn cargo_metadata_with_args(
147147
}
148148

149149
/// Pass-through mode
150-
pub fn run(args: &[String], verbose: bool) -> Result<ExitStatus> {
150+
pub fn run(args: &[String], verbose: bool) -> Result<ExitStatus, CommandError> {
151151
Command::new("cargo").args(args).run_and_get_status(verbose)
152152
}
153153

154154
/// run cargo and get the output, does not check the exit status
155-
pub fn run_and_get_output(args: &[String], verbose: bool) -> Result<std::process::Output> {
155+
pub fn run_and_get_output(
156+
args: &[String],
157+
verbose: bool,
158+
) -> Result<std::process::Output, CommandError> {
156159
Command::new("cargo").args(args).run_and_get_output(verbose)
157160
}

src/docker.rs

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub fn register(target: &Target, verbose: bool) -> Result<()> {
7979
.arg("ubuntu:16.04")
8080
.args(&["sh", "-c", cmd])
8181
.run(verbose)
82+
.map_err(Into::into)
8283
}
8384

8485
fn validate_env_var(var: &str) -> Result<(&str, Option<&str>)> {
@@ -363,6 +364,7 @@ pub fn run(
363364
.arg(&image(config, target)?)
364365
.args(&["sh", "-c", &format!("PATH=$PATH:/rust/bin {:?}", cmd)])
365366
.run_and_get_status(verbose)
367+
.map_err(Into::into)
366368
}
367369

368370
pub fn image(config: &Config, target: &Target) -> Result<String> {

src/errors.rs

+10
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ pub fn install_panic_hook() -> Result<()> {
77
.display_env_section(false)
88
.install()
99
}
10+
11+
#[derive(Debug, thiserror::Error)]
12+
pub enum CommandError {
13+
#[error("`{1}` failed with exit code: {0}")]
14+
NonZeroExitCode(std::process::ExitStatus, String),
15+
#[error("could not execute `{0}`")]
16+
CouldNotExecute(#[source] Box<dyn std::error::Error + Send + Sync>, String),
17+
#[error("`{0:?}` output was not UTF-8")]
18+
Utf8Error(#[source] std::string::FromUtf8Error, std::process::Output),
19+
}

src/extensions.rs

+16-18
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use crate::errors::*;
66

77
pub trait CommandExt {
88
fn print_verbose(&self, verbose: bool);
9-
fn status_result(&self, status: ExitStatus) -> Result<()>;
10-
fn run(&mut self, verbose: bool) -> Result<()>;
11-
fn run_and_get_status(&mut self, verbose: bool) -> Result<ExitStatus>;
12-
fn run_and_get_stdout(&mut self, verbose: bool) -> Result<String>;
13-
fn run_and_get_output(&mut self, verbose: bool) -> Result<std::process::Output>;
9+
fn status_result(&self, status: ExitStatus) -> Result<(), CommandError>;
10+
fn run(&mut self, verbose: bool) -> Result<(), CommandError>;
11+
fn run_and_get_status(&mut self, verbose: bool) -> Result<ExitStatus, CommandError>;
12+
fn run_and_get_stdout(&mut self, verbose: bool) -> Result<String, CommandError>;
13+
fn run_and_get_output(&mut self, verbose: bool) -> Result<std::process::Output, CommandError>;
1414
}
1515

1616
impl CommandExt for Command {
@@ -20,29 +20,29 @@ impl CommandExt for Command {
2020
}
2121
}
2222

23-
fn status_result(&self, status: ExitStatus) -> Result<()> {
23+
fn status_result(&self, status: ExitStatus) -> Result<(), CommandError> {
2424
if status.success() {
2525
Ok(())
2626
} else {
27-
eyre::bail!("`{:?}` failed with exit code: {:?}", self, status.code())
27+
Err(CommandError::NonZeroExitCode(status, format!("{self:?}")))
2828
}
2929
}
3030

3131
/// Runs the command to completion
32-
fn run(&mut self, verbose: bool) -> Result<()> {
32+
fn run(&mut self, verbose: bool) -> Result<(), CommandError> {
3333
let status = self.run_and_get_status(verbose)?;
3434
self.status_result(status)
3535
}
3636

3737
/// Runs the command to completion
38-
fn run_and_get_status(&mut self, verbose: bool) -> Result<ExitStatus> {
38+
fn run_and_get_status(&mut self, verbose: bool) -> Result<ExitStatus, CommandError> {
3939
self.print_verbose(verbose);
4040
self.status()
41-
.wrap_err_with(|| format!("couldn't execute `{:?}`", self))
41+
.map_err(|e| CommandError::CouldNotExecute(Box::new(e), format!("{self:?}")))
4242
}
4343

4444
/// Runs the command to completion and returns its stdout
45-
fn run_and_get_stdout(&mut self, verbose: bool) -> Result<String> {
45+
fn run_and_get_stdout(&mut self, verbose: bool) -> Result<String, CommandError> {
4646
let out = self.run_and_get_output(verbose)?;
4747
self.status_result(out.status)?;
4848
out.stdout()
@@ -53,22 +53,20 @@ impl CommandExt for Command {
5353
/// # Notes
5454
///
5555
/// This command does not check the status.
56-
fn run_and_get_output(&mut self, verbose: bool) -> Result<std::process::Output> {
56+
fn run_and_get_output(&mut self, verbose: bool) -> Result<std::process::Output, CommandError> {
5757
self.print_verbose(verbose);
5858
self.output()
59-
.wrap_err_with(|| format!("couldn't execute `{:?}`", self))
60-
.map_err(Into::into)
59+
.map_err(|e| CommandError::CouldNotExecute(Box::new(e), format!("{self:?}")))
6160
}
6261
}
6362

6463
pub trait OutputExt {
65-
fn stdout(&self) -> Result<String>;
64+
fn stdout(&self) -> Result<String, CommandError>;
6665
}
6766

6867
impl OutputExt for std::process::Output {
69-
fn stdout(&self) -> Result<String> {
70-
String::from_utf8(self.stdout.clone())
71-
.wrap_err_with(|| format!("`{:?}` output was not UTF-8", self))
68+
fn stdout(&self) -> Result<String, CommandError> {
69+
String::from_utf8(self.stdout.clone()).map_err(|e| CommandError::Utf8Error(e, self.clone()))
7270
}
7371
}
7472

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod cli;
2222
mod config;
2323
mod cross_toml;
2424
mod docker;
25-
mod errors;
25+
pub mod errors;
2626
mod extensions;
2727
mod file;
2828
mod id;
@@ -464,7 +464,7 @@ pub fn run() -> Result<ExitStatus> {
464464
}
465465
Ok(out.status)
466466
}
467-
_ => cargo::run(&argv, verbose),
467+
_ => cargo::run(&argv, verbose).map_err(Into::into),
468468
}
469469
}
470470

src/rustc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub fn target_list(verbose: bool) -> Result<TargetList> {
4040
.map(|s| TargetList {
4141
triples: s.lines().map(|l| l.to_owned()).collect(),
4242
})
43+
.map_err(Into::into)
4344
}
4445

4546
pub fn sysroot(host: &Host, target: &Target, verbose: bool) -> Result<PathBuf> {

xtask/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cross = { path = "..", features = ["dev"] }
1212
walkdir = { version = "2" }
1313
color-eyre = "0.6"
1414
eyre = "0.6"
15-
clap = { version = "~3.1", features = ["derive", "env"] }
15+
clap = { version = "3.2.2", features = ["derive", "env", "unstable-v4"] }
1616
which = { version = "4", default_features = false }
1717
serde = { version = "1", features = ["derive"] }
1818
serde_yaml = "0.8"

0 commit comments

Comments
 (0)