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).
reviewable/pr1251/r21
Tamir Duberstein 3 weeks ago
parent 025b6eaa0d
commit c8e9037ca6

@ -8,7 +8,7 @@ use std::{
use anyhow::{Context as _, Ok, Result, anyhow}; use anyhow::{Context as _, Ok, Result, anyhow};
use aya_build::cargo_metadata::{Metadata, MetadataCommand, Package, Target, TargetKind}; 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 /// 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 /// 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}"); println!("cargo:rerun-if-changed={libbpf_dir}");
let libbpf_headers_dir = out_dir.join("libbpf_headers"); 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"); let bpf_dir = manifest_dir.join("bpf");
@ -158,7 +160,8 @@ fn main() -> Result<()> {
.arg("--dump-section") .arg("--dump-section")
.arg(output) .arg(output)
.arg("-") .arg("-")
.stdin(stdout), .stdin(stdout)
.stdout(Stdio::null()),
)?; )?;
let output = child let output = child

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

@ -15,25 +15,22 @@ pub fn exec(cmd: &mut Command) -> Result<()> {
Ok(()) 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`. /// `headers_dir`.
pub fn install_libbpf_headers( pub fn install_libbpf_headers_cmd(
source_dir: impl AsRef<Path>, source_dir: impl AsRef<Path>,
headers_dir: impl AsRef<Path>, headers_dir: impl AsRef<Path>,
) -> Result<()> { ) -> Command {
let mut includedir = OsString::new(); let mut includedir = OsString::new();
includedir.push("INCLUDEDIR="); includedir.push("INCLUDEDIR=");
includedir.push(headers_dir.as_ref().as_os_str()); includedir.push(headers_dir.as_ref().as_os_str());
exec( let mut cmd = Command::new("make");
Command::new("make") cmd.arg("-C")
.arg("-C") .arg(source_dir.as_ref().join("src"))
.arg(source_dir.as_ref().join("src")) .arg(includedir)
.arg(includedir) .arg("install_headers");
.arg("install_headers"), cmd
)?;
Ok(())
} }
#[derive(Debug)] #[derive(Debug)]

Loading…
Cancel
Save