Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a32df7b4 authored by Martin Geisler's avatar Martin Geisler Committed by Henri Chataing
Browse files

pdl: Update code for compatibility with Clap 2.3.3

tm-mainline-prod has 2.3.3 version, use 3.2.23 on aosp/master.
This is for integration with UWB.

Tag: #feature
Bug: 228306436
Test: atest pdl_tests pdl_rust_generator_tests_{le,be}
Merged-In: Ib242d348a845f05a56edf45101e1b5d6ed291893
Change-Id: Id9b4fdcc45ac5813832c437cbe0eed4890c27841
(cherry picked from commit 45151b4a)
parent d060e539
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ rust_defaults {
    name: "pdl_defaults",
    // LINT.IfChange
    rustlibs: [
        "libclap",
        "libcodespan_reporting",
        "libheck",
        "libpest",
@@ -18,7 +19,6 @@ rust_defaults {
        "libquote",
        "libserde",
        "libserde_json",
        "libstructopt",
        "libsyn",
        "libtempfile",
    ],
+1 −2
Original line number Diff line number Diff line
@@ -17,8 +17,7 @@ pest_derive = "2.4.0"
proc-macro2 = "1.0.46"
quote = "1.0.21"
serde_json = "1.0.86"
clap = { version = "3.2.22", features = ["derive"] }
structopt = "0.3.26"
clap = "3.2.23"
syn = "1.0.102"

[dependencies.serde]
+32 −8
Original line number Diff line number Diff line
//! PDL parser and analyzer.

use codespan_reporting::term::{self, termcolor};
use structopt::StructOpt;

mod analyzer;
mod ast;
@@ -12,7 +11,7 @@ mod parser;
mod test_utils;
mod utils;

#[derive(Debug)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
enum OutputFormat {
    JSON,
    Rust,
@@ -34,25 +33,50 @@ impl std::str::FromStr for OutputFormat {
    }
}

#[derive(Debug, StructOpt)]
#[structopt(name = "pdl-parser", about = "Packet Description Language parser tool.")]
#[derive(Debug)]
struct Opt {
    /// Print tool version and exit.
    #[structopt(short, long = "--version")]
    version: bool,

    /// Generate output in this format ("json", "rust", "rust_no_alloc", "rust_no_alloc_test"). The output
    /// will be printed on stdout in both cases.
    #[structopt(short, long = "--output-format", name = "FORMAT", default_value = "JSON")]
    output_format: OutputFormat,

    /// Input file.
    #[structopt(name = "FILE")]
    input_file: String,
}

impl Opt {
    fn parse() -> Opt {
        let app = clap::App::new("Packet Description Language parser")
            .version("1.0")
            .arg(
                clap::Arg::with_name("input-file")
                    .value_name("FILE")
                    .help("Input PDL file")
                    .required(true),
            )
            .arg(
                clap::Arg::with_name("output-format")
                    .value_name("FORMAT")
                    .long("output-format")
                    .help("Output file format")
                    .takes_value(true)
                    .default_value("json")
                    .possible_values(&["json", "rust", "rust_no_alloc", "rust_no_alloc_test"]),
            );
        let matches = app.get_matches();

        Opt {
            version: matches.is_present("version"),
            input_file: matches.value_of("input-file").unwrap().into(),
            output_format: matches.value_of("output-format").unwrap().parse().unwrap(),
        }
    }
}

fn main() -> Result<(), String> {
    let opt = Opt::from_args();
    let opt = Opt::parse();

    if opt.version {
        println!("Packet Description Language parser version 1.0");