From 52a0910c718f2534ebbd3bb0d825c851537cb9e3 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 14 Jun 2023 20:49:48 +0200 Subject: [PATCH] `construct_runtime`: support for expanding the macro code (#14379) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * construct_runtime: support for expanding the macro code * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update frame/support/procedural/Cargo.toml Co-authored-by: Bastian Köcher <git@kchr.de> * fmt added * fmt removed --------- Co-authored-by: Bastian Köcher <git@kchr.de> --- substrate/Cargo.lock | 1 + substrate/frame/support/procedural/Cargo.toml | 1 + .../support/procedural/src/construct_runtime/mod.rs | 10 +++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 5affebc76fd..5584971260c 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -2848,6 +2848,7 @@ dependencies = [ "Inflector", "cfg-expr", "derive-syn-parse", + "expander", "frame-support-procedural-tools", "itertools", "macro_magic", diff --git a/substrate/frame/support/procedural/Cargo.toml b/substrate/frame/support/procedural/Cargo.toml index a2823463c5d..f8c6b9393f0 100644 --- a/substrate/frame/support/procedural/Cargo.toml +++ b/substrate/frame/support/procedural/Cargo.toml @@ -25,6 +25,7 @@ syn = { version = "2.0.16", features = ["full"] } frame-support-procedural-tools = { version = "4.0.0-dev", path = "./tools" } proc-macro-warning = { version = "0.4.1", default-features = false } macro_magic = { version = "0.3.5", features = ["proc_support"] } +expander = "2.0.0" [features] default = ["std"] diff --git a/substrate/frame/support/procedural/src/construct_runtime/mod.rs b/substrate/frame/support/procedural/src/construct_runtime/mod.rs index 958a10e7242..9879a65d684 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/mod.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/mod.rs @@ -178,7 +178,15 @@ pub fn construct_runtime(input: TokenStream) -> TokenStream { .and_then(|_| construct_runtime_final_expansion(explicit_decl)), }; - res.unwrap_or_else(|e| e.to_compile_error()).into() + let res = res.unwrap_or_else(|e| e.to_compile_error()); + + let res = expander::Expander::new("construct_runtime") + .dry(std::env::var("FRAME_EXPAND").is_err()) + .verbose(true) + .write_to_out_dir(res) + .expect("Does not fail because of IO in OUT_DIR; qed"); + + res.into() } /// When some pallet have implicit parts definition then the macro will expand into a macro call to -- GitLab