Skip to content

Commit 1b7ba74

Browse files
committed
check-missing-files: handle multi-disk file paths
Use a proper XML parser (python3 xml.etree, part of stdlib) instead of sed to extract file_name and file_path from contents.xml, combining them into relative paths. Match known filenames against the basename so that files in storage-type subdirectories (e.g. spinor/gpt_main0.bin) are recognized correctly, while checking existence with the full path. Don't check presence of sail_nor/ files that ptool might generate as these are not currently generated. Signed-off-by: Loïc Minier <loic.minier@oss.qualcomm.com>
1 parent 3204087 commit 1b7ba74

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

tests/integration/check-missing-files

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# SPDX-License-Identifier: BSD-3-Clause-Clear
44

55
# Takes rawprogram*.xml and contents.xml files as arguments, collects the
6-
# filenames referenced, and checks if any gpt_* or zeros_* file is missing
6+
# filenames referenced, and checks if any gpt_* or zeros_* file is missing and
7+
# if the filenames are known
78

89
set -eu
910

@@ -14,15 +15,36 @@ for xml in "$@"; do
1415
rawprogram_filenames="$(
1516
sed -En 's:.*filename="([^"]+)".*:\1:p' "${xml}"
1617
)"
18+
# for contents.xml, extract file_path/file_name pairs as relative paths
1719
contents_filenames="$(
18-
sed -En 's:.*<file_name>([^<]+)</file_name>.*:\1:p' "${xml}"
20+
python3 -c "
21+
import xml.etree.ElementTree as ET, sys
22+
tree = ET.parse(sys.argv[1])
23+
for el in tree.iter():
24+
fn = el.find('file_name')
25+
fp = el.find('file_path')
26+
if fn is not None and fn.text:
27+
# construct relative path by combining file_path and file_name, but only
28+
# if file_path is non-empty and not '.'
29+
path = fp.text.rstrip('/') if fp is not None and fp.text and fp.text != '.' else ''
30+
print(path + '/' + fn.text if path else fn.text)
31+
" "${xml}" 2>/dev/null
1932
)"
2033
for file in $(
2134
echo ${rawprogram_filenames} ${contents_filenames} | sort -u
2235
); do
23-
case "${file}" in
24-
# expected files that should be generated by ptool
36+
# for matching known filenames, use the basename (strip subdir from
37+
# contents.xml file_path); for checking file existence, use the
38+
# full relative path
39+
basename="${file##*/}"
40+
case "${basename}" in
41+
# expected files that should be generated by ptool: test if present
2542
gpt_*|zeros_*|patch*.xml|rawprogram*.xml)
43+
# except we don't generate SAIL programming files at the moment, so
44+
# don't test if these are present
45+
if [ "${file%/*}" = "./sail_nor" ]; then
46+
continue
47+
fi
2648
if ! [ -r "${dir}/${file}" ]; then
2749
errors=yes
2850
echo "Missing ${file} referenced in ${xml}" >&2

0 commit comments

Comments
 (0)