-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
146 lines (120 loc) · 3.64 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
DESTDIR ?= /usr/local
MANPAGE_DIR = doc/man
# We are linking libraries written in C which may have suboptimal security
# histories. Prefer dynamic linking so security updates need not require a
# recompile.
DYNAMIC ?= 1
ifeq ($(DYNAMIC),1)
LIBGIT2_SYS_USE_PKG_CONFIG ?= 1
PKG_CONFIG_ALL_DYNAMIC ?= 1
export LIBGIT2_SYS_USE_PKG_CONFIG
export PKG_CONFIG_ALL_DYNAMIC
endif
# Test configuration.
GROUPS := bookworm oldest stable nightly
CRATES := core bin lfs
DOCKER_FILES := $(patsubst %,test/Dockerfile.%,$(GROUPS))
DOCKER_STAMPS := $(patsubst %,test/Dockerfile.%.stamp,$(GROUPS))
CI_TARGETS := $(patsubst %,ci-%,$(GROUPS))
PACKAGE_TARGETS := $(patsubst %,package-%,$(CRATES))
INCLUDES := $(wildcard test/include/*.erb)
MANPAGES := $(patsubst %.adoc,%.1,$(wildcard doc/man/*.adoc))
SRC := $(shell find . -name '*.rs') Makefile Cargo.toml
all:
cargo build --release
test:
cargo test
install: all
for i in target/release/git-*; do \
[ -x "$$i" ] || continue; \
install -m 755 "$$i" "$(DESTDIR)/bin/$$(basename "$$i")"; \
done
%.md: %.adoc
asciidoctor -o $@+ -b docbook5 $^
pandoc -f docbook -t commonmark -o $@ $@+
$(RM) $@+
%.1: %.adoc
asciidoctor -b manpage -a compat-mode -o $@ $^
doc: $(MANPAGES)
clean:
cargo clean
rm -fr target tmp
for i in "$(DOCKER_STAMPS)"; \
do \
[ ! -f "$$i" ] || docker image rm -f "$$i"; \
done
rm -f $(DOCKER_FILES) $(DOCKER_STAMPS)
rm -fr tmp
rm -fr *.md *.md+ scutiger-*/*.md scutiger-*/*.md+
rm -fr doc/man/*.1
linkage: tmp
set -e; \
for i in target/release/git-*; \
do \
echo $$i | grep -vF '.d' || continue; \
lfile=tmp/$$(basename $$i)-linkage; \
ldd $$i | tee $$lfile; \
echo Ensuring libssl is absent; \
grep -qsv libssl $$lfile; \
echo Looking for libgit2; \
grep -qs libgit2 $$lfile; \
echo Looking for libz; \
grep -qs libz $$lfile; \
echo Looking for libpcre2; \
grep -qs libpcre2 $$lfile; \
done
tmp:
[ -d tmp ] || mkdir tmp
# We do not require both of these commands here since nightly Rust may be
# missing one or more of these. When run under CI, they should be present for
# stable Rust and catch any issues.
#
# Note if we're using rustup, cargo-clippy may exist in the PATH even if clippy
# isn't installed, but it may be a wrapper that just fails when invoked. Check
# that it can successfully print help output to check if we really have clippy.
# The same goes for rustfmt.
lint:
if command -v cargo-clippy && cargo-clippy --help >/dev/null 2>&1; \
then \
$(MAKE) clippy; \
fi
if command -v rustfmt && rustfmt --help >/dev/null 2>&1; \
then \
$(MAKE) fmt; \
fi
package: $(PACKAGE_TARGETS)
package-%: scutiger-% scutiger-%/README.md
(cd "$<" && cargo package --allow-dirty)
ci: $(CI_TARGETS)
ci-%: test/Dockerfile.%.stamp
docker run --rm \
-e CARGO_NET_GIT_FETCH_WITH_CLI=true \
$$(cat "$<") \
sh -c 'cd /usr/src/scutiger && make test-full'
test-full:
make all
make doc
make test
make lint
test/Dockerfile.%.stamp: test/Dockerfile.% $(SRC)
docker build --iidfile="$@" -f "$<" .
test/Dockerfile.%: test/Dockerfile.%.erb $(INCLUDES)
test/template "$<" >"$@"
clippy:
rm -rf target
@# We exclude these lints here instead of in the file because Rust 1.24
@# doesn't support excluding clippy warnings. Similarly, it doesn't support
@# the syntax these lints suggest.
cargo clippy -- \
-A clippy::range-plus-one \
-A clippy::needless-lifetimes \
-A clippy::unknown-clippy-lints \
-D warnings
fmt:
if rustfmt --help | grep -qse --check; \
then \
rustfmt --check $$(find . -name '*.rs' | grep -v '^./target'); \
else \
rustfmt --write-mode diff $$(find . -name '*.rs' | grep -v '^./target'); \
fi
.PHONY: all lint ci clean doc clippy fmt linkage test