Skip to content

Commit

Permalink
Makefile: use grouped targets for recipes with multiple fixed outputs
Browse files Browse the repository at this point in the history
See the section headed "Rules with Grouped Targets" on the Texinfo page
`(make)Multiple Targets`.

Without this fix, Make does not know that these recipes unconditionally
make *all* of their named targets regardless of which target triggers
their execution, and Make will blissfully execute multiple instances of
any such recipe in parallel, not only wasting CPU cycles but potentially
producing incorrect results if the recipe is not atomic in its effects
on the file system.  With this fix, Make understands that it need only
execute such a recipe once to make all of its targets.

In pursuit of the above, move and combine two redundant msggen recipes
into the top-level Makefile, and populate its grouped targets from the
subordinate Makefiles.

Changelog-None
  • Loading branch information
whitslack authored and rustyrussell committed Jun 15, 2023
1 parent cc71f75 commit e56828b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,16 @@ ifneq ($(RUST),0)
include cln-rpc/Makefile
include cln-grpc/Makefile

$(MSGGEN_GENALL)&: doc/schemas/*.request.json doc/schemas/*.schema.json
PYTHONPATH=contrib/msggen python3 contrib/msggen/msggen/__main__.py

GRPC_GEN = contrib/pyln-testing/pyln/testing/node_pb2.py \
contrib/pyln-testing/pyln/testing/node_pb2_grpc.py \
contrib/pyln-testing/pyln/testing/primitives_pb2.py

ALL_TEST_GEN += $(GRPC_GEN)

$(GRPC_GEN): cln-grpc/proto/node.proto cln-grpc/proto/primitives.proto
$(GRPC_GEN)&: cln-grpc/proto/node.proto cln-grpc/proto/primitives.proto
python -m grpc_tools.protoc -I cln-grpc/proto cln-grpc/proto/node.proto --python_out=contrib/pyln-testing/pyln/testing/ --grpc_python_out=contrib/pyln-testing/pyln/testing/ --experimental_allow_proto3_optional
python -m grpc_tools.protoc -I cln-grpc/proto cln-grpc/proto/primitives.proto --python_out=contrib/pyln-testing/pyln/testing/ --experimental_allow_proto3_optional
# The compiler assumes that the proto files are in the same
Expand Down
3 changes: 1 addition & 2 deletions cln-grpc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ CLN_GRPC_GENALL = cln-grpc/proto/node.proto \

DEFAULT_TARGETS += $(CLN_GRPC_EXAMPLES) $(CLN_GRPC_GENALL)

$(CLN_GRPC_GENALL): $(JSON_SCHEMA)
PYTHONPATH=contrib/msggen python3 contrib/msggen/msggen/__main__.py
MSGGEN_GENALL += $(CLN_GRPC_GENALL)

cln-grpc-all: ${CLN_GRPC_GENALL} ${CLN_GRPC_EXAMPLES}
4 changes: 1 addition & 3 deletions cln-rpc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ cln-rpc-wrongdir:
CLN_RPC_EXAMPLES := target/${RUST_PROFILE}/examples/cln-rpc-getinfo
CLN_RPC_GENALL = cln-rpc/src/model.rs
CLN_RPC_SOURCES = $(shell find cln-rpc -name *.rs) ${CLN_RPC_GENALL}
JSON_SCHEMAS = $(wildcard doc/schemas/*.request.json doc/schemas/*.schema.json)
DEFAULT_TARGETS += $(CLN_RPC_EXAMPLES) $(CLN_RPC_GENALL)

$(CLN_RPC_GENALL): $(JSON_SCHEMAS)
PYTHONPATH=contrib/msggen python3 contrib/msggen/msggen/__main__.py
MSGGEN_GENALL += $(CLN_RPC_GENALL)

target/${RUST_PROFILE}/examples/cln-rpc-getinfo: $(shell find cln-rpc -name *.rs)
cargo build ${CARGO_OPTS} --example cln-rpc-getinfo
Expand Down

0 comments on commit e56828b

Please sign in to comment.