Skip to content

Commit

Permalink
libbpf-cargo: Remove --quiet option of 'libbpf make' sub-command
Browse files Browse the repository at this point in the history
Remove the '--quiet' option of the 'libbpf make' sub-command. In my
opinion, it makes little sense to invert the logic here and emit output
by default, but allow for silencing -- after all, the default output (on
success) appears to be nothing more than some "Finished [...]" message.
Let's piggy-back on the existing logging initialization instead,
emitting this output if the user activated at least log level INFO.

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o authored and danielocfb committed Jan 16, 2025
1 parent 1885224 commit a35be25
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
1 change: 1 addition & 0 deletions libbpf-cargo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Unreleased
sub-command
- Replaced `--debug` option of `libbpf` sub-command with `-v` /
`--verbose`
- Removed `--quiet` option of `libbpf make` sub-command


0.25.0-beta.1
Expand Down
5 changes: 0 additions & 5 deletions libbpf-cargo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ enum Command {
manifest_path: Option<PathBuf>,
#[command(flatten)]
clang_opts: ClangOpts,
#[arg(short, long)]
/// Quiet output
quiet: bool,
/// Arguments to pass to `cargo build`
///
/// Example: cargo libbpf build -- --package mypackage
Expand Down Expand Up @@ -146,14 +143,12 @@ fn main() -> Result<()> {
clang_path,
clang_args,
},
quiet,
cargo_build_args,
rustfmt_path,
} => make::make(
manifest_path.as_ref(),
clang_path.as_ref(),
clang_args,
quiet,
cargo_build_args,
rustfmt_path.as_ref(),
),
Expand Down
15 changes: 6 additions & 9 deletions libbpf-cargo/src/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,29 @@ use std::process::Command;
use anyhow::bail;
use anyhow::Context;
use anyhow::Result;
use log::debug;
use log::log_enabled;
use log::Level::Info;

use crate::build;
use crate::gen;

#[allow(clippy::too_many_arguments)]
pub fn make(
manifest_path: Option<&PathBuf>,
clang: Option<&PathBuf>,
clang_args: Vec<OsString>,
quiet: bool,
cargo_build_args: Vec<String>,
rustfmt_path: Option<&PathBuf>,
) -> Result<()> {
if !quiet {
println!("Compiling BPF objects");
}
debug!("Compiling BPF objects");
build::build(manifest_path, clang, clang_args).context("Failed to compile BPF objects")?;

if !quiet {
println!("Generating skeletons");
}
debug!("Generating skeletons");
gen::gen(manifest_path, None, rustfmt_path).context("Failed to generate skeletons")?;

let mut cmd = Command::new("cargo");
cmd.arg("build");
if quiet {
if !log_enabled!(Info) {
cmd.arg("--quiet");
}
for arg in cargo_build_args {
Expand Down
5 changes: 2 additions & 3 deletions libbpf-cargo/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ fn test_make_basic() {
let _prog_file =
File::create(proj_dir.join("src/bpf/prog.bpf.c")).expect("failed to create prog file");

make(Some(&cargo_toml), None, Vec::new(), true, Vec::new(), None).unwrap();
make(Some(&cargo_toml), None, Vec::new(), Vec::new(), None).unwrap();

// Validate generated object file
validate_bpf_o(proj_dir.as_path().join("target/bpf/prog.bpf.o").as_path());
Expand Down Expand Up @@ -333,7 +333,6 @@ fn test_make_workspace() {
Some(&workspace_cargo_toml),
None,
Vec::new(),
true,
Vec::new(),
None,
)
Expand Down Expand Up @@ -385,7 +384,7 @@ fn build_rust_project_from_bpf_c_impl(bpf_c: &str, rust: &str, run: bool) {
// Lay down the necessary header files
add_vmlinux_header(&proj_dir);

make(Some(&cargo_toml), None, Vec::new(), true, Vec::new(), None).unwrap();
make(Some(&cargo_toml), None, Vec::new(), Vec::new(), None).unwrap();

let mut cargo = OpenOptions::new()
.append(true)
Expand Down

0 comments on commit a35be25

Please sign in to comment.