Skip to content

Commit 7666aca

Browse files
committed
enhance(scripts/lint-packages.sh): optimize handling of version arrays
1 parent bcd85f7 commit 7666aca

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

scripts/lint-packages.sh

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,11 @@ check_version() {
140140
} >&2
141141

142142
# If TERMUX_PKG_VERSION is an array that changes the formatting.
143-
local version i=-1 error=0 is_array="${TERMUX_PKG_VERSION@a}"
143+
local version i=0 error=0 is_array="${TERMUX_PKG_VERSION@a}"
144144
printf '%s' "${is_array:+$'ARRAY\n'}"
145145

146146
for version in "${TERMUX_PKG_VERSION[@]}"; do
147147
printf '%s' "${is_array:+$'\t'}"
148-
(( i++ ))
149148

150149
# Is this version valid?
151150
dpkg --validate-version "${version}" &> /dev/null || {
@@ -154,34 +153,39 @@ check_version() {
154153
continue
155154
}
156155

157-
# Was the package modified in this branch?
158-
git diff --exit-code "${base_commit}" -- "${package_dir}" &> /dev/null && {
159-
printf '%s\n' "PASS - ${version} (not modified in this branch)"
160-
continue
161-
}
162-
163156
local version_new version_old
164157
version_new="${version}-${TERMUX_PKG_REVISION:-0}"
165158
version_old=$(
166159
unset TERMUX_PKG_VERSION TERMUX_PKG_REVISION
167160
# shellcheck source=/dev/null
168161
. <(git -P show "${base_commit}:${package_dir}/build.sh" 2> /dev/null)
169-
if [[ -n "$is_array" ]]; then
170-
echo "${TERMUX_PKG_VERSION[$i]:-0}-${TERMUX_PKG_REVISION:-0}"
171-
else
172-
echo "${TERMUX_PKG_VERSION:-0}-${TERMUX_PKG_REVISION:-0}"
173-
fi
162+
# ${TERMUX_PKG_VERSION[0]} also works fine for non-array versions.
163+
# Since those resolve in 1 iteration, no higher index is ever attempted to be called.
164+
echo "${TERMUX_PKG_VERSION[$i]:-0}-${TERMUX_PKG_REVISION:-0}"
174165
)
175166

176167
# Is ${version_old} valid?
177168
local version_old_is_bad=""
178169
dpkg --validate-version "${version_old}" &> /dev/null || version_old_is_bad="0~invalid"
179170

171+
# The rest of the checks aren't useful past the first index when $TERMUX_PKG_VERSION is an array
172+
# since that is the index that determines the actual version.
173+
if (( i++ > 0 )); then
174+
echo "PASS - ${version_old%-0}${version_old_is_bad:+" (INVALID)"} -> ${version_new%-0}"
175+
continue
176+
fi
177+
178+
# Was the package modified in this branch?
179+
git diff --exit-code "${base_commit}" -- "${package_dir}" &> /dev/null && {
180+
printf '%s\n' "PASS - ${version} (not modified in this branch)"
181+
return 0
182+
}
183+
180184
# If ${version_new} isn't greater than "$version_old" that's an issue.
181185
# If ${version_old} isn't valid this check is a no-op.
182186
if dpkg --compare-versions "$version_new" le "${version_old_is_bad:-$version_old}"; then
183187
printf '%s\n' \
184-
"FAILED" \
188+
"FAILED ${version_old_is_bad:-$version_old} -> ${version_new}" \
185189
"" \
186190
"Version of '$package_name' has not been incremented." \
187191
"Either 'TERMUX_PKG_VERSION' or 'TERMUX_PKG_REVISION'" \
@@ -218,9 +222,7 @@ check_version() {
218222
continue
219223
# If that check passed the TERMUX_PKG_VERSION must have changed,
220224
# in which case TERMUX_PKG_REVISION should be reset to 0.
221-
# This check isn't useful past the first index when $TERMUX_PKG_VERSION is an array
222-
# since the main version of such a package may remain unchanged when another is changed.
223-
elif [[ "${version_new%-*}" != "${version_old%-*}" && "$new_revision" != "0" && "$i" == 0 ]]; then
225+
elif [[ "${version_new%-*}" != "${version_old%-*}" && "$new_revision" != "0" ]]; then
224226
(( error++ )) # Not reset
225227
printf '%s\n' \
226228
"FAILED - $version_old -> $version_new" \

0 commit comments

Comments
 (0)