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

Commit 489fd509 authored by Archie Pusaka's avatar Archie Pusaka Committed by Archie Pusaka
Browse files

floss: dbus_projection: Allow other attributes on top of dbus_method

The current logic in dbus_projection is very strict when checking for
the dbus_method attribute, specifically it doesn't allow other
attributes at all. This might come as surprising because even an
unsuspecting function comment actually counts as an attribute. When
parsing failure occurs, the macro treats as if it's not a dbus function
so no error is reported.

Change the logic to allow multiple attributes. For now those
attributes are ignored - if more support is required one needs to add
their own implementation still.

Bug: 371534263
Test: m -j
Test: btclient advertise on, verify doesn't crash
Flag: EXEMPT, floss-only change

Change-Id: I26d2595b0c536a2dbd0ae505f6234f881e2199f7
parent 94cfdf46
Loading
Loading
Loading
Loading
+40 −29
Original line number Diff line number Diff line
@@ -125,16 +125,21 @@ pub fn generate_dbus_exporter(attr: TokenStream, item: TokenStream) -> TokenStre

    for item in ast.items {
        if let ImplItem::Method(method) = item {
            if method.attrs.len() != 1 {
                continue;
            // Find the #[dbus_method] attribute
            let mut dbus_method_attr = None;
            for attr in &method.attrs {
                if attr.path.get_ident().unwrap().to_string().eq("dbus_method") {
                    dbus_method_attr = Some(attr);
                    break;
                }
            }

            let attr = &method.attrs[0];
            if !attr.path.get_ident().unwrap().to_string().eq("dbus_method") {
            // Skip the method is not marked with #[dbus_method].
            if dbus_method_attr.is_none() {
                continue;
            }

            let meta_list = match attr.parse_meta().unwrap() {
            let meta_list = match dbus_method_attr.unwrap().parse_meta().unwrap() {
                Meta::List(meta_list) => meta_list,
                _ => continue,
            };
@@ -333,9 +338,17 @@ pub fn generate_dbus_interface_client(attr: TokenStream, item: TokenStream) -> T
    // Iterate on every methods of a trait impl
    for item in ast.items {
        if let ImplItem::Method(method) = item {
            // If the method is not marked with #[dbus_method], just copy the
            // original method body.
            if method.attrs.len() != 1 {
            // Find the #[dbus_method] attribute
            let mut dbus_method_attr = None;
            for attr in &method.attrs {
                if attr.path.get_ident().unwrap().to_string().eq("dbus_method") {
                    dbus_method_attr = Some(attr);
                    break;
                }
            }

            // If the method is not marked with #[dbus_method], just copy the original method body.
            if dbus_method_attr.is_none() {
                methods = quote! {
                    #methods

@@ -344,15 +357,9 @@ pub fn generate_dbus_interface_client(attr: TokenStream, item: TokenStream) -> T
                continue;
            }

            let attr = &method.attrs[0];
            if !attr.path.get_ident().unwrap().to_string().eq("dbus_method") {
                continue;
            }

            let sig = &method.sig;

            // For RPC-friendly method, copy the original signature but add public, async, and wrap
            // the return with Result.
            let sig = &method.sig;
            let mut rpc_sig = sig.clone();
            rpc_sig.asyncness = Some(<syn::Token![async]>::default());
            rpc_sig.output = match rpc_sig.output {
@@ -367,7 +374,8 @@ pub fn generate_dbus_interface_client(attr: TokenStream, item: TokenStream) -> T
                pub #rpc_sig
            };

            let dbus_method_name = if let Meta::List(meta_list) = attr.parse_meta().unwrap() {
            let dbus_method_name =
                if let Meta::List(meta_list) = dbus_method_attr.unwrap().parse_meta().unwrap() {
                    Some(meta_list.nested[0].clone())
                } else {
                    None
@@ -769,9 +777,17 @@ pub fn dbus_proxy_obj(attr: TokenStream, item: TokenStream) -> TokenStream {

    for item in ast.items {
        if let ImplItem::Method(method) = item {
            // If the method is not marked with #[dbus_method], just copy the
            // original method body.
            if method.attrs.len() != 1 {
            // Find the #[dbus_method] attribute
            let mut dbus_method_attr = None;
            for attr in &method.attrs {
                if attr.path.get_ident().unwrap().to_string().eq("dbus_method") {
                    dbus_method_attr = Some(attr);
                    break;
                }
            }

            // If the method is not marked with #[dbus_method], just copy the original method body.
            if dbus_method_attr.is_none() {
                method_impls = quote! {
                    #method_impls
                    #method
@@ -779,12 +795,7 @@ pub fn dbus_proxy_obj(attr: TokenStream, item: TokenStream) -> TokenStream {
                continue;
            }

            let attr = &method.attrs[0];
            if !attr.path.get_ident().unwrap().to_string().eq("dbus_method") {
                continue;
            }

            let meta_list = match attr.parse_meta().unwrap() {
            let meta_list = match dbus_method_attr.unwrap().parse_meta().unwrap() {
                Meta::List(meta_list) => meta_list,
                _ => continue,
            };