From: guilherme giacomo simoes <trintaeoitogc@gmail.com>
To: ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com,
gary@garyguo.net, bjorn3_gh@protonmail.com,
benno.lossin@proton.me, a.hindborg@kernel.org,
aliceryhl@google.com, tmgross@umich.edu, walmeida@microsoft.com,
fujita.tomonori@gmail.com, tahbertschinger@gmail.com
Cc: guilherme giacomo simoes <trintaeoitogc@gmail.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] [PATCH] rust: macros: add authors
Date: Fri, 6 Dec 2024 16:22:44 -0300 [thread overview]
Message-ID: <20241206192244.443486-1-trintaeoitogc@gmail.com> (raw)
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
next reply other threads:[~2024-12-06 19:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-06 19:22 guilherme giacomo simoes [this message]
2024-12-06 20:17 ` [PATCH] [PATCH] rust: macros: add authors 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241206192244.443486-1-trintaeoitogc@gmail.com \
--to=trintaeoitogc@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tahbertschinger@gmail.com \
--cc=tmgross@umich.edu \
--cc=walmeida@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox