aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Nikitin <denik@google.com>2022-03-07 17:45:25 -0800
committerCommit Bot <commit-bot@chromium.org>2022-03-08 18:16:54 +0000
commit1222bbbd4bc1d31bffb9f15bd9d0e5948f1f2b06 (patch)
treeed5b5752102f20da79f832ce88cdcb4fcac2648f
parentd2b64f8ce4424f30a8cc268c1cfbd0f71d2631e3 (diff)
downloadtoolchain-utils-1222bbbd4bc1d31bffb9f15bd9d0e5948f1f2b06.tar.gz
update_kernel_afdo: Fix lint errors
BUG=b:221882737 TEST=cros lint afdo_tools/update_kernel_afdo Change-Id: Ib4c5a19531400d8cad1060679cf167397ddb4540 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3508820 Reviewed-by: Manoj Gupta <manojgupta@chromium.org> Tested-by: Denis Nikitin <denik@chromium.org> Commit-Queue: Denis Nikitin <denik@chromium.org>
-rwxr-xr-xafdo_tools/update_kernel_afdo67
1 files changed, 33 insertions, 34 deletions
diff --git a/afdo_tools/update_kernel_afdo b/afdo_tools/update_kernel_afdo
index ff0ab224..3944407c 100755
--- a/afdo_tools/update_kernel_afdo
+++ b/afdo_tools/update_kernel_afdo
@@ -9,7 +9,7 @@
#
USAGE="
-Usage: $(basename $0) [main|beta|stable|all] [--help]
+Usage: $(basename "$0") [main|beta|stable|all] [--help]
Description:
The script takes one optional argument which is the channel where we want
@@ -36,7 +36,7 @@ metadata_dir="${tc_utils_dir}/afdo_metadata"
outfile="$(realpath --relative-to="${tc_utils_dir}" \
"${metadata_dir}"/kernel_afdo.json)"
# Convert toolchain_utils into the absolute path.
-abs_tc_utils_dir="$(realpath ${tc_utils_dir})"
+abs_tc_utils_dir="$(realpath "${tc_utils_dir}")"
# Check profiles uploaded within the last week.
expected_time=$(date +%s -d "week ago")
@@ -47,10 +47,9 @@ canary_ref="refs/heads/main"
# Read the last two release-Rxx from remote branches
# and assign them to stable_ref and beta_ref.
# sort -V is the version sort which puts R100 after R99.
-last_branches=$(git -C "${tc_utils_dir}" ls-remote -h "${remote_repo}" \
- release-R\* | cut -f2 | sort -V | tail -n 2)
# We need `echo` to convert newlines into spaces for read.
-read stable_ref beta_ref <<< $(echo ${last_branches})
+read -r stable_ref beta_ref <<< "$(git -C "${tc_utils_dir}" ls-remote -h \
+ "${remote_repo}" release-R\* | cut -f2 | sort -V | tail -n 2 | paste -s)"
# Branch names which start from release-R.
branch["beta"]=${beta_ref##*/}
branch["stable"]=${stable_ref##*/}
@@ -62,8 +61,8 @@ branch_number["stable"]=$(echo "${branch["stable"]}" | \
branch_number["beta"]=$(echo "${branch["beta"]}" | \
sed -n -e "s/^release-R\([0-9][0-9]*\).*$/\1/p")
branch_number["canary"]="$((branch_number[beta] + 1))"
-for skipped_branch in $SKIPPED_BRANCHES ; do
- if [[ ${branch_number["canary"]} == $skipped_branch ]] ; then
+for skipped_branch in ${SKIPPED_BRANCHES} ; do
+ if [[ ${branch_number["canary"]} == "${skipped_branch}" ]] ; then
((branch_number[canary]++))
fi
done
@@ -80,13 +79,13 @@ case "${channels}" in
channels="canary beta stable"
;;
--help | help | -h )
- echo "$USAGE"
+ echo "${USAGE}"
exit 0
;;
* )
echo "Channel \"${channels}\" is not supported.
Must be main (or canary), beta, stable or all." >&2
- echo "$USAGE"
+ echo "${USAGE}"
exit 1
esac
@@ -99,7 +98,7 @@ echo "-> Working in ${worktree_dir}"
# This way we don't need to clean-up and sync toolchain_utils before the
# change. Neither we should care about clean-up after the submit.
git -C "${tc_utils_dir}" worktree add --detach "${worktree_dir}"
-trap "git -C ${abs_tc_utils_dir} worktree remove ${worktree_dir}" EXIT
+trap 'git -C "${abs_tc_utils_dir}" worktree remove "${worktree_dir}"' EXIT
cd "${worktree_dir}"
for channel in ${channels}
@@ -113,39 +112,39 @@ do
echo "branch_number=${curr_branch_number} branch=${curr_branch}"
json="{"
sep=""
- for kver in $KVERS
+ for kver in ${KVERS}
do
# Sort the gs output by timestamp (default ordering is by name, so
# R86-13310.3-1594633089.gcov.xz goes after R86-13310.18-1595237847.gcov.xz)
- latest=$(gsutil.py ls -l "$GS_BASE/$kver/" | sort -k2 | \
+ latest=$(gsutil.py ls -l "${GS_BASE}/${kver}/" | sort -k2 | \
grep "R${curr_branch_number}" | tail -1 || true)
- if [[ -z "$latest" && "${channel}" != "stable" ]]
+ if [[ -z "${latest}" && "${channel}" != "stable" ]]
then
# if no profiles exist for the current branch, try the previous branch
- latest=$(gsutil.py ls -l "$GS_BASE/$kver/" | sort -k2 | \
+ latest=$(gsutil.py ls -l "${GS_BASE}/${kver}/" | sort -k2 | \
grep "R$((curr_branch_number - 1))" | tail -1)
fi
# Verify that the file has the expected date.
- file_time=$(echo "$latest" | awk '{print $2}')
- file_time_unix=$(date +%s -d "$file_time")
- if [ $file_time_unix -lt $expected_time ]
+ file_time=$(echo "${latest}" | awk '{print $2}')
+ file_time_unix=$(date +%s -d "${file_time}")
+ if [ "${file_time_unix}" -lt "${expected_time}" ]
then
- expected=$(env TZ=UTC date +%Y-%m-%dT%H:%M:%SZ -d @$expected_time)
- echo "Wrong date for $kver: $file_time is before $expected" >&2
- errs="$errs $kver"
+ expected=$(env TZ=UTC date +%Y-%m-%dT%H:%M:%SZ -d @"${expected_time}")
+ echo "Wrong date for ${kver}: ${file_time} is before ${expected}" >&2
+ errs="${errs} ${kver}"
continue
fi
# Generate JSON.
- json_kver=$(echo "$kver" | tr . _)
+ json_kver=$(echo "${kver}" | tr . _)
# b/147370213 (migrating profiles from gcov format) may result in the
# pattern below no longer doing the right thing.
- name=$(echo "$latest" | sed 's%.*/\(.*\)\.gcov.*%\1%')
+ name="$(basename "${latest%.gcov.*}")"
json=$(cat <<EOT
-$json$sep
- "chromeos-kernel-$json_kver": {
- "name": "$name"
+${json}${sep}
+ "chromeos-kernel-${json_kver}": {
+ "name": "${name}"
}
EOT
)
@@ -154,7 +153,7 @@ EOT
done
# If we did not succeed for any kvers, exit now.
- if [[ $successes -eq 0 ]]
+ if [[ ${successes} -eq 0 ]]
then
echo "error: AFDO profiles out of date for all kernel versions" >&2
failed_channels="${failed_channels} ${channel}"
@@ -167,18 +166,18 @@ EOT
# Write new JSON file.
# Don't use `echo` since `json` might have esc characters in it.
- printf "%s\n}\n" "$json" > "$outfile"
+ printf "%s\n}\n" "${json}" > "${outfile}"
# If no changes were made, say so.
- outdir=$(dirname "$outfile")
- shortstat=$(cd "$outdir" && git status --short $(basename "$outfile"))
- [ -z "$shortstat" ] && echo $(basename "$outfile")" is up to date." \
+ outdir=$(dirname "${outfile}")
+ shortstat=$(cd "${outdir}" && git status --short "$(basename "${outfile}")")
+ [ -z "${shortstat}" ] && echo "$(basename "${outfile}") is up to date." \
&& continue
# If we had any errors, warn about them.
- if [[ -n "$errs" ]]
+ if [[ -n "${errs}" ]]
then
- echo "warning: failed to update $errs in ${channel}" >&2
+ echo "warning: failed to update ${errs} in ${channel}" >&2
failed_channels="${failed_channels} ${channel}"
continue
fi
@@ -221,10 +220,10 @@ set +u
if [[ ${#commit[@]} -gt 0 ]]
then
set -u
- echo "The change is applied in ${!commit[@]}."
+ echo "The change is applied in ${!commit[*]}."
echo "Run these commands to submit the change:"
echo
- for channel in ${!commit[@]}
+ for channel in "${!commit[@]}"
do
echo -e "\tgit -C ${tc_utils_dir} push ${remote_repo} \
${commit[${channel}]}:refs/for/${branch[${channel}]}"