| 1 |
#!/usr/bin/env just --justfile |
| 2 |
|
| 3 |
[private] |
| 4 |
default: |
| 5 |
@just --list |
| 6 |
|
| 7 |
# Setup the development environment. |
| 8 |
setup-dev: |
| 9 |
# Sudo is required to install packages with apt |
| 10 |
@echo Installing required packages from apt |
| 11 |
@sudo apt-get install bear valgrind libapt-pkg-dev dpkg-dev clang-format codespell -y |
| 12 |
@just setup-toolchain |
| 13 |
|
| 14 |
[private] |
| 15 |
@setup-toolchain: |
| 16 |
#!/bin/sh |
| 17 |
|
| 18 |
set -e |
| 19 |
|
| 20 |
echo Setting up toolchains |
| 21 |
rustup toolchain install nightly |
| 22 |
rustup toolchain install stable |
| 23 |
|
| 24 |
echo Installing nightly \`rustfmt\` |
| 25 |
rustup toolchain install nightly --component rustfmt |
| 26 |
echo Nightly \`rustfmt\` successfully installed! |
| 27 |
|
| 28 |
echo Cleaning and building c++ compile commands |
| 29 |
cargo clean |
| 30 |
|
| 31 |
bear -- cargo build |
| 32 |
echo Development environment installed successfully! |
| 33 |
|
| 34 |
# Run checks |
| 35 |
check: spellcheck clippy |
| 36 |
@cargo +nightly fmt --check |
| 37 |
@echo Checks were successful! |
| 38 |
|
| 39 |
# Remove generated artifacts |
| 40 |
clean: |
| 41 |
@cargo clean |
| 42 |
@echo Done! |
| 43 |
|
| 44 |
# Build the project |
| 45 |
build: |
| 46 |
@cargo build |
| 47 |
@echo Project successfully built! |
| 48 |
|
| 49 |
# Generate docs |
| 50 |
doc: |
| 51 |
@cargo doc |
| 52 |
@echo Documentation successfully generated! |
| 53 |
|
| 54 |
# Create the debs required for tests |
| 55 |
[private] |
| 56 |
@create-test-debs: |
| 57 |
#!/bin/sh |
| 58 |
set -e |
| 59 |
|
| 60 |
cd tests/files/cache |
| 61 |
rm -f *.deb Packages* |
| 62 |
for pkg in *; do |
| 63 |
dpkg-deb --build --nocheck "${pkg}"; |
| 64 |
done |
| 65 |
dpkg-scanpackages --multiversion . /dev/null > Packages |
| 66 |
|
| 67 |
# Create an empty garbage package to make sure it fails |
| 68 |
echo "\n" > pkg.deb |
| 69 |
|
| 70 |
# Run all tests except for root |
| 71 |
test +ARGS="": |
| 72 |
@just create-test-debs |
| 73 |
@cargo test --no-fail-fast -- --test-threads 1 --skip root --skip update {{ARGS}} |
| 74 |
|
| 75 |
# Run only the root tests. Sudo password required! |
| 76 |
@test-root +ARGS="": |
| 77 |
#!/bin/sh |
| 78 |
|
| 79 |
set -e |
| 80 |
|
| 81 |
just create-test-debs |
| 82 |
|
| 83 |
sudo -E /home/${USER}/.cargo/bin/cargo \ |
| 84 |
test \ |
| 85 |
--test root \ |
| 86 |
-- --test-threads 1 {{ARGS}} |
| 87 |
|
| 88 |
# Run leak tests. Requires root |
| 89 |
@leak: |
| 90 |
#!/bin/sh |
| 91 |
|
| 92 |
set -e |
| 93 |
just create-test-debs |
| 94 |
cargo test --no-run |
| 95 |
|
| 96 |
test_binaries=$( \ |
| 97 |
find target/debug/deps -executable -type f \ |
| 98 |
-printf "%T@ %p\n" | sort -nr | awk '{print $2}' \ |
| 99 |
| grep -v ".so" |
| 100 |
) |
| 101 |
|
| 102 |
for test in $test_binaries; do |
| 103 |
# Sudo is needed to memleak the root tests |
| 104 |
sudo valgrind --leak-check=full -- "${test}" --test-threads 1 |
| 105 |
done |
| 106 |
|
| 107 |
# Lint the codebase |
| 108 |
clippy +ARGS="": |
| 109 |
@cargo clippy --all-targets --all-features --workspace -- --deny warnings {{ARGS}} |
| 110 |
@echo Lint successful! |
| 111 |
|
| 112 |
# Format the codebase |
| 113 |
@fmt +ARGS="": |
| 114 |
#!/bin/sh |
| 115 |
|
| 116 |
set -e |
| 117 |
|
| 118 |
cargo +nightly fmt --all -- {{ARGS}} |
| 119 |
cd apt-pkg-c |
| 120 |
clang-format -i * |
| 121 |
echo Codebase formatted successfully! |
| 122 |
|
| 123 |
# Spellcheck the codebase |
| 124 |
spellcheck +ARGS="": |
| 125 |
@codespell --skip target --skip .git --skip .cargo --builtin clear,rare,informal,code --ignore-words-list mut,crate {{ARGS}} |
| 126 |
@echo Spellings look good! |
| 127 |
|
| 128 |
alias b := build |
| 129 |
alias c := check |
| 130 |
alias d := doc |
| 131 |
alias l := leak |
| 132 |
alias t := test |
| 133 |
alias r := test-root |