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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2024-09-16 16:53:54 +09:30
committed by Vincenzo Palazzo
parent 5c870c90a6
commit 4578748aca
2 changed files with 17 additions and 13 deletions

View File

@@ -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