codegen: Opt out of documentation (#843)

* codegen: Opt-out for API documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Add `--no-docs` flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests: Check no documentation was generated

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update cargo.lock

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests: Adjust testing for the new codegen API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* macro: Ensure `subxt` macro does not contain documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* macro: Expose documentation flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* expose_documentation => generate_docs

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: James Wilson <james@jsdw.me>
This commit is contained in:
Alexandru Vasile
2023-03-02 21:35:02 +02:00
committed by GitHub
parent 1c5faf3f8f
commit 5320ca9d55
13 changed files with 244 additions and 93 deletions
+18
View File
@@ -79,9 +79,22 @@
//!
//! ```ignore
//! #[subxt::subxt(crate = "crate::path::to::subxt")]
//! pub mod polkadot {}
//! ```
//!
//! By default the path `::subxt` is used.
//!
//! ### Expose documentation
//!
//! In order to expose the documentation from the runtime metadata on the generated
//! code, users must specify the `generate_docs` flag:
//!
//! ```ignore
//! #[subxt::subxt(generate_docs)]
//! pub mod polkadot {}
//! ```
//!
//! By default the documentation is not generated.
#![deny(unused_crate_dependencies)]
@@ -121,6 +134,8 @@ struct RuntimeMetadataArgs {
substitute_type: Vec<SubstituteType>,
#[darling(default, rename = "crate")]
crate_path: Option<String>,
#[darling(default)]
generate_docs: darling::util::Flag,
}
#[derive(Debug, FromMeta)]
@@ -177,6 +192,7 @@ pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream {
},
));
let should_gen_docs = args.generate_docs.is_present();
match (args.runtime_metadata_path, args.runtime_metadata_url) {
(Some(rest_of_path), None) => {
let root = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".into());
@@ -188,6 +204,7 @@ pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream {
derives_registry,
type_substitutes,
crate_path,
should_gen_docs,
)
.into()
}
@@ -201,6 +218,7 @@ pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream {
derives_registry,
type_substitutes,
crate_path,
should_gen_docs,
)
.into()
}