Pārlūkot izejas kodu

Avoid uncontrolled stdout into cargo

This fixes rebuild on change of C sources by black-holing:
- Output of `make` (harmless).
- Output of `llmv-objcopy` (harmful: binary data).
Tamir Duberstein 2 nedēļas atpakaļ
vecāks
revīzija
c8e9037ca6

+ 6 - 3
test/integration-test/build.rs

@@ -8,7 +8,7 @@ use std::{
 
 use anyhow::{Context as _, Ok, Result, anyhow};
 use aya_build::cargo_metadata::{Metadata, MetadataCommand, Package, Target, TargetKind};
-use xtask::{AYA_BUILD_INTEGRATION_BPF, LIBBPF_DIR, exec, install_libbpf_headers};
+use xtask::{AYA_BUILD_INTEGRATION_BPF, LIBBPF_DIR, exec, install_libbpf_headers_cmd};
 
 /// This file, along with the xtask crate, allows analysis tools such as `cargo check`, `cargo
 /// clippy`, and even `cargo build` to work as users expect. Prior to this file's existence, this
@@ -86,7 +86,9 @@ fn main() -> Result<()> {
         println!("cargo:rerun-if-changed={libbpf_dir}");
 
         let libbpf_headers_dir = out_dir.join("libbpf_headers");
-        install_libbpf_headers(&libbpf_dir, &libbpf_headers_dir)?;
+        let mut cmd = install_libbpf_headers_cmd(&libbpf_dir, &libbpf_headers_dir);
+        cmd.stdout(Stdio::null());
+        exec(&mut cmd)?;
 
         let bpf_dir = manifest_dir.join("bpf");
 
@@ -158,7 +160,8 @@ fn main() -> Result<()> {
                         .arg("--dump-section")
                         .arg(output)
                         .arg("-")
-                        .stdin(stdout),
+                        .stdin(stdout)
+                        .stdout(Stdio::null()),
                 )?;
 
                 let output = child

+ 3 - 2
xtask/src/codegen/aya_ebpf_bindings.rs

@@ -8,7 +8,7 @@ use aya_tool::bindgen;
 use proc_macro2::TokenStream;
 use quote::ToTokens as _;
 use syn::{Item, parse_str};
-use xtask::install_libbpf_headers;
+use xtask::{exec, install_libbpf_headers_cmd};
 
 use crate::codegen::{
     Architecture, SysrootOptions,
@@ -30,7 +30,8 @@ pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<()> {
     let tmp_dir = tempfile::tempdir().context("tempdir failed")?;
     let libbpf_headers_dir = tmp_dir.path().join("libbpf_headers");
 
-    install_libbpf_headers(libbpf_dir, &libbpf_headers_dir)?;
+    let mut cmd = install_libbpf_headers_cmd(libbpf_dir, &libbpf_headers_dir);
+    exec(&mut cmd)?;
 
     let dir = PathBuf::from("ebpf/aya-ebpf-bindings");
 

+ 9 - 12
xtask/src/lib.rs

@@ -15,25 +15,22 @@ pub fn exec(cmd: &mut Command) -> Result<()> {
     Ok(())
 }
 
-/// Installs the libbpf headers files from the `source_dir` to the
+/// Returns a [`Command`]` that Installs the libbpf headers files from the `source_dir` to the
 /// `headers_dir`.
-pub fn install_libbpf_headers(
+pub fn install_libbpf_headers_cmd(
     source_dir: impl AsRef<Path>,
     headers_dir: impl AsRef<Path>,
-) -> Result<()> {
+) -> Command {
     let mut includedir = OsString::new();
     includedir.push("INCLUDEDIR=");
     includedir.push(headers_dir.as_ref().as_os_str());
 
-    exec(
-        Command::new("make")
-            .arg("-C")
-            .arg(source_dir.as_ref().join("src"))
-            .arg(includedir)
-            .arg("install_headers"),
-    )?;
-
-    Ok(())
+    let mut cmd = Command::new("make");
+    cmd.arg("-C")
+        .arg(source_dir.as_ref().join("src"))
+        .arg(includedir)
+        .arg("install_headers");
+    cmd
 }
 
 #[derive(Debug)]