You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aya/xtask/src/main.rs

60 lines
1.6 KiB
Rust

mod codegen;
mod docs;
mod run;
use anyhow::{Context as _, Result};
use cargo_metadata::{Metadata, MetadataCommand};
use clap::Parser;
use std::process::Command;
use xtask::{exec, LIBBPF_DIR};
#[derive(Parser)]
pub struct XtaskOptions {
#[clap(subcommand)]
command: Subcommand,
}
#[derive(Parser)]
enum Subcommand {
Codegen(codegen::Options),
Docs,
BuildIntegrationTest(run::BuildOptions),
IntegrationTest(run::Options),
}
fn main() -> Result<()> {
let XtaskOptions { command } = Parser::parse();
let metadata = MetadataCommand::new()
.no_deps()
.exec()
.context("failed to run cargo metadata")?;
let Metadata { workspace_root, .. } = &metadata;
// Initialize the submodules.
exec(Command::new("git").arg("-C").arg(workspace_root).args([
"submodule",
"update",
"--init",
]))?;
let libbpf_dir = workspace_root.join(LIBBPF_DIR);
let libbpf_dir = libbpf_dir.as_std_path();
match command {
Subcommand::Codegen(opts) => codegen::codegen(opts, libbpf_dir),
Subcommand::Docs => docs::docs(metadata),
Subcommand::BuildIntegrationTest(opts) => {
let binaries = run::build(opts)?;
let mut stdout = std::io::stdout();
for (_name, binary) in binaries {
use std::{io::Write as _, os::unix::ffi::OsStrExt as _};
stdout.write_all(binary.as_os_str().as_bytes())?;
stdout.write_all("\n".as_bytes())?;
}
Ok(())
}
Subcommand::IntegrationTest(opts) => run::run(opts),
}
}