From b7df75cc2608fc337f13aed4f99e98d5ef96e5dc Mon Sep 17 00:00:00 2001 From: Benoit Lavenier <benoit.lavenier@e-is.pro> Date: Tue, 28 May 2024 11:09:45 +0200 Subject: [PATCH] Generate runtime-error.po --- xtask/README.md | 4 +++- xtask/res/templates/runtime-errors.po | 7 +++++++ xtask/src/gen_doc.rs | 15 ++++++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 xtask/res/templates/runtime-errors.po diff --git a/xtask/README.md b/xtask/README.md index f9ee2d898..c0f5fd5a8 100644 --- a/xtask/README.md +++ b/xtask/README.md @@ -15,9 +15,11 @@ Usage: xtask <COMMAND> Commands: build Build duniter binary - gen-calls-doc Generate calls documentation + gen-doc Generate documentation (calls and events) inject-runtime-code Inject runtime code in raw specs release-runtime Release a new runtime + update-raw-specs Update raw specs locally with the files published on a Release + create-asset-link Create asset in a release test Execute unit tests and integration tests End2tests are skipped help Print this message or the help of the given subcommand(s) diff --git a/xtask/res/templates/runtime-errors.po b/xtask/res/templates/runtime-errors.po new file mode 100644 index 000000000..b35e80ad3 --- /dev/null +++ b/xtask/res/templates/runtime-errors.po @@ -0,0 +1,7 @@ +{% for pallet in pallets -%} +{% for error in pallet.errors -%} + +msgid "{{ pallet.name }}.{{ error.name }}" +msgstr "{{ error.documentation }}" +{% endfor -%} +{% endfor -%} diff --git a/xtask/src/gen_doc.rs b/xtask/src/gen_doc.rs index 3ea49c742..fdae3b0e8 100644 --- a/xtask/src/gen_doc.rs +++ b/xtask/src/gen_doc.rs @@ -43,6 +43,7 @@ where const CALLS_DOC_FILEPATH: &str = "docs/api/runtime-calls.md"; const EVENTS_DOC_FILEPATH: &str = "docs/api/runtime-events.md"; const ERRORS_DOC_FILEPATH: &str = "docs/api/runtime-errors.md"; +const ERRORS_PO_FILEPATH: &str = "docs/api/runtime-errors.po"; const TEMPLATES_GLOB: &str = "xtask/res/templates/*.md"; const WEIGHT_FILEPATH: &str = "runtime/gdev/src/weights/"; @@ -306,7 +307,7 @@ pub(super) fn gen_doc() -> Result<()> { }) }); - let (call_doc, event_doc, error_doc) = print_runtime(runtime); + let (call_doc, event_doc, error_doc, error_po) = print_runtime(runtime); // Generate docs from rust code Command::new("cargo") @@ -348,6 +349,10 @@ pub(super) fn gen_doc() -> Result<()> { .with_context(|| format!("Failed to create file '{}'", ERRORS_DOC_FILEPATH))?; file.write_all(error_doc.as_bytes()) .with_context(|| format!("Failed to write to file '{}'", ERRORS_DOC_FILEPATH))?; + let mut file = File::create(ERRORS_PO_FILEPATH) + .with_context(|| format!("Failed to create file '{}'", ERRORS_PO_FILEPATH))?; + file.write_all(error_po.as_bytes()) + .with_context(|| format!("Failed to write to file '{}'", ERRORS_PO_FILEPATH))?; Ok(()) } @@ -469,7 +474,7 @@ fn get_weights(max_weight: u128) -> Result<HashMap<String, HashMap<String, Weigh } /// use template to render markdown file with runtime calls documentation -fn print_runtime(pallets: RuntimePallets) -> (String, String, String) { +fn print_runtime(pallets: RuntimePallets) -> (String, String, String, String) { // init variables let mut user_calls_counter = 0; let user_calls_pallets: RuntimePallets = pallets @@ -568,5 +573,9 @@ fn print_runtime(pallets: RuntimePallets) -> (String, String, String) { .render("runtime-errors.md", &context) .expect("template error"); - (call_doc, event_doc, error_doc) + let error_po = tera + .render("runtime-errors.po", &context) + .expect("template error"); + + (call_doc, event_doc, error_doc, error_po) } -- GitLab