xtask: rework command line

xtask codegen --libbpf-dir <libbpf-dir> [SUBCOMMAND]

If SUBCOMMAND (eg aya or aya-bpf-bindings) is not given, codegen
everything.
pull/1/head
Alessandro Decina 4 years ago
parent 9d112c35c7
commit f0444233b3

@ -1,23 +1,16 @@
use anyhow::anyhow;
use std::path::PathBuf;
use structopt::StructOpt;
use aya_gen::{bindgen, write_to_file};
use crate::codegen::Architecture;
use crate::codegen::{Architecture, Options};
#[derive(StructOpt)]
pub struct CodegenOptions {
#[structopt(long)]
libbpf_dir: PathBuf,
pub fn codegen(opts: &Options) -> Result<(), anyhow::Error> {
codegen_internal_btf_bindings(opts)?;
codegen_bindings(opts)
}
pub fn codegen(opts: CodegenOptions) -> Result<(), anyhow::Error> {
codegen_internal_btf_bindings(&opts)?;
codegen_bindings(&opts)
}
fn codegen_internal_btf_bindings(opts: &CodegenOptions) -> Result<(), anyhow::Error> {
fn codegen_internal_btf_bindings(opts: &Options) -> Result<(), anyhow::Error> {
let dir = PathBuf::from("aya");
let generated = dir.join("src/generated");
let mut bindgen = bindgen::user_builder().header(
@ -46,7 +39,7 @@ fn codegen_internal_btf_bindings(opts: &CodegenOptions) -> Result<(), anyhow::Er
Ok(())
}
fn codegen_bindings(opts: &CodegenOptions) -> Result<(), anyhow::Error> {
fn codegen_bindings(opts: &Options) -> Result<(), anyhow::Error> {
let types = [
// BPF
"BPF_TYPES",

@ -2,7 +2,6 @@ use anyhow::anyhow;
use proc_macro2::TokenStream;
use quote::ToTokens;
use std::path::PathBuf;
use structopt::StructOpt;
use aya_gen::{
bindgen,
@ -13,16 +12,10 @@ use syn::{parse_str, Item};
use crate::codegen::{
helpers::{expand_helpers, extract_helpers},
Architecture,
Architecture, Options,
};
#[derive(StructOpt)]
pub struct CodegenOptions {
#[structopt(long)]
libbpf_dir: PathBuf,
}
pub fn codegen(opts: CodegenOptions) -> Result<(), anyhow::Error> {
pub fn codegen(opts: &Options) -> Result<(), anyhow::Error> {
let dir = PathBuf::from("bpf/aya-bpf-bindings");
let builder = || {

@ -2,6 +2,8 @@ mod aya;
mod aya_bpf_bindings;
mod helpers;
use std::path::PathBuf;
use structopt::StructOpt;
const SUPPORTED_ARCHS: &'static [Architecture] = &[Architecture::X86_64, Architecture::AArch64];
@ -41,22 +43,29 @@ impl std::fmt::Display for Architecture {
#[derive(StructOpt)]
pub struct Options {
#[structopt(long)]
libbpf_dir: PathBuf,
#[structopt(subcommand)]
command: Command,
command: Option<Command>,
}
#[derive(StructOpt)]
enum Command {
#[structopt(name = "aya")]
Aya(aya::CodegenOptions),
Aya,
#[structopt(name = "aya-bpf-bindings")]
AyaBpfBindings(aya_bpf_bindings::CodegenOptions),
AyaBpfBindings,
}
pub fn codegen(opts: Options) -> Result<(), anyhow::Error> {
use Command::*;
match opts.command {
Aya(opts) => aya::codegen(opts),
AyaBpfBindings(opts) => aya_bpf_bindings::codegen(opts),
Some(Aya) => aya::codegen(&opts),
Some(AyaBpfBindings) => aya_bpf_bindings::codegen(&opts),
None => {
aya::codegen(&opts)?;
aya_bpf_bindings::codegen(&opts)
}
}
}

Loading…
Cancel
Save