-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
127 lines (102 loc) · 3.47 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
ifdef TRAVIS_RUST_VERSION
RUST_TOOLCHAIN := ${TRAVIS_RUST_VERSION}
endif
ifndef RUST_TOOLCHAIN
RUST_TOOLCHAIN := $(shell cat ${CURDIR}/rust-toolchain 2> /dev/null | head -n 1)
ifeq ("${RUST_TOOLCHAIN}","")
RUST_TOOLCHAIN := stable
endif
endif
export RUST_TOOLCHAIN
ifndef CODECOV_DIR
CODECOV_DIR := ${CURDIR}
endif
# Usage: $(call call_all_features,makefile_target)
define call_all_features
( \
CARGO_ARGS="--no-default-features ${CARGO_ARGS}" ${MAKE} $(1) && \
CARGO_ARGS="${CARGO_ARGS}" ${MAKE} $(1) && \
CARGO_ARGS="--all-features ${CARGO_ARGS}" ${MAKE} $(1) \
)
endef
.PHONY: development
development: install-hooks
git submodule update --init --recursive
.PHONY: install-hooks
install-hooks: .git/hooks/pre-commit
@true
.git/hooks/pre-commit: venv .pre-commit-config.yaml
./venv/bin/pre-commit install -f --install-hooks
# Python Virtual Environment needed to allow usage of pre-commit.com
venv:
virtualenv venv --python python3
venv/bin/pip install --no-cache pre-commit
.PHONY: clean
clean: clean-coverage
rm -rf target venv
.PHONY: bump-submodules
bump-submodules:
bash scripts/bump-all-submodules.sh
.PHONY: clippy
clippy:
touch src/lib.rs # touch a file of the rust project to "force" cargo to recompile it so clippy will actually run
cargo +${RUST_TOOLCHAIN} clippy --all-targets ${CARGO_ARGS}
.PHONY: clippy-all-flavours
clippy-all-flavours:
$(call call_all_features,clippy)
.PHONY: pre-commit
pre-commit: venv
./venv/bin/pre-commit run --all-files
.PHONY: lint
lint: pre-commit clippy
$(call call_all_features,clippy)
.PHONY: build
build:
cargo +${RUST_TOOLCHAIN} build --all-targets ${CARGO_ARGS}
.PHONY: build-all-flavours
build-all-flavours:
$(call call_all_features,build)
.PHONY: test
test:
cargo +${RUST_TOOLCHAIN} test --all-targets ${CARGO_ARGS}
.PHONY: test-all-flavours
test-all-flavours:
$(call call_all_features,test)
.PHONY: audit
audit:
cargo +${RUST_TOOLCHAIN} audit
.PHONY: doc
doc:
cargo +${RUST_TOOLCHAIN} doc --no-deps ${CARGO_ARGS}
${CODECOV_DIR}/codecov.bash:
mkdir -p ${CODECOV_DIR}
curl -s https://codecov.io/bash > ${CODECOV_DIR}/codecov.bash
.coverage:
mkdir -p ${CURDIR}/.coverage
.PHONY: coverage
coverage: export CARGO_INCREMENTAL := 0
coverage: export RUSTFLAGS := ${RUSTFLAGS} -Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off
coverage: clean-coverage ${CODECOV_DIR}/codecov.bash
@command -v grcov @> /dev/null || (echo "grcov is not yet installed" && cargo install grcov)
mkdir --parent ${CURDIR}/.coverage
${MAKE} test-all-flavours
find ${CURDIR}/target -name "*$$(bash scripts/cargo-project-name.sh)*.gc*" | xargs zip -0 ${CURDIR}/.coverage/ccov.zip
grcov ${CURDIR}/.coverage/ccov.zip \
--source-dir ${CURDIR} \
--output-type lcov \
--llvm \
--ignore "/*" \
--ignore-not-existing \
--output-file ${CURDIR}/.coverage/lcov.info
@[ "${TRAVIS}" = "true" ] && \
bash ${CODECOV_DIR}/codecov.bash -f ${CURDIR}/.coverage/lcov.info || \
echo "Skip codecov uploads"
coverage-html: coverage
command -v genhtml @> /dev/null || (echo "genhtml is not yet installed. Please install lcov (https://github.com/linux-test-project/lcov) tools"; exit 1)
genhtml -o ${CURDIR}/.coverage/report/ --show-details --highlight --ignore-errors source --legend ${CURDIR}/.coverage/lcov.info
.PHONY: clean-coverage
clean-coverage:
rm -rf ${CURDIR}/.coverage
.PHONY: expand-macros
expand-macros:
cargo +${RUST_TOOLCHAIN} rustc --tests --all-features -- -Z external-macro-backtrace -Z unstable-options --pretty=expanded