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

Commit 61dc8dc9 authored by Martin Geisler's avatar Martin Geisler
Browse files

pdl: Re-enable rustc errors for generated code

The generated code has rustc warnings: lots of warnings about wrong
camel-cased types, warnings about too many parenthesis, etc. We can
probably not fix all warnings, so we should suppress them.

Before, we suppressed the warnings by configuring Soong

    lints: "none",

which makes it pass something like "-A warnings -A deny“ to rustc.

This has the bad side effect of disabling all lints, not just
warnings. In particular, it disabled the overflowing_literals lint,
which is a deny-by-default lint which we very much want to keep
enabled.

To fix this, we now emit the desired lint settings in the generated
code. This makes it easier for people who use pdl: they can simply
compile the code like any other piece of Rust code.

Test: atest pdl_rust_generator_tests_{le,be} pdl_tests
Change-Id: I29e32a1350fea04e88cbd595e6ea7663c8d70679
parent f49babb7
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -96,8 +96,6 @@ rust_defaults {
        "libthiserror",
    ],
    proc_macros: ["libnum_derive"],
    clippy_lints: "none",
    lints: "none",
}

rust_library_host {
@@ -159,8 +157,6 @@ rust_test_host {
        "libnum_traits",
        "libpdl_le_backend",
    ],
    clippy_lints: "none",
    lints: "none",
}

rust_test_host {
@@ -171,8 +167,6 @@ rust_test_host {
        "libnum_traits",
        "libpdl_be_backend",
    ],
    clippy_lints: "none",
    lints: "none",
}

// Defaults for PDL python backend generation.
+3 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ pub fn generate(path: &Path) -> String {
    let filename = path.file_name().unwrap().to_str().expect("non UTF-8 filename");
    code.push_str(&format!("// @generated rust packets from {filename}\n\n"));

    // TODO(mgeisler): make the generated code clean from warnings.
    code.push_str("#![allow(warnings, missing_docs)]\n\n");

    code.push_str(&quote_block! {
        use bytes::{BufMut, Bytes, BytesMut};
        use num_derive::{FromPrimitive, ToPrimitive};
+11 −6
Original line number Diff line number Diff line
@@ -116,13 +116,18 @@ fn generate_unit_tests(input: &str, packet_names: &[&str], module_name: &str) {
        }
    }

    let code = quote! {
    // TODO(mgeisler): make the generated code clean from warnings.
    println!("#![allow(warnings, missing_docs)]");
    println!();
    println!(
        "{}",
        &quote! {
            use #module::Packet;
            use num_traits::{FromPrimitive, ToPrimitive};

            #(#tests)*
    };
    println!("{code}");
        }
    );
}

fn main() {
+2 −0
Original line number Diff line number Diff line
// @generated rust packets from foo.pdl

#![allow(warnings, missing_docs)]

use bytes::{BufMut, Bytes, BytesMut};
use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::{FromPrimitive, ToPrimitive};