trace-forwarder: add make check for Rust

Add make check to run cargo fmt/clippy
for Rust projects.

Fixes: #3656

Signed-off-by: bin <bin@hyper.sh>
This commit is contained in:
bin 2022-02-14 16:17:53 +08:00
parent 7ae8901a66
commit 12c37fafc5
5 changed files with 13 additions and 15 deletions

View File

@ -98,6 +98,8 @@ define INSTALL_FILE
install -D -m 644 $1 $(DESTDIR)$2/$1 || exit 1; install -D -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
endef endef
.DEFAULT_GOAL := default
##TARGET default: build code ##TARGET default: build code
default: $(TARGET) show-header default: $(TARGET) show-header
@ -116,17 +118,6 @@ $(GENERATED_FILES): %: %.in
optimize: $(SOURCES) | show-summary show-header optimize: $(SOURCES) | show-summary show-header
@RUSTFLAGS="-C link-arg=-s $(EXTRA_RUSTFLAGS) --deny warnings" cargo build --target $(TRIPLE) --$(BUILD_TYPE) $(EXTRA_RUSTFEATURES) @RUSTFLAGS="-C link-arg=-s $(EXTRA_RUSTFLAGS) --deny warnings" cargo build --target $(TRIPLE) --$(BUILD_TYPE) $(EXTRA_RUSTFEATURES)
##TARGET clippy: run clippy linter
clippy: $(GENERATED_CODE)
cargo clippy --all-targets --all-features --release \
-- \
-Aclippy::redundant_allocation \
-D warnings
format:
cargo fmt -- --check
##TARGET install: install agent ##TARGET install: install agent
install: install-services install: install-services
@install -D $(TARGET_PATH) $(DESTDIR)/$(BINDIR)/$(TARGET) @install -D $(TARGET_PATH) $(DESTDIR)/$(BINDIR)/$(TARGET)
@ -146,7 +137,7 @@ test:
@cargo test --all --target $(TRIPLE) $(EXTRA_RUSTFEATURES) -- --nocapture @cargo test --all --target $(TRIPLE) $(EXTRA_RUSTFEATURES) -- --nocapture
##TARGET check: run test ##TARGET check: run test
check: clippy format check: $(GENERATED_FILES) standard_rust_check
##TARGET run: build and run agent ##TARGET run: build and run agent
run: run:

View File

@ -5,6 +5,7 @@
include ../../../utils.mk include ../../../utils.mk
.DEFAULT_GOAL := default
default: build default: build
build: logging-crate-tests build: logging-crate-tests

View File

@ -5,6 +5,7 @@
include ../../../utils.mk include ../../../utils.mk
.DEFAULT_GOAL := default
default: build default: build
build: logging-crate-tests build: logging-crate-tests
@ -24,7 +25,7 @@ test:
install: install:
check: check: standard_rust_check
.PHONY: \ .PHONY: \
build \ build \

View File

@ -73,8 +73,7 @@ async fn handle_trace_data<'a>(
let payload_len: u64 = NetworkEndian::read_u64(&header); let payload_len: u64 = NetworkEndian::read_u64(&header);
let mut encoded_payload = Vec::with_capacity(payload_len as usize); let mut encoded_payload = vec![0; payload_len as usize];
encoded_payload.resize(payload_len as usize, 0);
reader reader
.read_exact(&mut encoded_payload) .read_exact(&mut encoded_payload)

View File

@ -145,3 +145,9 @@ endif
TRIPLE = $(ARCH)-unknown-linux-$(LIBC) TRIPLE = $(ARCH)-unknown-linux-$(LIBC)
CWD := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) CWD := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
standard_rust_check:
cargo fmt -- --check
cargo clippy --all-targets --all-features --release \
-- \
-D warnings