From 4578748acaf92041a19ebed32871a3d6f2c8e859 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 16 Sep 2024 16:53:54 +0930 Subject: [PATCH] plugins/Makefile: fail if jq command fails. Nested within the loop, jq would fail silently. This can happen if jq is too old. Fixes: https://github.com/ElementsProject/lightning/issues/7657 Signed-off-by: Rusty Russell --- cln-rpc/src/model.rs | 2 +- plugins/Makefile | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/cln-rpc/src/model.rs b/cln-rpc/src/model.rs index 2704515ce..26a25e53a 100644 --- a/cln-rpc/src/model.rs +++ b/cln-rpc/src/model.rs @@ -3,7 +3,7 @@ // This file was automatically generated using the following command: // // ```bash -// contrib/msggen/msggen/__main__.py -s generate +// contrib/msggen/msggen/__main__.py generate // ``` // // Do not edit this file, it'll be overwritten. Rather edit the schema that diff --git a/plugins/Makefile b/plugins/Makefile index a0b2d5efe..e236af317 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -226,6 +226,7 @@ plugins/recklessrpc: $(PLUGIN_RECKLESSRPC_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMM # This covers all the low-level list RPCs which return simple arrays SQL_LISTRPCS := listchannels listforwards listhtlcs listinvoices listnodes listoffers listpeers listpeerchannels listclosedchannels listtransactions listsendpays bkpr-listaccountevents bkpr-listincome SQL_LISTRPCS_SCHEMAS := $(foreach l,$(SQL_LISTRPCS),doc/schemas/lightning-$l.json) +SQL_SCHEMA_PARTS := $(foreach l,$(SQL_LISTRPCS), plugins/sql-schema_$l_gen.h) # RES_JSON is generated by: # 1: deleting description array (used for field details) but keeping description keys @@ -233,18 +234,21 @@ SQL_LISTRPCS_SCHEMAS := $(foreach l,$(SQL_LISTRPCS),doc/schemas/lightning-$l.jso # (We only need [field].type, [field].name, [field].deprecated, [field].allOf, [field].items.allOf and allOf from response.properties) # 3: deleting empty objects from .response.properties # But these simple removals drop us from 100k to 18k. -plugins/sql-schema_gen.h: plugins/Makefile $(SQL_LISTRPCS_SCHEMAS) - @$(call VERBOSE,GEN $@, \ - ( \ - SEP=""; \ - echo '"{'; \ - for f in $(SQL_LISTRPCS); do \ - RES_JSON=$$(echo "$$(jq 'walk(if type == "object" then if has("description") and (.description | type) == "array" then del(.description) else . end else . end ) | walk(if type == "object" then del(.additionalProperties, .required, .enum, .maxLength, .minLength, .pre_return_value_notes, .post_return_value_notes, .anyOf, .oneOf, .hidden, .untyped, .default, .comment, .added, .maximum, .minimum, .pattern, .format) else . end) | walk(if type == "object" then with_entries(select(.value != {})) else . end) | .response.properties' < doc/schemas/lightning-$$f.json)" | sed 's/"/\\"/g'); \ - echo "$$SEP\\\"$$f\\\":{\\\"properties\\\": $$RES_JSON}"; \ - SEP=","; \ - done; \ - echo '}"' \ - ) | tr -d ' \n' > $@ \ +plugins/sql-schema_%_gen.h: doc/schemas/lightning-%.json + @jq 'walk(if type == "object" then if has("description") and (.description | type) == "array" then del(.description) else . end else . end ) | walk(if type == "object" then del(.additionalProperties, .required, .enum, .maxLength, .minLength, .pre_return_value_notes, .post_return_value_notes, .anyOf, .oneOf, .hidden, .untyped, .default, .comment, .added, .maximum, .minimum, .pattern, .format) else . end) | walk(if type == "object" then with_entries(select(.value != {})) else . end) | .response.properties' < $< > $@ + +# Regen if these rules change! +$(SQL_SCHEMA_PARTS): plugins/Makefile + +plugins/sql-schema_gen.h: $(SQL_SCHEMA_PARTS) + @$(call VERBOSE,GEN $@, set -e; (\ + SEP=""; \ + echo "\"{"; \ + for l in $(SQL_LISTRPCS); do \ + echo "$$SEP\"$$l\":{\"properties\":$$(cat plugins/sql-schema_$${l}_gen.h)}" | sed s/\"/\\\"/g; \ + SEP=","; \ + done | sed "s/\\\"/\\\\\"/g"; \ + echo "}\"") | tr -d " \n" > $@ \ ) plugins/sql.o: plugins/sql-schema_gen.h