Add feature: no-metadata-doc which removes doc from metadata and full-metadata which build metadata with all doc (#10493)

* add features to remove or add doc

* fmt

* add test for event/error/call

* fmt
This commit is contained in:
Guillaume Thiolliere
2022-01-18 06:21:19 +09:00
committed by GitHub
parent 2a122c44b1
commit 137628b4d7
17 changed files with 76 additions and 16 deletions
+25 -7
View File
@@ -1100,6 +1100,14 @@ fn migrate_from_pallet_version_to_storage_version() {
fn metadata() {
use frame_support::metadata::*;
fn maybe_docs(doc: Vec<&'static str>) -> Vec<&'static str> {
if cfg!(feature = "no-metadata-docs") {
vec![]
} else {
doc
}
}
let pallets = vec![
PalletMetadata {
index: 1,
@@ -1269,7 +1277,7 @@ fn metadata() {
modifier: StorageEntryModifier::Default,
ty: StorageEntryType::Plain(meta_type::<u32>()),
default: vec![0, 0, 0, 0],
docs: vec!["Counter for the related counted storage map"],
docs: maybe_docs(vec!["Counter for the related counted storage map"]),
},
StorageEntryMetadata {
name: "Unbounded",
@@ -1287,13 +1295,13 @@ fn metadata() {
name: "MyGetParam",
ty: meta_type::<u32>(),
value: vec![10, 0, 0, 0],
docs: vec![" Some comment", " Some comment"],
docs: maybe_docs(vec![" Some comment", " Some comment"]),
},
PalletConstantMetadata {
name: "MyGetParam2",
ty: meta_type::<u32>(),
value: vec![11, 0, 0, 0],
docs: vec![" Some comment", " Some comment"],
docs: maybe_docs(vec![" Some comment", " Some comment"]),
},
PalletConstantMetadata {
name: "MyGetParam3",
@@ -1305,19 +1313,19 @@ fn metadata() {
name: "some_extra",
ty: meta_type::<u64>(),
value: vec![100, 0, 0, 0, 0, 0, 0, 0],
docs: vec![" Some doc", " Some doc"],
docs: maybe_docs(vec![" Some doc", " Some doc"]),
},
PalletConstantMetadata {
name: "some_extra_extra",
ty: meta_type::<u64>(),
value: vec![0, 0, 0, 0, 0, 0, 0, 0],
docs: vec![" Some doc"],
docs: maybe_docs(vec![" Some doc"]),
},
PalletConstantMetadata {
name: "SomeExtraRename",
ty: meta_type::<u64>(),
value: vec![0, 0, 0, 0, 0, 0, 0, 0],
docs: vec![" Some doc"],
docs: maybe_docs(vec![" Some doc"]),
},
],
error: Some(PalletErrorMetadata { ty: meta_type::<pallet::Error<Runtime>>() }),
@@ -1351,7 +1359,7 @@ fn metadata() {
modifier: StorageEntryModifier::Default,
ty: StorageEntryType::Plain(meta_type::<u32>()),
default: vec![0, 0, 0, 0],
docs: vec!["Counter for the related counted storage map"],
docs: maybe_docs(vec!["Counter for the related counted storage map"]),
},
],
}),
@@ -1362,6 +1370,16 @@ fn metadata() {
},
];
let empty_doc = pallets[0].event.as_ref().unwrap().ty.type_info().docs().is_empty() &&
pallets[0].error.as_ref().unwrap().ty.type_info().docs().is_empty() &&
pallets[0].calls.as_ref().unwrap().ty.type_info().docs().is_empty();
if cfg!(feature = "no-metadata-docs") {
assert!(empty_doc)
} else {
assert!(!empty_doc)
}
let extrinsic = ExtrinsicMetadata {
ty: meta_type::<UncheckedExtrinsic>(),
version: 4,
@@ -15,6 +15,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Old macros don't support the flag `no-metadata-docs` so the result differs when the feature is
// activated.
#![cfg(not(feature = "no-metadata-docs"))]
use frame_support::traits::{ConstU32, ConstU64};
pub trait SomeAssociation {
@@ -15,6 +15,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Old macros don't support the flag `no-metadata-docs` so the result differs when the feature is
// activated.
#![cfg(not(feature = "no-metadata-docs"))]
use frame_support::traits::{ConstU32, ConstU64};
mod pallet_old {