public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [PATCH] rust: macros: add authors
@ 2024-12-06 19:22 guilherme giacomo simoes
  2024-12-06 20:17 ` Miguel Ojeda
  2024-12-09  3:59 ` [PATCH] " kernel test robot
  0 siblings, 2 replies; 13+ messages in thread
From: guilherme giacomo simoes @ 2024-12-06 19:22 UTC (permalink / raw)
  To: ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, benno.lossin,
	a.hindborg, aliceryhl, tmgross, walmeida, fujita.tomonori,
	tahbertschinger
  Cc: guilherme giacomo simoes, rust-for-linux, linux-kernel

The module is only accepted to have a single author. If the module needs
more than one author, you cannot define this in the module creating
flow.
Add another key in the module stream that accepts a string array with
authors.
Author and authors keys cannot coexist, so add a check that if the
module authors addss these two keys, throw a panic!

Signed-off-by: guilherme giacomo simoes <trintaeoitogc@gmail.com>
---
 rust/macros/module.rs | 43 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index 2587f41b0d39..a6965354824f 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -83,6 +83,12 @@ fn emit_only_loadable(&mut self, field: &str, content: &str) {
         self.emit_base(field, content, false)
     }
 
+    fn emit_arr_str(&mut self, field: &str, arr_content: &Vec<String>) {
+        for content in arr_content {
+            self.emit(field, content);
+        }
+    }
+
     fn emit(&mut self, field: &str, content: &str) {
         self.emit_only_builtin(field, content);
         self.emit_only_loadable(field, content);
@@ -95,12 +101,30 @@ struct ModuleInfo {
     license: String,
     name: String,
     author: Option<String>,
+    authors: Option<Vec<String>>,
     description: Option<String>,
     alias: Option<Vec<String>>,
     firmware: Option<Vec<String>>,
 }
 
 impl ModuleInfo {
+    fn coexist(arr: &mut Vec<String>, cannot_coexist: &[&str]) -> bool {
+        let mut found: bool = false;
+
+        for cc in cannot_coexist {
+
+            for key in &mut *arr {
+                if cc == key {
+                    if found {
+                        return true;
+                    }
+                    found = true;
+                }
+            }
+        }
+        return false;
+    }
+
     fn parse(it: &mut token_stream::IntoIter) -> Self {
         let mut info = ModuleInfo::default();
 
@@ -108,6 +132,7 @@ fn parse(it: &mut token_stream::IntoIter) -> Self {
             "type",
             "name",
             "author",
+            "authors",
             "description",
             "license",
             "alias",
@@ -136,6 +161,7 @@ fn parse(it: &mut token_stream::IntoIter) -> Self {
                 "type" => info.type_ = expect_ident(it),
                 "name" => info.name = expect_string_ascii(it),
                 "author" => info.author = Some(expect_string(it)),
+                "authors" => info.authors = Some(expect_string_array(it)),
                 "description" => info.description = Some(expect_string(it)),
                 "license" => info.license = expect_string_ascii(it),
                 "alias" => info.alias = Some(expect_string_array(it)),
@@ -153,6 +179,16 @@ fn parse(it: &mut token_stream::IntoIter) -> Self {
 
         expect_end(it);
 
+        const CANNOT_COEXIST: &[&[&str]] = &[
+            &["author", "authors"]
+        ];
+
+        for cannot_coexist in CANNOT_COEXIST {
+            if Self::coexist(&mut seen_keys, cannot_coexist) {
+                panic!("keys {:?} coexist", cannot_coexist);
+            }
+        }
+
         for key in REQUIRED_KEYS {
             if !seen_keys.iter().any(|e| e == key) {
                 panic!("Missing required key \"{}\".", key);
@@ -183,6 +219,9 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
     let info = ModuleInfo::parse(&mut it);
 
     let mut modinfo = ModInfoBuilder::new(info.name.as_ref());
+    if let Some(authors) = info.authors {
+        modinfo.emit_arr_str("author", &authors);
+    }
     if let Some(author) = info.author {
         modinfo.emit("author", &author);
     }
@@ -191,9 +230,7 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
     }
     modinfo.emit("license", &info.license);
     if let Some(aliases) = info.alias {
-        for alias in aliases {
-            modinfo.emit("alias", &alias);
-        }
+        modinfo.emit_arr_str("alias", &aliases);
     }
     if let Some(firmware) = info.firmware {
         for fw in firmware {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-12-09 13:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-06 19:22 [PATCH] [PATCH] rust: macros: add authors guilherme giacomo simoes
2024-12-06 20:17 ` Miguel Ojeda
2024-12-06 21:19   ` guilherme giacomo simoes
2024-12-06 22:42     ` Miguel Ojeda
2024-12-07  1:47   ` guilherme giacomo simoes
2024-12-07 10:14   ` [PATCH] " Daniel Sedlak
2024-12-07 16:07     ` guilherme giacomo simoes
2024-12-09 12:21       ` Daniel Sedlak
2024-12-09 11:47     ` [PATCH] " Miguel Ojeda
2024-12-09 12:29       ` Daniel Sedlak
2024-12-09 13:14         ` guilherme giacomo simoes
2024-12-09 12:55       ` guilherme giacomo simoes
2024-12-09  3:59 ` [PATCH] " kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox