Repository navigation
Expand file tree
/
Copy pathlints.sh
More file actions
executable file
·121 lines (108 loc) · 4.96 KB
/
Copy pathlints.sh
File metadata and controls
executable file
·121 lines (108 loc) · 4.96 KB
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
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (c) 2026 Fábio Henrique de Lima Silva (fhl.bsb@gmail.com) All rights reserved.
# lints.sh — Análise estática, formatação e conformidade textual. Classe A.
# Uso: utils/lints.sh
# Orçamento: 130 # +15: margem preventiva cross_target bidirecional e scan spdx
set -x; PS4='+ ${BASH_SOURCE##*/}:${LINENO}: '
set -euo pipefail
cd "$(dirname "$0")/.."
. utils/_lib.sh
case "${1:-}" in "") ;; -h|--help) help_exit "Uso: utils/lints.sh" ;; *) usage_fail "lints.sh aceita apenas -h/--help" ;; esac
lib_init
trap 'trap_fail $?' ERR
phase_fmt() {
if [ "${CI:-}" = "true" ]; then cargo fmt --all -- --check; else cargo fmt --all && git diff --stat; fi
}
run_step fmt phase_fmt
phase_check() {
cargo check --locked --all-targets --all-features
cargo check --locked --lib --no-default-features
cargo check --locked --all-targets --no-default-features
}
run_step check phase_check
phase_clippy() {
cargo clippy --locked --all-targets --all-features -- -D warnings
cargo clippy --locked --lib --no-default-features -- -D warnings
cargo clippy --locked --all-targets --no-default-features -- -D warnings
}
run_step clippy phase_clippy
# Cross-checks target-specific cfg branches (N-26). Native aarch64 already ran clippy in phase_clippy;
# x86_64 hosts only emit .rmeta with PKG_CONFIG_ALLOW_CROSS=1 for pkg-config metadata discovery.
PHASE_NAME=cross_target_check
HOST_ARCH="$(rustc -vV | sed -n 's/^host: //p')"
if [ "$HOST_ARCH" = aarch64-unknown-linux-gnu ]; then
if rustup target list --installed | grep -qx x86_64-unknown-linux-gnu; then
run_step cross_target_check env PKG_CONFIG_ALLOW_CROSS=1 cargo clippy --locked --lib --target x86_64-unknown-linux-gnu -- -D warnings
else
gap "cross_target_check:native-host-x86-target-not-installed"
fi
elif ! rustup target list --installed | grep -qx aarch64-unknown-linux-gnu; then
gap "cross_target_check:target-not-installed"
else
run_step cross_target_check env PKG_CONFIG_ALLOW_CROSS=1 cargo clippy --locked --lib --target aarch64-unknown-linux-gnu -- -D warnings
fi
phase_doc() {
RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps --all-features
}
run_step doc phase_doc
phase_spdx() {
local files=() missing=() f rc listing
listing=$(git ls-files '*.rs' '*.sh' '*.py' 'build.rs' 'Cargo.toml') \
|| { echo "SPDX scan failed: git ls-files failed" >&2; return 1; }
[ -n "$listing" ] || { echo "SPDX scan failed: git ls-files returned no files" >&2; return 1; }
mapfile -t files <<< "$listing"
for f in "${files[@]}"; do
grep -qE "SPDX-License-Identifier: (GPL-3\.0-or-later|MIT)" "$f"; rc=$?
[ "$rc" -eq 0 ] && continue
[ "$rc" -eq 1 ] || { echo "SPDX scan failed: $f" >&2; return 1; }
missing+=("$f")
done
[ ${#missing[@]} -eq 0 ] || { echo "Missing or invalid SPDX header:" >&2; printf ' %s\n' "${missing[@]}" >&2; return 1; }
}
run_step spdx phase_spdx
phase_policies() {
if [ -d "tests/common" ] && grep -rnF "#[test]" tests/common/ > /dev/null 2>&1; then
echo "ERROR: #[test] in tests/common/" >&2; exit 1
fi
lib_quiet=1 utils/verify_no_rt_alloc.sh
local clippy_errs
clippy_errs=$(git ls-files 'src/*.rs' 'tests/*.rs' 'benches/*.rs' | xargs awk '
FNR == 1 { prev = 0 }
/^[[:space:]]*#\[allow\(clippy::/ {
if (!prev) print FILENAME ":" FNR ": " $0
prev = 0; next
}
/^[[:space:]]*(\/\/[[:space:]]*(SPDX|Copyright)|\/\/\/|\/\/!)/ { prev = 0; next }
/^[[:space:]]*(\/\/[^/!]|[\/]\*)/ { prev = 1; next }
/^[[:space:]]*$/ { next }
{ prev = 0 }
')
if [ -n "$clippy_errs" ]; then
echo "Uncommented clippy allow attributes found:" >&2
echo "$clippy_errs" >&2
exit 1
fi
local cargo_ver metainfo_file xml_ver
cargo_ver=$(grep -m1 '^version = ' Cargo.toml | cut -d '"' -f2)
metainfo_file="packaging/flatpak/org.freedesktop.LinuxAudio.Plugins.NAMPlug.metainfo.xml"
if [ -f "$metainfo_file" ]; then
xml_ver=$(grep -m1 '<release version=' "$metainfo_file" | sed -E 's/.*version="([^"]+)".*/\1/')
if [ "$cargo_ver" != "$xml_ver" ]; then
echo "ERROR: Version mismatch between Cargo.toml ($cargo_ver) and $metainfo_file ($xml_ver)!" >&2
exit 1
fi
fi
}
run_step policies phase_policies
# AppStream metadata was validated manually before; make it a real gate.
phase_packaging() {
local m="packaging/flatpak/org.freedesktop.LinuxAudio.Plugins.NAMPlug.metainfo.xml"
[ -f "$m" ] || { echo "Missing mandatory packaging path: $m" >&2; return 1; }
command -v appstreamcli >/dev/null 2>&1 || { echo "appstreamcli is required (appstream package)" >&2; return 1; }
appstreamcli validate --no-net --strict "$m"
}
run_step packaging phase_packaging
phase_script_budget() { local f b; for f in $(find utils -name '*.sh'); do b=$(sed -n 's/^# Orçamento: *\([0-9]*\).*/\1/p;T;q' "$f"); [ -n "$b" ] && [ "$(wc -l < "$f")" -le "$b" ] || { echo "ORÇAMENTO: $f teto=${b:-AUSENTE} linhas=$(wc -l < "$f")" >&2; return 1; }; done; }
run_step script-budget phase_script_budget
finish