Skip to content

Commit

Permalink
Merge #824
Browse files Browse the repository at this point in the history
824: Minor xtask restructuring. r=Emilgardis a=Alexhuszagh

Remove the `-it` flag from `target-info`, which can the command to not complete. Also changes `pull_image` to use `run_and_get_output` rather than `run`, which is how we should capture the output. Finally, it moves `format_repo` and `pull_image` to `util`, so they can be used by other commands.

This applies a few of the changes mentioned in #822.

Co-authored-by: Alex Huszagh <[email protected]>
  • Loading branch information
bors[bot] and Alexhuszagh authored Jun 19, 2022
2 parents 3d586e8 + f934745 commit b6dfd7a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
26 changes: 1 addition & 25 deletions xtask/src/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
process::{Command, Stdio},
};

use crate::util::{format_repo, pull_image};
use clap::Args;
use cross::CommandExt;

Expand Down Expand Up @@ -32,30 +33,6 @@ pub struct TargetInfo {
pub engine: Option<String>,
}

fn format_repo(registry: &str, repository: &str) -> String {
let mut output = String::new();
if !repository.is_empty() {
output = repository.to_string();
}
if !registry.is_empty() {
output = format!("{registry}/{output}");
}

output
}

fn pull_image(engine: &Path, image: &str, verbose: bool) -> cross::Result<()> {
let mut command = Command::new(engine);
command.arg("pull");
command.arg(image);
if !verbose {
// capture output to avoid polluting table
command.stdout(Stdio::null());
command.stderr(Stdio::null());
}
command.run(verbose, false).map_err(Into::into)
}

fn image_info(
engine: &Path,
target: &crate::ImageTarget,
Expand All @@ -70,7 +47,6 @@ fn image_info(

let mut command = Command::new(engine);
command.arg("run");
command.arg("-it");
command.arg("--rm");
command.args(&["-e", &format!("TARGET={}", target.triplet)]);
if has_test {
Expand Down
25 changes: 25 additions & 0 deletions xtask/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use std::path::Path;
use std::process::Command;

use cross::CommandExt;
use once_cell::sync::OnceCell;
use serde::Deserialize;

Expand Down Expand Up @@ -68,6 +72,27 @@ pub fn get_matrix() -> &'static Vec<Matrix> {
.unwrap()
}

pub fn format_repo(registry: &str, repository: &str) -> String {
let mut output = String::new();
if !repository.is_empty() {
output = repository.to_string();
}
if !registry.is_empty() {
output = format!("{registry}/{output}");
}

output
}

pub fn pull_image(engine: &Path, image: &str, verbose: bool) -> cross::Result<()> {
let mut command = Command::new(engine);
command.arg("pull");
command.arg(image);
let out = command.run_and_get_output(verbose)?;
command.status_result(verbose, out.status, Some(&out))?;
Ok(())
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct ImageTarget {
pub triplet: String,
Expand Down

0 comments on commit b6dfd7a

Please sign in to comment.