]> git.proxmox.com Git - perlmod.git/commitdiff
macro: add a write attribute to packages
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 25 Feb 2022 14:45:56 +0000 (15:45 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 25 Feb 2022 14:45:56 +0000 (15:45 +0100)
the .pm file now gets written if either 'write=true' or
'file' is set, setting just 'lib' won't trigger a write
anymore

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
perlmod-macro/src/attribs.rs
perlmod-macro/src/module.rs

index 35e61f96f9bf624207d50ad0f817ebf30fbb51da..1f6edfc1f4adbb3c7ee1c4365fc1736a9602db27 100644 (file)
@@ -7,6 +7,7 @@ pub struct ModuleAttrs {
     pub package_name: String,
     pub file_name: Option<String>,
     pub lib_name: Option<String>,
+    pub write: Option<bool>,
 }
 
 fn is_ident_check_dup<T>(path: &syn::Path, var: &Option<T>, what: &'static str) -> bool {
@@ -27,6 +28,7 @@ impl TryFrom<AttributeArgs> for ModuleAttrs {
         let mut package_name = None;
         let mut file_name = None;
         let mut lib_name = None;
+        let mut write = None;
 
         for arg in args {
             match arg {
@@ -45,6 +47,17 @@ impl TryFrom<AttributeArgs> for ModuleAttrs {
                         error!(path => "unknown argument");
                     }
                 }
+                syn::NestedMeta::Meta(syn::Meta::NameValue(syn::MetaNameValue {
+                    path,
+                    lit: syn::Lit::Bool(litbool),
+                    ..
+                })) => {
+                    if is_ident_check_dup(&path, &write, "write") {
+                        write = Some(litbool.value());
+                    } else {
+                        error!(path => "unknown argument");
+                    }
+                }
                 _ => error!(Span::call_site(), "unexpected attribute argument"),
             }
         }
@@ -56,6 +69,7 @@ impl TryFrom<AttributeArgs> for ModuleAttrs {
             package_name,
             file_name,
             lib_name,
+            write,
         })
     }
 }
index 6df79288c7ffc0b9b11044f0c13a54de648e63f8..9b5843fd8d76d9beaa7637cd92ef9f96eb2bb7d8 100644 (file)
@@ -68,8 +68,8 @@ pub fn handle_module(attr: AttributeArgs, mut module: syn::ItemMod) -> Result<To
         items.push(syn::Item::Verbatim(package.bootstrap_function()));
     }
 
-    if package.attrs.file_name.is_some()
-        || package.attrs.lib_name.is_some()
+    if package.attrs.write == Some(true)
+        || package.attrs.file_name.is_some()
         || std::env::var("PERLMOD_WRITE_PACKAGES").ok().as_deref() == Some("1")
     {
         package.write()?;