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

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

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

Loading…
Cancel
Save