Skip to content

Commit

Permalink
plugins/Makefile: fail if jq command fails.
Browse files Browse the repository at this point in the history
Nested within the loop, jq would fail silently.

This can happen if jq is too old.

Fixes: #7657
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and vincenzopalazzo committed Sep 17, 2024
1 parent 5c870c9 commit 4578748
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 16 additions & 12 deletions plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -226,25 +226,29 @@ 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
# 2: deleting additionalProperties, required, enum, maxLength, minLength, pre_return_value_notes, post_return_value_notes, anyOf, oneOf, hidden, untyped, default, comment, added, maximum, minimum, pattern, format
# (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
Expand Down

0 comments on commit 4578748

Please sign in to comment.