mirror of https://github.com/aya-rs/aya
xtask: ensure libbpf submodule is initialized
For xtask tasks which need libbpf, make sure it's initialized automatically. This eases the user-experience so that users don't need to think about the submodule, while retaining all the benefits of using a submodule vs forcing the user to manually check out libbpf and stick it in some pre-defined place.reviewable/pr664/r1
parent
af54a819a3
commit
7f24e25f44
@ -0,0 +1,23 @@
|
||||
/// Functionality for ensuring that the submodule is properly set up.
|
||||
use std::{path::PathBuf, process::Command};
|
||||
|
||||
use anyhow::Context;
|
||||
|
||||
/// Ensures that the submodule is initialized and returns the path to the submodule.
|
||||
pub(crate) fn ensure_initialized() -> Result<PathBuf, anyhow::Error> {
|
||||
// It's okay to hard-code this path because the submodule is checked in.
|
||||
let libbpf_dir = PathBuf::from("libbpf");
|
||||
// Exec `git submodule update --init` to ensure that the submodule is initialized.
|
||||
let status = Command::new("git")
|
||||
.args(["submodule", "update", "--init", "--"])
|
||||
.arg(&libbpf_dir)
|
||||
.status()
|
||||
.context("failed to initialized submodules")?;
|
||||
if status.success() {
|
||||
Ok(libbpf_dir)
|
||||
} else {
|
||||
Err(anyhow::anyhow!(
|
||||
"failed to initialize submodules: {status:?}"
|
||||
))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue