Skip to content

Commit df6f501

Browse files
committed
Eliminate warnings in the auto-generated device tree
Move the module declaration for the device tree up into `lib.rs` to allow insertion of allow directives to eliminate documentation warnings on the generated devicetree. Signed-off-by: David Brown <[email protected]>
1 parent 86fefec commit df6f501

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

zephyr-build/src/devicetree/output.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ impl DeviceTree {
1818
pub fn to_tokens(&self) -> TokenStream {
1919
let augments = get_augments();
2020

21-
// Root is a little special, as we don't represent the name of the node as it's actual name,
22-
// but as just 'devicetree'.
23-
self.node_walk(self.root.as_ref(), "devicetree", &augments)
21+
// Root is a little special. Since we don't want a module for this (it will be provided
22+
// above where it is included, so it can get documentation and attributes), we use None for
23+
// the name.
24+
self.node_walk(self.root.as_ref(), None, &augments)
2425
}
2526

26-
fn node_walk(&self, node: &Node, name: &str, augments: &[Box<dyn Augment>]) -> TokenStream {
27-
let name_id = dt_to_lower_id(name);
27+
fn node_walk(&self, node: &Node, name: Option<&str>, augments: &[Box<dyn Augment>]) -> TokenStream {
2828
let children = node.children.iter().map(|child| {
29-
self.node_walk(child.as_ref(), &child.name, augments)
29+
self.node_walk(child.as_ref(), Some(&child.name), augments)
3030
});
3131
// Simplistic first pass, turn the properties into constents of the formatted text of the
3232
// property.
@@ -52,12 +52,21 @@ impl DeviceTree {
5252
// If this is compatible with an augment, use the augment to add any additional properties.
5353
let augs = augments.iter().map(|aug| aug.augment(node, self));
5454

55-
quote! {
56-
pub mod #name_id {
57-
pub const ORD: usize = #ord;
55+
if let Some(name) = name {
56+
let name_id = dt_to_lower_id(name);
57+
quote! {
58+
pub mod #name_id {
59+
pub const ORD: usize = #ord;
60+
#(#props)*
61+
#(#children)*
62+
// #parent
63+
#(#augs)*
64+
}
65+
}
66+
} else {
67+
quote! {
5868
#(#props)*
5969
#(#children)*
60-
// #parent
6170
#(#augs)*
6271
}
6372
}

zephyr/src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,21 @@ pub mod kconfig {
4141
include!(concat!(env!("OUT_DIR"), "/kconfig.rs"));
4242
}
4343

44-
// And the generated devicetree.
45-
include!(concat!(env!("OUT_DIR"), "/devicetree.rs"));
44+
pub mod devicetree {
45+
//! Zephyr device tree
46+
//!
47+
//! This is an auto-generated module that represents the device tree for a given build. The
48+
//! hierarchy here should match the device tree, with an additional top-level module "labels"
49+
//! that contains submodules for all of the labels.
50+
//!
51+
//! **Note**: Unless you are viewing docs generated for a specific build, the values below are
52+
//! unlikely to directly correspond to those in a given build.
53+
54+
// Don't enforce doc comments on the generated device tree.
55+
#![allow(missing_docs)]
56+
57+
include!(concat!(env!("OUT_DIR"), "/devicetree.rs"));
58+
}
4659

4760
// Ensure that Rust is enabled.
4861
#[cfg(not(CONFIG_RUST))]

0 commit comments

Comments
 (0)