Skip to content

Add multiple author support to module! #904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: rust
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/android/rust_binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use {context::Context, thread::Thread};
module! {
type: BinderModule,
name: "rust_binder",
author: "Wedson Almeida Filho",
authors: ["Wedson Almeida Filho"],
description: "Android Binder",
license: "GPL",
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/char/hw_random/bcm2835_rng_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use kernel::{
module_platform_driver! {
type: RngDriver,
name: "bcm2835_rng_rust",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
description: "BCM2835 Random Number Generator (RNG) driver",
license: "GPL v2",
}
Expand Down
8 changes: 8 additions & 0 deletions rust/macros/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ pub(crate) fn try_ident(it: &mut token_stream::IntoIter) -> Option<String> {
}
}

pub(crate) fn try_punct(it: &mut token_stream::IntoIter) -> Option<char> {
if let Some(TokenTree::Punct(punct)) = it.next() {
Some(punct.as_char())
} else {
None
}
}

pub(crate) fn try_literal(it: &mut token_stream::IntoIter) -> Option<String> {
if let Some(TokenTree::Literal(literal)) = it.next() {
Some(literal.to_string())
Expand Down
32 changes: 27 additions & 5 deletions rust/macros/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ struct ModuleInfo {
type_: String,
license: String,
name: String,
author: Option<String>,
authors: Option<Vec<String>>,
description: Option<String>,
alias: Option<String>,
params: Option<Group>,
Expand All @@ -228,7 +228,7 @@ impl ModuleInfo {
const EXPECTED_KEYS: &[&str] = &[
"type",
"name",
"author",
"authors",
"description",
"license",
"alias",
Expand Down Expand Up @@ -257,7 +257,7 @@ impl ModuleInfo {
match key.as_str() {
"type" => info.type_ = expect_ident(it),
"name" => info.name = expect_string_ascii(it),
"author" => info.author = Some(expect_string(it)),
"authors" => info.authors = Some(Self::parse_authors(it)),
"description" => info.description = Some(expect_string(it)),
"license" => info.license = expect_string_ascii(it),
"alias" => info.alias = Some(expect_string_ascii(it)),
Expand Down Expand Up @@ -300,6 +300,26 @@ impl ModuleInfo {

info
}

/// Parse ["First", "Second"] into Some(vec!["First", "Second"])
Copy link
Member

@ojeda ojeda Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Parse ["First", "Second"] into Some(vec!["First", "Second"])
/// Parses `["First", "Second"]` into `Some(vec!["First", "Second"])`.

i.e. please use Markdown, a period at the end, and the third person.

In addition, this does not add Some(...) -- it is the caller that does it, no?

I would reword it like this instead, if you want to give an example:

Suggested change
/// Parse ["First", "Second"] into Some(vec!["First", "Second"])
/// Parses a list of authors.
///
/// # Examples
///
/// Parsing `["First", "Second"]` returns a `vec!["First", "Second"]`.

fn parse_authors(it: &mut token_stream::IntoIter) -> Vec<String> {
let mut authors: Vec<String> = vec![];
let group = expect_group(it);
assert_eq!(group.delimiter(), Delimiter::Bracket);
let mut stream = group.stream().into_iter();
loop {
let author = expect_string(&mut stream);
authors.push(author);
if let Some(punct) = try_punct(&mut stream) {
assert_eq!(punct, ',');
} else {
assert!(stream.next().is_none());
break;
}
}

authors
}
}

pub(crate) fn module(ts: TokenStream) -> TokenStream {
Expand All @@ -308,8 +328,10 @@ 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(author) = info.author {
modinfo.emit("author", &author);
if let Some(authors) = &info.authors {
for author in authors {
modinfo.emit("author", author);
}
}
if let Some(description) = info.description {
modinfo.emit("description", &description);
Expand Down
2 changes: 1 addition & 1 deletion samples/rust/rust_chrdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use kernel::{chrdev, file};
module! {
type: RustChrdev,
name: "rust_chrdev",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
description: "Rust character device sample",
license: "GPL",
}
Expand Down
2 changes: 1 addition & 1 deletion samples/rust/rust_echo_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl kernel::Module for RustEchoServer {
module! {
type: RustEchoServer,
name: "rust_echo_server",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
description: "Rust tcp echo sample",
license: "GPL v2",
}
2 changes: 1 addition & 1 deletion samples/rust/rust_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use kernel::{c_str, fs};
module_fs! {
type: RustFs,
name: "rust_fs",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
license: "GPL",
}

Expand Down
2 changes: 1 addition & 1 deletion samples/rust/rust_minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use kernel::prelude::*;
module! {
type: RustMinimal,
name: "rust_minimal",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
description: "Rust minimal sample",
license: "GPL",
}
Expand Down
2 changes: 1 addition & 1 deletion samples/rust/rust_miscdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use kernel::{
module! {
type: RustMiscdev,
name: "rust_miscdev",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
description: "Rust miscellaneous device sample",
license: "GPL",
}
Expand Down
2 changes: 1 addition & 1 deletion samples/rust/rust_module_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use kernel::prelude::*;
module! {
type: RustModuleParameters,
name: "rust_module_parameters",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
description: "Rust module parameters sample",
license: "GPL",
params: {
Expand Down
2 changes: 1 addition & 1 deletion samples/rust/rust_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use kernel::{pr_cont, str::CStr, ThisModule};
module! {
type: RustPrint,
name: "rust_print",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
description: "Rust printing macros sample",
license: "GPL",
}
Expand Down
2 changes: 1 addition & 1 deletion samples/rust/rust_random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use kernel::{
module_misc_device! {
type: RandomFile,
name: "rust_random",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
description: "Just use /dev/urandom: Now with early-boot safety",
license: "GPL",
}
Expand Down
2 changes: 1 addition & 1 deletion samples/rust/rust_selftests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use kernel::prelude::*;
module! {
type: RustSelftests,
name: "rust_selftests",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
description: "Self test cases for Rust",
license: "GPL",
}
Expand Down
2 changes: 1 addition & 1 deletion samples/rust/rust_semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use kernel::{
module! {
type: RustSemaphore,
name: "rust_semaphore",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
description: "Rust semaphore sample",
license: "GPL",
}
Expand Down
2 changes: 1 addition & 1 deletion samples/rust/rust_stack_probing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use kernel::prelude::*;
module! {
type: RustStackProbing,
name: "rust_stack_probing",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
description: "Rust stack probing sample",
license: "GPL",
}
Expand Down
2 changes: 1 addition & 1 deletion samples/rust/rust_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use kernel::{
module! {
type: RustSync,
name: "rust_sync",
author: "Rust for Linux Contributors",
authors: ["Rust for Linux Contributors"],
description: "Rust synchronisation primitives sample",
license: "GPL",
}
Expand Down