Skip to content

Commit 9c78a79

Browse files
AndrobinCopybara-Service
authored and
Copybara-Service
committed
Various Shell Script Fixes and Improvements - Part One
see bazelbuild#4023 Closes bazelbuild#4051. PiperOrigin-RevId: 177279457
1 parent ff62e1d commit 9c78a79

File tree

14 files changed

+26
-24
lines changed

14 files changed

+26
-24
lines changed

scripts/bash_completion_test.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ expand() {
6868
#
6969
# Alias expansion still inserts an extra space after 'blaze',
7070
# though, hence the following sed. Not sure why.
71-
for i in ${COMMAND_ALIASES[@]}; do
71+
for i in "${COMMAND_ALIASES[@]}"; do
7272
echo "alias $i=\"echo $i'\""
7373
done
7474
echo -en "$input'"
@@ -82,7 +82,7 @@ expand() {
8282
# e.g. assert_expansion 'foo' 'foo_expand' 'flag1=bar;flag2=baz'
8383
assert_expansion() {
8484
local prefix=$1 expected=$2 flags=${3:-}
85-
for i in ${COMMAND_ALIASES[@]}; do
85+
for i in "${COMMAND_ALIASES[@]}"; do
8686
local nprefix="$i $prefix"
8787
local nexpected="$i $expected"
8888
assert_equals "$nexpected" "$(expand "$nprefix\t" "$flags" "/dev/null")"
@@ -100,7 +100,7 @@ assert_expansion() {
100100
assert_expansion_error_not_contains() {
101101
local prefix=$1 not_expected=$2 flags=${3:-}
102102
local temp_file="$(mktemp "${TEST_TMPDIR}/tmp.stderr.XXXXXX")"
103-
for i in ${COMMAND_ALIASES[@]}; do
103+
for i in "${COMMAND_ALIASES[@]}"; do
104104
local nprefix="$i "
105105
expand "$nprefix\t" "$flags" "$temp_file" > /dev/null
106106
assert_not_contains "$not_expected" "$temp_file"

scripts/bootstrap/compile.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ PROTO_FILES=$(ls src/main/protobuf/*.proto src/main/java/com/google/devtools/bui
2020
LIBRARY_JARS=$(find third_party -name '*.jar' | grep -Fv /javac-9-dev-r3297-4.jar | grep -Fv /javac-9-dev-4023-3.jar | grep -Fv /javac7.jar | grep -Fv JavaBuilder | grep -Fv third_party/guava | grep -Fv third_party/guava | grep -ve third_party/grpc/grpc.*jar | tr "\n" " ")
2121
GRPC_JAVA_VERSION=1.7.0
2222
GRPC_LIBRARY_JARS=$(find third_party/grpc -name '*.jar' | grep -e .*${GRPC_JAVA_VERSION}.*jar | tr "\n" " ")
23-
GUAVA_VERSIONE=23.1
23+
GUAVA_VERSION=23.1
2424
GUAVA_JARS=$(find third_party/guava -name '*.jar' | grep -e .*${GUAVA_VERSION}.*jar | tr "\n" " ")
2525
LIBRARY_JARS="${LIBRARY_JARS} ${GRPC_LIBRARY_JARS} ${GUAVA_JARS}"
2626

@@ -41,7 +41,7 @@ if [ "$ERROR_PRONE_INDEX" -lt "$GUAVA_INDEX" ]; then
4141
TEMP_FOR_SWAP="${LIBRARY_JARS_ARRAY[$ERROR_PRONE_INDEX]}"
4242
LIBRARY_JARS_ARRAY[$ERROR_PRONE_INDEX]="${LIBRARY_JARS_ARRAY[$GUAVA_INDEX]}"
4343
LIBRARY_JARS_ARRAY[$GUAVA_INDEX]="$TEMP_FOR_SWAP"
44-
LIBRARY_JARS="${LIBRARY_JARS_ARRAY[@]}"
44+
LIBRARY_JARS="${LIBRARY_JARS_ARRAY[*]}"
4545
fi
4646

4747
DIRS=$(echo src/{java_tools/singlejar/java/com/google/devtools/build/zip,main/java,tools/xcode-common/java/com/google/devtools/build/xcode/{common,util}} third_party/java/dd_plist/java ${OUTPUT_DIR}/src)

scripts/release/release.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ function create_release_commit() {
122122
function apply_cherry_picks() {
123123
echo "Applying cherry-picks"
124124
# Apply cherry-picks
125-
for i in $@; do
125+
for commit in "$@"; do
126126
local previous_head="$(git rev-parse HEAD)"
127-
echo " Cherry-picking $i"
128-
git cherry-pick $i >/dev/null || {
129-
echo "Failed to cherry-pick $i. please resolve the conflict and exit." >&2
127+
echo " Cherry-picking ${commit}"
128+
git cherry-pick ${commit} >/dev/null || {
129+
echo "Failed to cherry-pick ${commit}. please resolve the conflict and exit." >&2
130130
echo " Use 'git cherry-pick --abort; exit' to abort the cherry-picks." >&2
131131
echo " Use 'git cherry-pick --continue; exit' to resolve the conflict." >&2
132132
bash
@@ -137,7 +137,7 @@ function apply_cherry_picks() {
137137
}
138138
# Add the origin of the cherry-pick in case the patch-id diverge and we cannot
139139
# find the original commit.
140-
git notes --ref=cherrypick add -f -m "$i"
140+
git notes --ref=cherrypick add -f -m "${commit}"
141141
done
142142
return 0
143143
}
@@ -147,9 +147,9 @@ function find_last_release() {
147147
local branch="${1:-HEAD}"
148148
local baseline="${2:-$(get_release_baseline "${branch}")}"
149149
local changes="$(git log --pretty=format:%H "${baseline}~".."${branch}")"
150-
for i in ${changes}; do
151-
if git notes --ref=release show $i &>/dev/null; then
152-
echo $i
150+
for change in ${changes}; do
151+
if git notes --ref=release show ${change} &>/dev/null; then
152+
echo ${change}
153153
return 0
154154
fi
155155
done

scripts/release/relnotes.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ function generate_release_notes() {
100100
for i in "${RELNOTES_TYPES[@]}"; do
101101
eval "RELNOTES_${i}=()"
102102
done
103-
for i in $@; do
104-
extract_release_note $i
103+
for commit in $@; do
104+
extract_release_note "${commit}"
105105
done
106106
}
107107

src/test/shell/bazel/workspace_test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ genrule(
104104
EOF
105105
bazel fetch //:test || fail "Fetch failed"
106106
bazel build //:test || echo "Expected build to succeed"
107-
check_eq "12" "$(cat bazel-genfiles/test.out | tr -d '[[:space:]]')"
107+
check_eq "12" "$(cat bazel-genfiles/test.out | tr -d '[:space:]')"
108108
}
109109

110110
# Regression test for issue #724: NullPointerException in WorkspaceFile

src/test/shell/integration/java_integration_test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ EOF
270270
cp ${PRODUCT_NAME}-bin/$pkg/java/hello/hello_deploy.jar $pkg/ugly/
271271

272272
$pkg/ugly/hello build.target build.time build.timestamp \
273-
main.class=hello.Hello "$expected_build_data" 2>&1 >>$TEST_log
273+
main.class=hello.Hello "$expected_build_data" >> $TEST_log 2>&1
274274
expect_log 'Hello, World!'
275275
}
276276

src/test/shell/integration/loading_phase_tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function test_all_help_topics_succeed() {
131131
awk '{print $1}') \
132132
startup_options \
133133
target-syntax)
134-
for topic in ${topics[@]}; do
134+
for topic in "${topics[@]}"; do
135135
bazel help $topic >$TEST_log 2>&1 || {
136136
fail "help $topic failed"
137137
expect_not_log . # print the log

src/test/shell/integration/progress_reporting_test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ set -eu
2525

2626
# TODO(b/37617303): make tests UI-independent
2727
add_to_bazelrc "build --noexperimental_ui"
28-
add_to_bazelrc "build --workspace_status_command="$(which true)" --nostamp"
28+
add_to_bazelrc "build --workspace_status_command=$(which true) --nostamp"
2929
add_to_bazelrc "build --show_progress_rate_limit=-1"
3030
add_to_bazelrc "build --genrule_strategy=local"
3131

src/test/shell/integration_test_setup.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function print_message_and_exit() {
2222
CURRENT_SCRIPT=${BASH_SOURCE[0]}
2323
# Go to the directory where the script is running
2424
cd "$(dirname ${CURRENT_SCRIPT})" \
25-
|| print_message_and_exit "Unable to access "$(dirname ${CURRENT_SCRIPT})""
25+
|| print_message_and_exit "Unable to access $(dirname ${CURRENT_SCRIPT})"
2626

2727
DIR=$(pwd)
2828
# Load the unit test framework

src/test/shell/testenv.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ function cleanup_workspace() {
472472
cd ${WORKSPACE_DIR}
473473
bazel clean >> $TEST_log 2>&1 # Clean up the output base
474474

475-
for i in $(ls); do
475+
for i in *; do
476476
if ! is_tools_directory "$i"; then
477477
rm -fr "$i"
478478
fi

src/tools/xcode/actoolwrapper/actoolwrapper.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ trap "rm -rf \"$TEMPDIR\"" EXIT
4040

4141
TOOLARGS=()
4242
LASTARG=""
43-
for i in $@; do
43+
for i in "$@"; do
4444
if [ "$LASTARG" = "--output-partial-info-plist" ]; then
4545
touch "$i"
4646
fi

src/tools/xcode/environment/environment_plist.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
set -eu
2727

28-
while [[ $# > 1 ]]
28+
while [[ $# -gt 1 ]]
2929
do
3030
key="$1"
3131

src/tools/xcode/ibtoolwrapper/ibtoolwrapper.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ TOOLARGS=()
5656
# By default, have ibtool compile storyboards (to stay compatible with the
5757
# native rules). If the command line includes "--link", we use it instead.
5858
ACTION=--compile
59-
for i in $@; do
59+
for i in "$@"; do
6060
if [ -e "$i" ]; then
6161
if [[ "$i" == *.zip ]]; then
6262
unzip -qq "$i" -d "$LINKDIR"

tools/genrule/genrule-setup.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/bash
2+
13
# Copyright 2017 The Bazel Authors. All rights reserved.
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");

0 commit comments

Comments
 (0)