Debian Codegraph @

debian/rust-vendor/zerocopy/ci/check_stale_stderr.sh

raw
1 #!/usr/bin/env bash
2 #
3 # Copyright 2026 The Fuchsia Authors
4 #
5 # Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
6 # <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
7 # license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
8 # This file may not be copied, modified, or distributed except according to
9 # those terms.
10
11 set -eo pipefail
12 cd "$(dirname "$0")/.."
13
14 # Directories to search
15 DIRS=("tests" "zerocopy-derive/tests")
16
17 EXIT_CODE=0
18
19 for dir in "${DIRS[@]}"; do
20 if [ ! -d "$dir" ]; then
21 echo "Warning: Directory $dir does not exist, skipping." >&2
22 continue
23 fi
24
25 # Find all .stderr files
26 while IFS= read -r -d '' stderr_file; do
27 # Strip .stderr extension
28 base="${stderr_file%.stderr}"
29
30 # Strip toolchain suffixes
31 base="${base%.msrv}"
32 base="${base%.stable}"
33 base="${base%.nightly}"
34
35 # Construct the corresponding .rs file path
36 rs_file="${stderr_file%.stderr}.rs"
37 rs_file="${base}.rs"
38
39 # Check if the .rs file exists. The `-e` flag checks if file exists:
40 # It returns true for regular files and valid symlinks, and false for
41 # broken symlinks or missing files.
42 if [ ! -e "$rs_file" ]; then
43 echo "Error: Orphaned stderr file found: $stderr_file" >&2
44 echo " Missing regular file or valid symlink: $rs_file" >&2
45 EXIT_CODE=1
46 fi
47 done < <(find "$dir" -name "*.stderr" -print0)
48 done
49
50 if [ "$EXIT_CODE" -eq 1 ]; then
51 echo "Found stale .stderr files. Please delete them." >&2
52 fi
53
54 exit "$EXIT_CODE"