Repository: cross-rs/cross
Pull request #909 (2022-07-04 16:37:17)

Allow verbose output in ct-ng images.
Defaulting to verbose output pollutes the build logs during CI, which can be obscure any errors or status results. However, silencing output on local builds can make it difficult to debug issues. This checks for verbose output and the build script is running on a TTY, so we only get spinner output in those cases (IE, where the spinners actually work and are able to delete the current output line).


Patch:
diff --git a/.github/workflows/weekly.yml b/.github/workflows/weekly.yml
index 0e34792..f6f5cc5 100644
--- a/.github/workflows/weekly.yml
+++ b/.github/workflows/weekly.yml
@@ -24,18 +24,6 @@ jobs:
       - name: Build Docker image
         id: build-docker-image
         run: cargo xtask build-docker-image -v --no-cache --no-output --from-ci --no-fastfail --tag weekly
-        timeout-minutes: 1440
-  wiki:
-    name: Ensure wiki is valid
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v3
-      - uses: ./.github/actions/setup-rust
-      - run: git clone ${wikirepo}
-        shell: bash
-        env:
-          wikirepo: https://github.com/${{ github.repository }}.wiki.git
-      - run: cargo test toml_check -- --nocapture
   cargo-deny:
     runs-on: ubuntu-latest
     steps:
diff --git a/README.md b/README.md
index 6f8a690..e1d7c95 100644
--- a/README.md
+++ b/README.md
@@ -91,7 +91,7 @@ You have three options to configure `cross`. All of these options use the TOML f
 You can directly set [configuration values](docs/cross_toml.md) in your `Cargo.toml` file, under the `[package.metadata.cross]` table, i.e. key prefix.
 An example config snippet would look like this:
 
-```toml,cargo
+```
 [package.metadata.cross.target.aarch64-unknown-linux-gnu]
 xargo = false
 image = "test-image"
diff --git a/docker/Dockerfile.arm-unknown-linux-gnueabihf b/docker/Dockerfile.arm-unknown-linux-gnueabihf
index c0d56c7..cc8aa81 100644
--- a/docker/Dockerfile.arm-unknown-linux-gnueabihf
+++ b/docker/Dockerfile.arm-unknown-linux-gnueabihf
@@ -10,6 +10,7 @@ RUN /cmake.sh
 COPY xargo.sh /
 RUN /xargo.sh
 
+ARG VERBOSE
 COPY crosstool-ng.sh /
 COPY crosstool-config/arm-unknown-linux-gnueabihf.config /
 RUN /crosstool-ng.sh arm-unknown-linux-gnueabihf.config 5
diff --git a/docker/cross-toolchains b/docker/cross-toolchains
index 852e448..5504d92 160000
--- a/docker/cross-toolchains
+++ b/docker/cross-toolchains
@@ -1,1 +1,1 @@
-Subproject commit 852e448897beb8d6c3ca31cd7188f4d8b97799a4
+Subproject commit 5504d9293334744cf2555286707d9907b89afbfb
diff --git a/docker/crosstool-ng.sh b/docker/crosstool-ng.sh
index 16a3078..6c76bd0 100755
--- a/docker/crosstool-ng.sh
+++ b/docker/crosstool-ng.sh
@@ -1,11 +1,19 @@
 #!/bin/bash
 
 set -x
-set -euo pipefail
+set -eo pipefail
 
 # shellcheck disable=SC1091
 . lib.sh
 
+silence_stdout() {
+    if [[ "${VERBOSE}" == "1" ]]; then
+        "${@}"
+    else
+        "${@}" >/dev/null
+    fi
+}
+
 main() {
     local config="${1}"
     local nproc="${2}"
@@ -75,14 +83,15 @@ main() {
         # work with any bash functions: must call a command.
         timeout "${timeout}" \
             su "${username}" -c \
-            "STOP=${step} CT_DEBUG_CT_SAVE_STEPS=1 ${crosstooldir}/bin/ct-ng build.${nproc} &> /dev/null"
+            "STOP=${step} CT_DEBUG_CT_SAVE_STEPS=1 ${crosstooldir}/bin/ct-ng build.${nproc}"
     }
 
-    while download; [ $? -eq 124 ]; do
+    while silence_stdout download; [ $? -eq 124 ]; do
         # Indicates a timeout, repeat the command.
         sleep "${sleep}"
     done
-    su "${username}" -c "CT_DEBUG_CT_SAVE_STEPS=1 ${crosstooldir}/bin/ct-ng build.${nproc} &> /dev/null"
+    silence_stdout su "${username}" \
+        -c "CT_DEBUG_CT_SAVE_STEPS=1 ${crosstooldir}/bin/ct-ng build.${nproc}"
 
     popd
 
diff --git a/src/docker/shared.rs b/src/docker/shared.rs
index 9e8cece..0465ee4 100644
--- a/src/docker/shared.rs
+++ b/src/docker/shared.rs
@@ -59,10 +59,8 @@ impl Directories {
 
         // create the directories we are going to mount before we mount them,
         // otherwise `docker` will create them but they will be owned by `root`
-        // cargo builds all intermediate directories, but fails
-        // if it has other issues (such as permission errors).
-        fs::create_dir_all(&cargo)?;
-        fs::create_dir_all(&xargo)?;
+        fs::create_dir(&cargo).ok();
+        fs::create_dir(&xargo).ok();
         create_target_dir(target)?;
 
         let cargo = mount_finder.find_mount_path(cargo);
diff --git a/xtask/src/build_docker_image.rs b/xtask/src/build_docker_image.rs
index eacaf17..c1e056b 100644
--- a/xtask/src/build_docker_image.rs
+++ b/xtask/src/build_docker_image.rs
@@ -24,8 +24,8 @@ pub struct BuildDockerImage {
     #[clap(long, env = "LABELS")]
     pub labels: Option<String>,
     /// Provide verbose diagnostic output.
-    #[clap(short, long)]
-    pub verbose: bool,
+    #[clap(short, long, action = clap::ArgAction::Count)]
+    pub verbose: u8,
     /// Do not print cross log messages.
     #[clap(short, long)]
     pub quiet: bool,
@@ -113,7 +113,7 @@ pub fn build_docker_image(
     }: BuildDockerImage,
     engine: &docker::Engine,
 ) -> cross::Result<()> {
-    let msg_info = MessageInfo::create(verbose, quiet, color.as_deref())?;
+    let msg_info = MessageInfo::create(verbose != 0, quiet, color.as_deref())?;
     let metadata = cargo_metadata(msg_info)?;
     let version = metadata
         .get_package("cross")
@@ -236,6 +236,9 @@ pub fn build_docker_image(
         for arg in &build_arg {
             docker_build.args(&["--build-arg", arg]);
         }
+        if verbose > 1 {
+            docker_build.args(&["--build-arg", "VERBOSE=1"]);
+        }
 
         docker_build.arg(".");
 
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 783561d..5e45f3a 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -75,7 +75,8 @@ pub fn main() -> cross::Result<()> {
             target_info::target_info(args, &engine)?;
         }
         Commands::BuildDockerImage(args) => {
-            let msg_info = MessageInfo::create(args.verbose, args.quiet, args.color.as_deref())?;
+            let msg_info =
+                MessageInfo::create(args.verbose != 0, args.quiet, args.color.as_deref())?;
             let engine = get_container_engine(args.engine.as_deref(), msg_info)?;
             build_docker_image::build_docker_image(args, &engine)?;
         }


Test patch:
diff --git a/src/tests/toml.rs b/src/tests/toml.rs
index e8cd68f..4501755 100644
--- a/src/tests/toml.rs
+++ b/src/tests/toml.rs
@@ -3,10 +3,8 @@ use std::io::Read;
 use once_cell::sync::Lazy;
 use regex::{Regex, RegexBuilder};
 
-use crate::ToUtf8;
-
 static TOML_REGEX: Lazy<Regex> = Lazy::new(|| {
-    RegexBuilder::new(r#"```toml(.*?)\n(.*?)```"#)
+    RegexBuilder::new(r#"```toml\n(.*?)```"#)
         .multi_line(true)
         .dot_matches_new_line(true)
         .build()
@@ -37,40 +35,16 @@ fn toml_check() -> Result<(), Box<dyn std::error::Error>> {
         let mut contents = String::new();
         file.read_to_string(&mut contents).unwrap();
         for matches in TOML_REGEX.captures_iter(&contents) {
-            let cargo = {
-                let t = matches.get(1).unwrap().as_str();
-                if t.is_empty() {
-                    false
-                } else if t == ",cargo" {
-                    true
-                } else {
-                    println!("skipping {t}");
-                    continue;
-                }
-            };
-            let fence = matches.get(2).unwrap();
-            let fence_content = fence
-                .as_str()
-                .replace("$TARGET", "x86_64-unknown-linux-gnu")
-                .replace("${target}", "x86_64-unknown-linux-gnu");
-
+            let fence = matches.get(1).unwrap();
             eprintln!(
-                "testing snippet at: {}:{:?}",
-                dir_entry.path().to_utf8()?,
+                "testing snippet at: {:?}:{:?}",
+                dir_entry.path(),
                 text_line_no(&contents, fence.range().start),
             );
-            assert!(if !cargo {
-                crate::cross_toml::CrossToml::parse_from_cross(
-                    &fence_content,
-                    crate::shell::MessageInfo::default(),
-                )?
-            } else {
-                crate::cross_toml::CrossToml::parse_from_cargo(
-                    &fence_content,
-                    crate::shell::MessageInfo::default(),
-                )?
-                .unwrap_or_default()
-            }
+            assert!(crate::cross_toml::CrossToml::parse_from_cross(
+                fence.as_str(),
+                crate::shell::MessageInfo::default()
+            )?
             .1
             .is_empty());
         }