mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 02:17:58 +00:00
Emit error when Config part is imported but without the std feature (#9225)
* Emit error when Config part is imported but without the std feature * Add UI test for missing std feature on GenesisConfig * Update frame/support/test/Cargo.toml Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Remove unused imports * Unify all dummy party checker macros * Fix * Dispaly pallet_path::GenesisConfig instead of PalletConfig in error message * Revert changes to construct_runtime_ui.rs * Add additional parameter for dummy part checker macro * Apply suggestions from code review * fix master merge: update version * update Cargo.lock Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
use crate::construct_runtime::Pallet;
|
||||
use inflector::Inflector;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
use quote::{ToTokens, format_ident, quote};
|
||||
use syn::Ident;
|
||||
|
||||
pub fn expand_outer_config(
|
||||
@@ -35,6 +35,7 @@ pub fn expand_outer_config(
|
||||
if let Some(pallet_entry) = decl.find_part("Config") {
|
||||
let path = &decl.path;
|
||||
let pallet_name = &decl.name;
|
||||
let path_str = path.into_token_stream().to_string();
|
||||
let config = format_ident!("{}Config", pallet_name);
|
||||
let field_name = &Ident::new(
|
||||
&pallet_name.to_string().to_snake_case(),
|
||||
@@ -47,6 +48,8 @@ pub fn expand_outer_config(
|
||||
build_storage_calls.extend(expand_config_build_storage_call(scrate, runtime, decl, &field_name));
|
||||
query_genesis_config_part_macros.push(quote! {
|
||||
#path::__substrate_genesis_config_check::is_genesis_config_defined!(#pallet_name);
|
||||
#[cfg(feature = "std")]
|
||||
#path::__substrate_genesis_config_check::is_std_enabled_for_genesis!(#pallet_name, #path_str);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,96 +9,54 @@ pub fn generate_dummy_part_checker(input: TokenStream) -> TokenStream {
|
||||
|
||||
let count = COUNTER.with(|counter| counter.borrow_mut().inc());
|
||||
|
||||
let genesis_config_macro_ident = syn::Ident::new(
|
||||
&format!("__is_genesis_config_defined_{}", count),
|
||||
proc_macro2::Span::call_site(),
|
||||
);
|
||||
let event_macro_ident = syn::Ident::new(
|
||||
&format!("__is_event_part_defined_{}", count),
|
||||
proc_macro2::Span::call_site(),
|
||||
);
|
||||
let inherent_macro_ident = syn::Ident::new(
|
||||
&format!("__is_inherent_part_defined_{}", count),
|
||||
proc_macro2::Span::call_site(),
|
||||
);
|
||||
let validate_unsigned_macro_ident = syn::Ident::new(
|
||||
&format!("__is_validate_unsigned_part_defined_{}", count),
|
||||
proc_macro2::Span::call_site(),
|
||||
);
|
||||
let call_macro_ident = syn::Ident::new(
|
||||
&format!("__is_call_part_defined_{}", count),
|
||||
proc_macro2::Span::call_site(),
|
||||
);
|
||||
let origin_macro_ident = syn::Ident::new(
|
||||
&format!("__is_origin_part_defined_{}", count),
|
||||
let no_op_macro_ident = syn::Ident::new(
|
||||
&format!("__dummy_part_checker_{}", count),
|
||||
proc_macro2::Span::call_site(),
|
||||
);
|
||||
|
||||
quote::quote!(
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! #no_op_macro_ident {
|
||||
( $( $tt:tt )* ) => {};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __substrate_genesis_config_check {
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! #genesis_config_macro_ident {
|
||||
($pallet_name:ident) => {};
|
||||
}
|
||||
pub use #no_op_macro_ident as is_genesis_config_defined;
|
||||
#[doc(hidden)]
|
||||
pub use #genesis_config_macro_ident as is_genesis_config_defined;
|
||||
pub use #no_op_macro_ident as is_std_enabled_for_genesis;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __substrate_event_check {
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! #event_macro_ident {
|
||||
($pallet_name:ident) => {};
|
||||
}
|
||||
#[doc(hidden)]
|
||||
pub use #event_macro_ident as is_event_part_defined;
|
||||
pub use #no_op_macro_ident as is_event_part_defined;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __substrate_inherent_check {
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! #inherent_macro_ident {
|
||||
($pallet_name:ident) => {};
|
||||
}
|
||||
#[doc(hidden)]
|
||||
pub use #inherent_macro_ident as is_inherent_part_defined;
|
||||
pub use #no_op_macro_ident as is_inherent_part_defined;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __substrate_validate_unsigned_check {
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! #validate_unsigned_macro_ident {
|
||||
($pallet_name:ident) => {};
|
||||
}
|
||||
#[doc(hidden)]
|
||||
pub use #validate_unsigned_macro_ident as is_validate_unsigned_part_defined;
|
||||
pub use #no_op_macro_ident as is_validate_unsigned_part_defined;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __substrate_call_check {
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! #call_macro_ident {
|
||||
($pallet_name:ident) => {};
|
||||
}
|
||||
#[doc(hidden)]
|
||||
pub use #call_macro_ident as is_call_part_defined;
|
||||
pub use #no_op_macro_ident as is_call_part_defined;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __substrate_origin_check {
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! #origin_macro_ident {
|
||||
($pallet_name:ident) => {};
|
||||
}
|
||||
#[doc(hidden)]
|
||||
pub use #origin_macro_ident as is_origin_part_defined;
|
||||
pub use #no_op_macro_ident as is_origin_part_defined;
|
||||
}
|
||||
).into()
|
||||
}
|
||||
|
||||
@@ -23,39 +23,60 @@ use syn::{Ident, spanned::Spanned};
|
||||
pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
let count = COUNTER.with(|counter| counter.borrow_mut().inc());
|
||||
|
||||
let (genesis_config, macro_ident) = if let Some(genesis_config) = &def.genesis_config {
|
||||
let ident = Ident::new(
|
||||
&format!("__is_genesis_config_defined_{}", count),
|
||||
genesis_config.genesis_config.span(),
|
||||
);
|
||||
(genesis_config, ident)
|
||||
} else {
|
||||
let macro_ident = Ident::new(
|
||||
&format!("__is_genesis_config_defined_{}", count),
|
||||
def.item.span(),
|
||||
);
|
||||
let (genesis_config, def_macro_ident, std_macro_ident) =
|
||||
if let Some(genesis_config) = &def.genesis_config {
|
||||
let def_macro_ident = Ident::new(
|
||||
&format!("__is_genesis_config_defined_{}", count),
|
||||
genesis_config.genesis_config.span(),
|
||||
);
|
||||
|
||||
return quote::quote! {
|
||||
#[doc(hidden)]
|
||||
pub mod __substrate_genesis_config_check {
|
||||
#[macro_export]
|
||||
let std_macro_ident = Ident::new(
|
||||
&format!("__is_std_macro_defined_for_genesis_{}", count),
|
||||
genesis_config.genesis_config.span(),
|
||||
);
|
||||
|
||||
(genesis_config, def_macro_ident, std_macro_ident)
|
||||
} else {
|
||||
let def_macro_ident = Ident::new(
|
||||
&format!("__is_genesis_config_defined_{}", count),
|
||||
def.item.span(),
|
||||
);
|
||||
|
||||
let std_macro_ident = Ident::new(
|
||||
&format!("__is_std_enabled_for_genesis_{}", count),
|
||||
def.item.span(),
|
||||
);
|
||||
|
||||
return quote::quote! {
|
||||
#[doc(hidden)]
|
||||
macro_rules! #macro_ident {
|
||||
($pallet_name:ident) => {
|
||||
compile_error!(concat!(
|
||||
"`",
|
||||
stringify!($pallet_name),
|
||||
"` does not have #[pallet::genesis_config] defined, perhaps you should \
|
||||
remove `Config` from construct_runtime?",
|
||||
));
|
||||
pub mod __substrate_genesis_config_check {
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! #def_macro_ident {
|
||||
($pallet_name:ident) => {
|
||||
compile_error!(concat!(
|
||||
"`",
|
||||
stringify!($pallet_name),
|
||||
"` does not have #[pallet::genesis_config] defined, perhaps you should \
|
||||
remove `Config` from construct_runtime?",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! #std_macro_ident {
|
||||
($pallet_name:ident, $pallet_path:expr) => {};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use #def_macro_ident as is_genesis_config_defined;
|
||||
#[doc(hidden)]
|
||||
pub use #std_macro_ident as is_std_enabled_for_genesis;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use #macro_ident as is_genesis_config_defined;
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
let frame_support = &def.frame_support;
|
||||
|
||||
let genesis_config_item = &mut def.item.content.as_mut()
|
||||
@@ -94,12 +115,36 @@ pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
pub mod __substrate_genesis_config_check {
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! #macro_ident {
|
||||
macro_rules! #def_macro_ident {
|
||||
($pallet_name:ident) => {};
|
||||
}
|
||||
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
pub use #macro_ident as is_genesis_config_defined;
|
||||
macro_rules! #std_macro_ident {
|
||||
($pallet_name:ident, $pallet_path:expr) => {
|
||||
compile_error!(concat!(
|
||||
"`",
|
||||
stringify!($pallet_name),
|
||||
"` does not have the std feature enabled, this will cause the `",
|
||||
$pallet_path,
|
||||
"::GenesisConfig` type to be undefined."
|
||||
));
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! #std_macro_ident {
|
||||
($pallet_name:ident, $pallet_path:expr) => {};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use #def_macro_ident as is_genesis_config_defined;
|
||||
#[doc(hidden)]
|
||||
pub use #std_macro_ident as is_std_enabled_for_genesis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user