sp-api: Support expanding the macro code (#13573)

* sp-api: Support expanding the macro code

This pr introduces the `expander` crate to expand the generated source code into a file. This gives
better error reporting when trying to fix issues in the macro itself as Rustc will point to the line
in this file. The feature can be enabled by setting `SP_API_EXPAND=1` at compile time.

Besides that the generated code is changed to fix warnings in the exanped version.

* Fixes
This commit is contained in:
Bastian Köcher
2023-03-14 22:14:58 +01:00
committed by GitHub
parent ef165cec3e
commit 4ef1d0df02
9 changed files with 124 additions and 101 deletions
@@ -166,17 +166,17 @@ fn test_client_side_function_signature() {
#[test]
fn check_runtime_api_info() {
assert_eq!(&<dyn Api::<Block>>::ID, &runtime_decl_for_Api::ID);
assert_eq!(<dyn Api::<Block>>::VERSION, runtime_decl_for_Api::VERSION);
assert_eq!(&<dyn Api::<Block>>::ID, &runtime_decl_for_api::ID);
assert_eq!(<dyn Api::<Block>>::VERSION, runtime_decl_for_api::VERSION);
assert_eq!(<dyn Api::<Block>>::VERSION, 1);
assert_eq!(
<dyn ApiWithCustomVersion::<Block>>::VERSION,
runtime_decl_for_ApiWithCustomVersion::VERSION,
runtime_decl_for_api_with_custom_version::VERSION,
);
assert_eq!(
&<dyn ApiWithCustomVersion::<Block>>::ID,
&runtime_decl_for_ApiWithCustomVersion::ID,
&runtime_decl_for_api_with_custom_version::ID,
);
assert_eq!(<dyn ApiWithCustomVersion::<Block>>::VERSION, 2);
@@ -1,10 +1,10 @@
error[E0433]: failed to resolve: could not find `ApiV4` in `runtime_decl_for_Api`
error[E0433]: failed to resolve: could not find `ApiV4` in `runtime_decl_for_api`
--> tests/ui/impl_missing_version.rs:21:13
|
21 | impl self::Api<Block> for Runtime {
| ^^^ could not find `ApiV4` in `runtime_decl_for_Api`
| ^^^ could not find `ApiV4` in `runtime_decl_for_api`
error[E0405]: cannot find trait `ApiV4` in module `self::runtime_decl_for_Api`
error[E0405]: cannot find trait `ApiV4` in module `self::runtime_decl_for_api`
--> tests/ui/impl_missing_version.rs:21:13
|
11 | pub trait Api {