-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
276 lines (228 loc) · 7.39 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
## Configuration
## =============
# Parameters
# ----------
# Name of package containing the app to be built.
# Rust does not enforce that the path to the package matches the package name, but
# this makefile does to keep things simple.
export AXIS_PACKAGE ?= hello_world
# The architecture that will be assumed when interacting with the device.
export AXIS_DEVICE_ARCH ?= aarch64
# The IP address of the device to interact with.
export AXIS_DEVICE_IP ?= 192.168.0.90
# The username to use when interacting with the device.
export AXIS_DEVICE_USER ?= root
# The password to use when interacting with the device.
export AXIS_DEVICE_PASS ?= pass
# Reproducible and stable results by default
export SOURCE_DATE_EPOCH ?= 0
# Other
# -----
# Have zero effect by default to prevent accidental changes.
.DEFAULT_GOAL := help
# Delete targets that fail to prevent subsequent attempts incorrectly assuming
# the target is up to date.
.DELETE_ON_ERROR: ;
# Don't remove intermediate files.
.SECONDARY:
# Prevent pesky default rules from creating unexpected dependency graphs.
.SUFFIXES: ;
# Rebuild targets when marking them as phony directly is not enough.
FORCE:;
.PHONY: FORCE
## Verbs
## =====
help:
@mkhelp $(firstword $(MAKEFILE_LIST))
## Reset <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> to a clean state suitable for development and testing.
reinit:
RUST_LOG=info device-manager reinit
## Build <AXIS_PACKAGE> for <AXIS_DEVICE_ARCH>
build: apps/$(AXIS_PACKAGE)/LICENSE
CARGO_TARGET_DIR=target-$(AXIS_DEVICE_ARCH) \
cargo-acap-build \
--target $(AXIS_DEVICE_ARCH) \
-- \
--package $(AXIS_PACKAGE) \
--profile app
## Install <AXIS_PACKAGE> on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
install:
cargo-acap-sdk install \
-- \
--profile app
## Remove <AXIS_PACKAGE> from <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS>
remove:
cargo-acap-sdk remove
## Start <AXIS_PACKAGE> on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS>
start:
cargo-acap-sdk start
## Stop <AXIS_PACKAGE> on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS>
stop:
cargo-acap-sdk stop
## Build and run <AXIS_PACKAGE> directly on <AXIS_DEVICE_IP> assuming architecture <AXIS_DEVICE_ARCH>
##
## Prerequisites:
##
## * <AXIS_PACKAGE> is recognized by `cargo-acap-build` as an ACAP app.
## * The app is installed on the device.
## * The app is stopped.
## * The device has SSH enabled the ssh user root configured.
run: apps/$(AXIS_PACKAGE)/LICENSE
CARGO_TARGET_DIR=target-$(AXIS_DEVICE_ARCH) \
cargo-acap-build --target $(AXIS_DEVICE_ARCH) -- -p $(AXIS_PACKAGE)
acap-ssh-utils patch target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)/*.eap
acap-ssh-utils run-app \
--environment RUST_LOG=debug \
--environment RUST_LOG_STYLE=always \
$(AXIS_PACKAGE)
## Build and execute unit tests for <AXIS_PACKAGE> on <AXIS_DEVICE_IP> assuming architecture <AXIS_DEVICE_ARCH>
##
## Prerequisites:
##
## * <AXIS_PACKAGE> is recognized by `cargo-acap-build` as an ACAP app.
## * The app is installed on the device.
## * The app is stopped.
## * The device has SSH enabled the ssh user root configured.
test: apps/$(AXIS_PACKAGE)/LICENSE
# The `scp` command below needs the wildcard to match exactly one file.
rm -r target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)-*/$(AXIS_PACKAGE) ||:
CARGO_TARGET_DIR=target-$(AXIS_DEVICE_ARCH) \
cargo-acap-build --target $(AXIS_DEVICE_ARCH) -- -p $(AXIS_PACKAGE) --tests
acap-ssh-utils patch target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)-*/*.eap
acap-ssh-utils run-app \
--environment RUST_LOG=debug \
--environment RUST_LOG_STYLE=always \
$(AXIS_PACKAGE) \
-- \
--test-threads=1
## Bulk operations
## ---------------
## Install all apps on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
install_all: $(patsubst %/,%/LICENSE,$(wildcard apps/*/))
cargo-acap-sdk install \
-- \
--package '*_*' \
--profile app
## Build and execute unit tests for all apps on <AXIS_DEVICE_IP> assuming architecture <AXIS_DEVICE_ARCH>
test_all: $(patsubst %/,%/LICENSE,$(wildcard apps/*/))
cargo-acap-sdk test \
-- \
--package licensekey \
--package '*_*'
## Checks
## ------
## Run all checks except generated files
check_other: check_build check_docs check_format check_lint check_tests
.PHONY: check_other
## Check that all crates can be built
check_build: target-$(AXIS_DEVICE_ARCH)/acap/_envoy
cargo build \
--exclude '*_*' \
--locked \
--workspace
.PHONY: check_build
## Check that docs can be built
check_docs:
RUSTDOCFLAGS="-Dwarnings" cargo doc \
--document-private-items \
--locked \
--no-deps \
--workspace
CARGO_TARGET_DIR=target-$(AXIS_DEVICE_ARCH) \
RUSTDOCFLAGS="-Dwarnings" cargo doc \
--document-private-items \
--locked \
--no-deps \
--target aarch64-unknown-linux-gnu \
--workspace
.PHONY: check_docs
## Check that the code is formatted correctly
check_format:
cargo fmt --check
.PHONY: check_format
## Check that generated files are up to date
check_generated_files: Cargo.lock $(patsubst %/,%/src/bindings.rs,$(wildcard crates/*-sys/))
git update-index -q --refresh
git --no-pager diff --exit-code HEAD -- $^
.PHONY: check_generated_files
## Check that generated files are up to date, including machine-dependent generated files.
check_generated_files_container: apps-$(AXIS_DEVICE_ARCH).checksum apps-$(AXIS_DEVICE_ARCH).filesize
git update-index -q --refresh
git --no-pager diff --exit-code HEAD -- $^
.PHONY: check_generated_files_container
## Check that the code is free of lints
check_lint:
cargo clippy \
--all-targets \
--locked \
--no-deps \
--workspace \
-- \
-Dwarnings
CARGO_TARGET_DIR=target-$(AXIS_DEVICE_ARCH) \
cargo clippy \
--all-targets \
--locked \
--no-deps \
--target aarch64-unknown-linux-gnu \
--workspace \
-- \
-Dwarnings
.PHONY: check_lint
## _
check_tests:
cargo test \
--exclude '*_*' \
--exclude '*-sys' \
--exclude axevent \
--exclude axstorage \
--exclude bbox \
--exclude licensekey \
--exclude mdb \
--locked \
--workspace
.PHONY: check_tests
## Fixes
## -----
## Attempt to fix formatting automatically
fix_format:
cargo fmt
.PHONY: fix_format
## Attempt to fix lints automatically
fix_lint:
cargo clippy --fix
.PHONY: fix_lint
## Nouns
## =====
Cargo.lock: FORCE
cargo metadata > /dev/null
.devhost/constraints.txt: .devhost/requirements.txt
pip-compile \
--allow-unsafe \
--no-header \
--quiet \
--strip-extras \
--output-file $@ \
$^
# TODO: Find a convenient way to integrate this with cargo-acap-build
apps/%/LICENSE: apps/%/Cargo.toml about.hbs
cargo-about generate \
--fail \
--manifest-path apps/$*/Cargo.toml \
--output-file $@ \
about.hbs
apps-$(AXIS_DEVICE_ARCH).checksum: target-$(AXIS_DEVICE_ARCH)/acap/_envoy
find target-$(AXIS_DEVICE_ARCH)/acap/ -name '*.eap' | LC_ALL=C sort | xargs shasum > $@
apps-$(AXIS_DEVICE_ARCH).filesize: target-$(AXIS_DEVICE_ARCH)/acap/_envoy
find target-$(AXIS_DEVICE_ARCH)/acap/ -name '*.eap' | LC_ALL=C sort | xargs du --apparent-size > $@
crates/%-sys/src/bindings.rs: target-$(AXIS_DEVICE_ARCH)/acap/_envoy
cp --archive $(firstword $(wildcard target-$(AXIS_DEVICE_ARCH)/*/*/build/$*-sys-*/out/bindings.rs)) $@
target-$(AXIS_DEVICE_ARCH)/acap/_envoy: $(patsubst %/,%/LICENSE,$(wildcard apps/*/))
CARGO_TARGET_DIR=target-$(AXIS_DEVICE_ARCH) \
cargo-acap-build \
--target $(AXIS_DEVICE_ARCH) \
-- \
--package '*_*' \
--locked
touch $@
.PHONY: target-$(AXIS_DEVICE_ARCH)/acap/_envoy