Allow construct_runtime to take cfg attributes for pallets (#11818)

* Allow construct_runtime to take cfg attributes for pallets

* cargo fmt

* Remove commented out code

* Fixes

* cargo fmt

* Remove inaccurate comments

* Fix typo

* Properly reverse pallets

* Fixes

* cargo fmt

* Add missing newlines
This commit is contained in:
Keith Yeung
2022-08-25 16:56:18 +08:00
committed by GitHub
parent edc8f7b409
commit 948af11977
20 changed files with 480 additions and 85 deletions
@@ -0,0 +1,14 @@
use frame_support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
#[cfg(test)]
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: `System` pallet declaration is feature gated, please remove any `#[cfg]` attributes
--> tests/construct_runtime_ui/feature_gated_system_pallet.rs:10:3
|
10 | System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^
@@ -0,0 +1,15 @@
use frame_support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet},
#[cfg(feature = 1)]
Balance: balances::{Config, Call},
}
}
fn main() {}
@@ -0,0 +1,6 @@
error: feature = 1
^ expected one of `<key>`, `all`, `any`, `not` here
--> tests/construct_runtime_ui/invalid_meta_literal.rs:10:3
|
10 | #[cfg(feature = 1)]
| ^
@@ -0,0 +1,15 @@
use frame_support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet},
#[cfg(feature(test))]
Balance: balances::{Config, Call},
}
}
fn main() {}
@@ -0,0 +1,6 @@
error: feature(test)
^ expected one of `=`, `,`, `)` here
--> tests/construct_runtime_ui/unsupported_meta_structure.rs:10:3
|
10 | #[cfg(feature(test))]
| ^
@@ -0,0 +1,15 @@
use frame_support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet},
#[attr]
Balance: balances::{Config, Call},
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: Unsupported attribute, only #[cfg] is supported on pallet declarations in `construct_runtime`
--> tests/construct_runtime_ui/unsupported_pallet_attr.rs:10:3
|
10 | #[attr]
| ^
@@ -626,6 +626,8 @@ frame_support::construct_runtime!(
System: frame_system exclude_parts { Pallet, Storage },
Example: pallet,
Example2: pallet2 exclude_parts { Call },
#[cfg(feature = "example3")]
Example3: pallet3,
Example4: pallet4 use_parts { Call },
}
);