Improvements in minimal template (#4119)

This PR makes a few improvements in the docs for the minimal template.

---------

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
gupnik
2024-04-30 11:09:08 +05:30
committed by GitHub
parent 1fb058b791
commit 31dc8bb1de
13 changed files with 208 additions and 19 deletions
@@ -66,6 +66,7 @@ pub fn expand_outer_dispatch(
quote! {
#( #query_call_part_macros )*
/// The aggregated runtime call type.
#[derive(
Clone, PartialEq, Eq,
#scrate::__private::codec::Encode,
@@ -533,6 +533,7 @@ pub(crate) fn decl_all_pallets<'a>(
for pallet_declaration in pallet_declarations {
let type_name = &pallet_declaration.name;
let pallet = &pallet_declaration.path;
let docs = &pallet_declaration.docs;
let mut generics = vec![quote!(#runtime)];
generics.extend(pallet_declaration.instance.iter().map(|name| quote!(#pallet::#name)));
let mut attrs = Vec::new();
@@ -541,6 +542,7 @@ pub(crate) fn decl_all_pallets<'a>(
attrs.extend(TokenStream2::from_str(&feat).expect("was parsed successfully; qed"));
}
let type_decl = quote!(
#( #[doc = #docs] )*
#(#attrs)*
pub type #type_name = #pallet::Pallet <#(#generics),*>;
);
@@ -605,6 +605,8 @@ pub struct Pallet {
pub pallet_parts: Vec<PalletPart>,
/// Expressions specified inside of a #[cfg] attribute.
pub cfg_pattern: Vec<cfg_expr::Expression>,
/// The doc literals
pub docs: Vec<syn::Expr>,
}
impl Pallet {
@@ -774,6 +776,7 @@ fn convert_pallets(pallets: Vec<PalletDeclaration>) -> syn::Result<PalletsConver
instance: pallet.instance,
cfg_pattern,
pallet_parts,
docs: vec![],
})
})
.collect::<Result<Vec<_>>>()?;
@@ -198,9 +198,9 @@ pub fn expand_tt_default_parts(def: &mut Def) -> proc_macro2::TokenStream {
macro_rules! #default_parts_unique_id_v2 {
{
$caller:tt
frame_support = [{ $($frame_support:ident)::* }]
your_tt_return = [{ $my_tt_return:path }]
} => {
$($frame_support)*::__private::tt_return! {
$my_tt_return! {
$caller
tokens = [{
+ Pallet #call_part_v2 #storage_part_v2 #event_part_v2 #error_part_v2 #origin_part_v2 #config_part_v2
@@ -93,7 +93,7 @@ fn construct_runtime_implicit_to_explicit(
let frame_support = generate_access_from_frame_or_crate("frame-support")?;
let attr = if legacy_ordering { quote!((legacy_ordering)) } else { quote!() };
let mut expansion = quote::quote!(
#[frame_support::runtime #attr]
#[#frame_support::runtime #attr]
#input
);
for pallet in definition.pallet_decls.iter() {
@@ -103,7 +103,7 @@ fn construct_runtime_implicit_to_explicit(
expansion = quote::quote!(
#frame_support::__private::tt_call! {
macro = [{ #pallet_path::tt_default_parts_v2 }]
frame_support = [{ #frame_support }]
your_tt_return = [{ #frame_support::__private::tt_return }]
~~> #frame_support::match_and_insert! {
target = [{ #expansion }]
pattern = [{ #pallet_name = #pallet_path #pallet_instance }]
@@ -16,6 +16,7 @@
// limitations under the License.
use crate::construct_runtime::parse::{Pallet, PalletPart, PalletPartKeyword, PalletPath};
use frame_support_procedural_tools::get_doc_literals;
use quote::ToTokens;
use syn::{punctuated::Punctuated, spanned::Spanned, token, Error, Ident, PathArguments};
@@ -86,6 +87,8 @@ impl Pallet {
let cfg_pattern = vec![];
let docs = get_doc_literals(&item.attrs);
Ok(Pallet {
is_expanded: true,
name,
@@ -94,6 +97,7 @@ impl Pallet {
instance,
cfg_pattern,
pallet_parts,
docs,
})
}
}
@@ -21,13 +21,14 @@ use syn::{spanned::Spanned, Attribute, Ident, PathArguments};
/// The declaration of a pallet.
#[derive(Debug, Clone)]
pub struct PalletDeclaration {
/// The name of the pallet, e.g.`System` in `System: frame_system`.
/// The name of the pallet, e.g.`System` in `pub type System = frame_system`.
pub name: Ident,
/// Optional attributes tagged right above a pallet declaration.
pub attrs: Vec<Attribute>,
/// The path of the pallet, e.g. `frame_system` in `System: frame_system`.
/// The path of the pallet, e.g. `frame_system` in `pub type System = frame_system`.
pub path: syn::Path,
/// The instance of the pallet, e.g. `Instance1` in `Council: pallet_collective::<Instance1>`.
/// The instance of the pallet, e.g. `Instance1` in `pub type Council =
/// pallet_collective<Instance1>`.
pub instance: Option<Ident>,
}