From 9cdee6373771c10a97393efa91dec30fcb156c10 Mon Sep 17 00:00:00 2001 From: Peter Neuroth Date: Mon, 19 Aug 2024 17:02:55 +0200 Subject: [PATCH] chore: Add convenience targets to Makefiles Adds some rust (cargo) convenience targets to the Makefiles, this allows to run clippy on `check` targets. This may help us to address clippy hints in the future. Signed-off-by: Peter Neuroth --- Makefile | 23 ++++++++++++++----- libs/gl-client/Makefile | 43 ++++++++++++++++++++++++++++++++++-- libs/gl-plugin/Makefile | 30 +++++++++++++++++++++++++ libs/gl-signerproxy/Makefile | 30 +++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 65c07a216..1db3696ad 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ GL_CLIENT = ${LIBS}/gl-client GL_PLUGIN = ${LIBS}/gl-plugin GL_SIGNERPROXY = ${LIBS}/gl-signerproxy +# Do not run clippy on dependencies +CLIPPY_OPTS = --no-deps --message-format short + ARTIFACTS = \ .coverage @@ -58,6 +61,7 @@ DOCKER_OPTIONS= \ -v /tmp/gltesting/cargo/registry:/opt/cargo/registry \ -v ${REPO_ROOT}:/repo +# sync-files section .PHONY: sync-files gl_client_sync-files gl_plugin_sync-files gl_signerproxy_sync-files gl_client_sync-files: $(MAKE) -C ${GL_CLIENT} sync-files @@ -68,18 +72,25 @@ gl_plugin_sync-files: gl_signerproxy_sync-files: $(MAKE) -C ${GL_SIGNERPROXY} sync-files +# Sync all files sync-files: gl_client_sync-files gl_plugin_sync-files gl_signerproxy_sync-files -.PHONY: ensure-docker build-self check-self docker-image docs wheels +# Run clippy +clippy: + cargo clippy ${CLIPPY_OPTS} + +# Run rust tests +test-rs: + cargo test -check-rs: - cargo test --all -- --test-threads=1 +# Check runs clippy and the tests but does not fail on clippy warnings +check-rs: clippy test-rs + +.PHONY: clippy test-rs check-rs ensure-docker build-self check-self check-all docker-image docs wheels clean-rs: cargo clean -check: check-rs check-py - clean: clean-rs rm -rf ${ARTIFACTS} rm ${GENALL} @@ -91,7 +102,7 @@ build-self: ensure-docker cd libs/gl-client-py; maturin develop #mypy examples/python -check-all: check-self check-gl-client check-py +check-all: check-rs check-self check-py check-self: ensure-docker build-self PYTHONPATH=/repo/libs/gl-testing \ diff --git a/libs/gl-client/Makefile b/libs/gl-client/Makefile index 3dbd9a0e4..d7084e9c2 100644 --- a/libs/gl-client/Makefile +++ b/libs/gl-client/Makefile @@ -7,8 +7,35 @@ endif LIBS=${REPO_ROOT}/libs SELF_DIR=${LIBS}/gl-client -check-gl-client: - (cd ${GL_CLIENT_DIR}; cargo test) +MANIFEST_PATH = --manifest-path=${SELF_DIR}/Cargo.toml +FMT_OPTS = -- --check +CLIPPY_OPTS = --no-deps --message-format short + +# Check code for formatting issues +fmt: + cargo fmt ${MANIFEST_PATH} ${FMT_OPTS} + +# Fix formatting issues +fmt-fix: + cargo fmt ${MANIFEST_PATH} + +# Check Clippy linter, does not fail on warnings +clippy: + cargo clippy ${CLIPPY_OPTS} ${MANIFEST_PATH} + +# Run clippy linter and fix issues automatically where possible +clippy-fix: + cargo clippy --fix ${MANIFEST_PATH} + +# Run tests +test: + cargo test ${MANIFEST_PATH} + +# Checks that clippy and tests only produce warnings +check: clippy test + +# Same as check but also fails if there are formatting issues +check-all: fmt clippy test # Syncronize proto and tls files into .resources dir sync-files: @@ -16,3 +43,15 @@ sync-files: rsync -avr --delete --delete-excluded ${LIBS}/tls/ ${SELF_DIR}/.resources/tls git add ${SELF_DIR}/.resources +help: + @echo "Usage:" + @echo " make check - Check the project" + @echo " make check-all - Same as make check but also checks the format" + @echo " make test - Run tests" + @echo " make clippy - Run Clippy linter" + @echo " make clippy-fix - Run Clippy and automatically fix issues" + @echo " make fmt - Check code formatting" + @echo " make fmt-fix - Format the code (in-place)" + @echo " make help - Show this help message" + +.PHONY: fmt fmt-fix clippy clippy-fix check sync-files help diff --git a/libs/gl-plugin/Makefile b/libs/gl-plugin/Makefile index 504a2330f..0b2d2f0a3 100644 --- a/libs/gl-plugin/Makefile +++ b/libs/gl-plugin/Makefile @@ -7,6 +7,36 @@ endif LIBS=${REPO_ROOT}/libs SELF_DIR=${LIBS}/gl-plugin +MANIFEST_PATH = --manifest-path=${SELF_DIR}/Cargo.toml +FMT_OPTS = -- --check +CLIPPY_OPTS = --no-deps --message-format short + +# Check code for formatting issues +fmt: + cargo fmt ${MANIFEST_PATH} ${FMT_OPTS} + +# Fix formatting issues +fmt-fix: + cargo fmt ${MANIFEST_PATH} + +# Check Clippy linter, does not fail on warnings +clippy: + cargo clippy ${CLIPPY_OPTS} ${MANIFEST_PATH} + +# Run clippy linter and fix issues automatically where possible +clippy-fix: + cargo clippy --fix ${MANIFEST_PATH} + +# Run tests +test: + cargo test ${MANIFEST_PATH} + +# Checks that clippy and tests only produce warnings +check: clippy test + +# Same as check but also fails if there are formatting issues +check-all: fmt clippy test + # Syncronize proto and tls files into .resources dir sync-files: rsync -avr --delete --delete-excluded ${LIBS}/proto/glclient/greenlight.proto ${SELF_DIR}/.resources/proto/glclient/greenlight.proto diff --git a/libs/gl-signerproxy/Makefile b/libs/gl-signerproxy/Makefile index 4d4168dd3..3966cf090 100644 --- a/libs/gl-signerproxy/Makefile +++ b/libs/gl-signerproxy/Makefile @@ -7,6 +7,36 @@ endif LIBS=${REPO_ROOT}/libs SELF_DIR=${LIBS}/gl-signerproxy +MANIFEST_PATH = --manifest-path=${SELF_DIR}/Cargo.toml +FMT_OPTS = -- --check +CLIPPY_OPTS = --no-deps --message-format short + +# Check code for formatting issues +fmt: + cargo fmt ${MANIFEST_PATH} ${FMT_OPTS} + +# Fix formatting issues +fmt-fix: + cargo fmt ${MANIFEST_PATH} + +# Check Clippy linter, does not fail on warnings +clippy: + cargo clippy ${CLIPPY_OPTS} ${MANIFEST_PATH} + +# Run clippy linter and fix issues automatically where possible +clippy-fix: + cargo clippy --fix ${MANIFEST_PATH} + +# Run tests +test: + cargo test ${MANIFEST_PATH} + +# Checks that clippy and tests only produce warnings +check: clippy test + +# Same as check but also fails if there are formatting issues +check-all: fmt clippy test + # Syncronize proto and tls files into .resources dir sync-files: rsync -avr --delete --delete-excluded ${LIBS}/proto/glclient/greenlight.proto ${SELF_DIR}/.resources/proto/glclient/greenlight.proto