diff --git a/bazel/coverage/collect_cc_coverage.sh b/bazel/coverage/collect_cc_coverage.sh index 53926e5cb6aff..f0b85c5c0ddb5 100755 --- a/bazel/coverage/collect_cc_coverage.sh +++ b/bazel/coverage/collect_cc_coverage.sh @@ -41,6 +41,8 @@ # gcda or profraw) and uses either lcov or gcov to get the coverage data. # The coverage data is placed in $COVERAGE_OUTPUT_FILE. +read -ra COVERAGE_GCOV_OPTIONS <<< "${COVERAGE_GCOV_OPTIONS:-}" + # Checks if clang llvm coverage should be used instead of lcov. function uses_llvm() { if stat "${COVERAGE_DIR}"/*.profraw >/dev/null 2>&1; then @@ -68,24 +70,24 @@ function init_gcov() { # $COVERAGE_DIR. # Writes the collected coverage into the given output file. function llvm_coverage() { - local output_file="${1}"; shift + local output_file="${1}" object_file object_files object_param=() + shift export LLVM_PROFILE_FILE="${COVERAGE_DIR}/%h-%p-%m.profraw" "${COVERAGE_GCOV_PATH}" merge -output "${output_file}.data" \ "${COVERAGE_DIR}"/*.profraw - local object_files="$(find -L "${RUNFILES_DIR}" -type f -exec file -L {} \; \ + object_files="$(find -L "${RUNFILES_DIR}" -type f -exec file -L {} \; \ | grep ELF | grep -v "LSB core" | sed 's,:.*,,')" - - local object_param="" + for object_file in ${object_files}; do - object_param+=" -object ${object_file}" + object_param+=(-object "${object_file}") done llvm-cov export -instr-profile "${output_file}.data" -format=lcov \ -ignore-filename-regex='.*external/.+' \ -ignore-filename-regex='/tmp/.+' \ - ${object_param} | sed 's#/proc/self/cwd/##' > "${output_file}" + "${object_param[@]}" | sed 's#/proc/self/cwd/##' > "${output_file}" } # Generates a code coverage report in gcov intermediate text format by invoking @@ -97,17 +99,15 @@ function llvm_coverage() { # - output_file The location of the file where the generated code coverage # report is written. function gcov_coverage() { - local output_file="${1}"; shift - - # We'll save the standard output of each the gcov command in this log. - local gcov_log="$output_file.gcov.log" + local gcda gcno_path line output_file="${1}" + shift # Copy .gcno files next to their corresponding .gcda files in $COVERAGE_DIR # because gcov expects them to be in the same directory. while read -r line; do if [[ ${line: -4} == "gcno" ]]; then gcno_path=${line} - local gcda="${COVERAGE_DIR}/$(dirname ${gcno_path})/$(basename ${gcno_path} .gcno).gcda" + gcda="${COVERAGE_DIR}/$(dirname "${gcno_path}")/$(basename "${gcno_path}" .gcno).gcda" # If the gcda file was not found we skip generating coverage from the gcno # file. if [[ -f "$gcda" ]]; then @@ -115,7 +115,7 @@ function gcov_coverage() { # We overcome this by copying the gcno to $COVERAGE_DIR where the gcda # files are expected to be. if [ ! -f "${COVERAGE_DIR}/${gcno_path}" ]; then - mkdir -p "${COVERAGE_DIR}/$(dirname ${gcno_path})" + mkdir -p "${COVERAGE_DIR}/$(dirname "${gcno_path}")" cp "$ROOT/${gcno_path}" "${COVERAGE_DIR}/${gcno_path}" fi # Invoke gcov to generate a code coverage report with the flags: @@ -134,12 +134,12 @@ function gcov_coverage() { # Don't generate branch coverage (-b) because of a gcov issue that # segfaults when both -i and -b are used (see # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84879). - "${GCOV}" -i $COVERAGE_GCOV_OPTIONS -o "$(dirname ${gcda})" "${gcda}" + "${GCOV}" -i "${COVERAGE_GCOV_OPTIONS[@]}" -o "$(dirname "${gcda}")" "${gcda}" # Append all .gcov files in the current directory to the output file. - cat *.gcov >> "$output_file" + cat ./*.gcov >> "$output_file" # Delete the .gcov files. - rm *.gcov + rm ./*.gcov fi fi done < "${COVERAGE_MANIFEST}" diff --git a/bazel/coverage/fuzz_coverage_wrapper.sh b/bazel/coverage/fuzz_coverage_wrapper.sh index 29ad5e4eea915..f185b7d370831 100755 --- a/bazel/coverage/fuzz_coverage_wrapper.sh +++ b/bazel/coverage/fuzz_coverage_wrapper.sh @@ -9,11 +9,14 @@ shift rm -rf fuzz_corpus mkdir -p fuzz_corpus/seed_corpus -cp -r $@ fuzz_corpus/seed_corpus +cp -r "$@" fuzz_corpus/seed_corpus # TODO(asraa): When fuzz targets are stable, remove error suppression and run coverage while fuzzing. -LLVM_PROFILE_FILE= ${TEST_BINARY} fuzz_corpus -seed=${FUZZ_CORPUS_SEED:-1} -max_total_time=${FUZZ_CORPUS_TIME:-60} -max_len=2048 -rss_limit_mb=8192 -timeout=30 || true +LLVM_PROFILE_FILE='' ${TEST_BINARY} fuzz_corpus -seed="${FUZZ_CORPUS_SEED:-1}" -max_total_time="${FUZZ_CORPUS_TIME:-60}" -max_len=2048 -rss_limit_mb=8192 -timeout=30 || : # Passing files instead of a directory will run fuzzing as a regression test. -# TODO(asraa): Remove manual `|| true`, but this shouldn't be necessary. -${TEST_BINARY} $(find fuzz_corpus -type f) -rss_limit_mb=8192 || true +# TODO(asraa): Remove manual `|| :`, but this shouldn't be necessary. +_CORPUS="$(find fuzz_corpus -type f)" +while read -r line; do CORPUS+=("$line"); done \ + <<< "$_CORPUS" +${TEST_BINARY} "${CORPUS[@]}" -rss_limit_mb=8192 || : diff --git a/bazel/gen_sh_test_runner.sh b/bazel/gen_sh_test_runner.sh index 8e33707db49b6..5665ce9148146 100755 --- a/bazel/gen_sh_test_runner.sh +++ b/bazel/gen_sh_test_runner.sh @@ -14,7 +14,7 @@ TEST_NAME="${RAW_TEST_NAME//./_}" EXEC_ARGS="\"$1\"" shift -for a in $@ +for a in "$@" do EXEC_ARGS="${EXEC_ARGS}, \"$a\"" done diff --git a/bazel/get_workspace_status b/bazel/get_workspace_status index 82bb7593c7f3c..4cfce22fd2d27 100755 --- a/bazel/get_workspace_status +++ b/bazel/get_workspace_status @@ -29,21 +29,14 @@ then fi # The code below presents an implementation that works for git repository -git_rev=$(git rev-parse HEAD) -if [[ $? != 0 ]]; -then - exit 1 -fi +git_rev=$(git rev-parse HEAD) || exit 1 echo "BUILD_SCM_REVISION ${git_rev}" echo "STABLE_BUILD_SCM_REVISION ${git_rev}" # Check whether there are any uncommitted changes -git diff-index --quiet HEAD -- -if [[ $? == 0 ]]; -then - tree_status="Clean" -else +tree_status="Clean" +git diff-index --quiet HEAD -- || { tree_status="Modified" -fi +} echo "BUILD_SCM_STATUS ${tree_status}" echo "STABLE_BUILD_SCM_STATUS ${tree_status}" diff --git a/bazel/setup_clang.sh b/bazel/setup_clang.sh index 0ed987b9d4d0b..d0e58478dc0ab 100755 --- a/bazel/setup_clang.sh +++ b/bazel/setup_clang.sh @@ -9,9 +9,10 @@ if [[ ! -e "${LLVM_PREFIX}/bin/llvm-config" ]]; then exit 1 fi -export PATH="$(${LLVM_PREFIX}/bin/llvm-config --bindir):${PATH}" +PATH="$("${LLVM_PREFIX}"/bin/llvm-config --bindir):${PATH}" +export PATH -RT_LIBRARY_PATH="$(dirname $(find $(llvm-config --libdir) -name libclang_rt.ubsan_standalone_cxx-x86_64.a | head -1))" +RT_LIBRARY_PATH="$(dirname "$(find "$(llvm-config --libdir)" -name libclang_rt.ubsan_standalone_cxx-x86_64.a | head -1)")" echo "# Generated file, do not edit. If you want to disable clang, just delete this file. build:clang --action_env='PATH=${PATH}' @@ -28,5 +29,4 @@ build:clang-asan --linkopt=-fsanitize=vptr,function build:clang-asan --linkopt='-L${RT_LIBRARY_PATH}' build:clang-asan --linkopt=-l:libclang_rt.ubsan_standalone-x86_64.a build:clang-asan --linkopt=-l:libclang_rt.ubsan_standalone_cxx-x86_64.a -" > ${BAZELRC_FILE} - +" > "${BAZELRC_FILE}" diff --git a/bazel/setup_local_tsan.sh b/bazel/setup_local_tsan.sh index c805704af9e8c..a5bd56ceb8127 100755 --- a/bazel/setup_local_tsan.sh +++ b/bazel/setup_local_tsan.sh @@ -15,5 +15,4 @@ build:local-tsan --config=libc++ build:local-tsan --config=clang-tsan build:local-tsan --linkopt=-L${LIBCXX_PREFIX}/lib build:local-tsan --linkopt=-Wl,-rpath,${LIBCXX_PREFIX}/lib -" > ${BAZELRC_FILE} - +" > "${BAZELRC_FILE}" diff --git a/bazel/sh_test_wrapper.sh b/bazel/sh_test_wrapper.sh index 9e2f1138dea73..8a290d6684d55 100755 --- a/bazel/sh_test_wrapper.sh +++ b/bazel/sh_test_wrapper.sh @@ -4,8 +4,8 @@ # TODO(lizan): remove when we have a solution for # https://github.com/bazelbuild/bazel/issues/3510 -cd $(dirname "$0") +cd "$(dirname "$0")" || exit 1 if [ $# -gt 0 ]; then - "./$@" + "./${1}" "${@:2}" fi diff --git a/bazel/test_for_benchmark_wrapper.sh b/bazel/test_for_benchmark_wrapper.sh index 37de6d0d0d810..0a53ca0ada3e6 100755 --- a/bazel/test_for_benchmark_wrapper.sh +++ b/bazel/test_for_benchmark_wrapper.sh @@ -3,4 +3,4 @@ # Set the benchmark time to 0 to just verify that the benchmark runs to # completion. We're interacting with two different flag parsers, so the order # of flags and the -- matters. -"${TEST_SRCDIR}/envoy/$@" --skip_expensive_benchmarks -- --benchmark_min_time=0 +"${TEST_SRCDIR}/envoy/${1}" "${@:2}" --skip_expensive_benchmarks -- --benchmark_min_time=0 diff --git a/ci/build_setup.sh b/ci/build_setup.sh index b7ddcd90cf1f3..b64e85a6b50d1 100755 --- a/ci/build_setup.sh +++ b/ci/build_setup.sh @@ -86,7 +86,9 @@ export LLVM_ROOT="${LLVM_ROOT:-/opt/llvm}" [[ "${BUILD_REASON}" != "PullRequest" ]] && BAZEL_EXTRA_TEST_OPTIONS+=("--nocache_test_results") -export BAZEL_QUERY_OPTIONS="${BAZEL_OPTIONS}" +# TODO(phlax): deprecate/remove this - i believe it was made redundant here: +# https://github.com/envoyproxy/envoy/commit/3ebedeb708a23062332a6fcdf33b462b7070adba#diff-2fa22a1337effee365a51e6844be0ab3 +export BAZEL_QUERY_OPTIONS="${BAZEL_OPTIONS[*]}" # Use https://docs.bazel.build/versions/master/command-line-reference.html#flag--experimental_repository_cache_hardlinks # to save disk space. BAZEL_BUILD_OPTIONS=( diff --git a/examples/cache/start_service.sh b/examples/cache/start_service.sh index 8e2907a2ead95..43a8c112e6362 100644 --- a/examples/cache/start_service.sh +++ b/examples/cache/start_service.sh @@ -1,3 +1,3 @@ #!/bin/sh python3 /code/service.py & -envoy -c /etc/service-envoy.yaml --service-cluster service${SERVICE_NAME} +envoy -c /etc/service-envoy.yaml --service-cluster "service${SERVICE_NAME}" diff --git a/examples/cache/verify.sh b/examples/cache/verify.sh index 422e956569193..15cb42bbc0e4f 100755 --- a/examples/cache/verify.sh +++ b/examples/cache/verify.sh @@ -7,10 +7,12 @@ export NAME=cache check_validated() { # Get the date header and the response generation timestamp - local dates - dates=($(grep -oP '\d\d:\d\d:\d\d' <<< "$1")) + local _dates dates + _dates=$(grep -oP '\d\d:\d\d:\d\d' <<< "$1") + while read -r line; do dates+=("$line"); done \ + <<< "$_dates" # Make sure they are different - if [[ ${dates[0]} == ${dates[1]} ]]; then + if [[ ${dates[0]} == "${dates[1]}" ]]; then echo "ERROR: validated responses should have a date AFTER the generation timestamp" >&2 return 1 fi @@ -31,10 +33,12 @@ check_cached() { check_from_origin() { # Get the date header and the response generation timestamp - local dates - dates=($(grep -oP '\d\d:\d\d:\d\d' <<< "$1")) + local _dates dates + _dates=$(grep -oP '\d\d:\d\d:\d\d' <<< "$1") + while read -r line; do dates+=("$line"); done \ + <<< "$_dates" # Make sure they are equal - if [[ ${dates[0]} != ${dates[1]} ]]; then + if [[ ${dates[0]} != "${dates[1]}" ]]; then echo "ERROR: responses from origin should have a date equal to the generation timestamp" >&2 return 1 fi @@ -65,7 +69,7 @@ response=$(curl -si localhost:8000/service/1/valid-for-minute) check_validated "$response" run_log "Private: Make 4 requests make sure they are all served by the origin" -for i in {0..3} +for _ in {0..3} do response=$(curl -si localhost:8000/service/1/private) check_from_origin "$response" @@ -76,7 +80,7 @@ response=$(curl -si localhost:8000/service/1/no-cache) check_from_origin "$response" run_log "No-cache: Make 4 more requests and make sure they are all validated before being served from cache" -for i in {0..3} +for _ in {0..3} do sleep 1 response=$(curl -si localhost:8000/service/1/no-cache) diff --git a/examples/front-proxy/start_service.sh b/examples/front-proxy/start_service.sh index cc529bcf2b157..43a8c112e6362 100644 --- a/examples/front-proxy/start_service.sh +++ b/examples/front-proxy/start_service.sh @@ -1,3 +1,3 @@ #!/bin/sh python3 /code/service.py & -envoy -c /etc/service-envoy.yaml --service-cluster service${SERVICE_NAME} \ No newline at end of file +envoy -c /etc/service-envoy.yaml --service-cluster "service${SERVICE_NAME}" diff --git a/examples/load-reporting-service/send_requests.sh b/examples/load-reporting-service/send_requests.sh index b65b284890677..d8cf8f9e8721d 100644 --- a/examples/load-reporting-service/send_requests.sh +++ b/examples/load-reporting-service/send_requests.sh @@ -2,11 +2,11 @@ counter=1 while [ $counter -le 50 ] -do +do # generate random Port number to send requests ports=("80" "81") port=${ports[$RANDOM % ${#ports[@]} ]} - curl -v localhost:$port/service + curl -v "localhost:${port}/service" ((counter++)) -done \ No newline at end of file +done diff --git a/examples/load-reporting-service/start_service.sh b/examples/load-reporting-service/start_service.sh index da0b0c47096b0..3fa5d85f7a371 100644 --- a/examples/load-reporting-service/start_service.sh +++ b/examples/load-reporting-service/start_service.sh @@ -1,3 +1,3 @@ -#!/bin/sh +#!/bin/bash python3 /code/http_server.py & -/usr/local/bin/envoy -c /etc/service-envoy-w-lrs.yaml --service-node ${HOSTNAME} --service-cluster http_service +/usr/local/bin/envoy -c /etc/service-envoy-w-lrs.yaml --service-node "${HOSTNAME}" --service-cluster http_service diff --git a/test/integration/hotrestart_test.sh b/test/integration/hotrestart_test.sh index a83420461bb47..69d7ccac336e4 100755 --- a/test/integration/hotrestart_test.sh +++ b/test/integration/hotrestart_test.sh @@ -78,10 +78,10 @@ echo "Hot restart test using dynamic base id" TEST_INDEX=0 function run_testsuite() { - local BASE_ID BASE_ID_PATH HOT_RESTART_JSON="$1" FAKE_SYMBOL_TABLE="$2" + local BASE_ID BASE_ID_PATH HOT_RESTART_JSON="$1" FAKE_SYMBOL_TABLE="$2" local SOCKET_PATH=@envoy_domain_socket local SOCKET_MODE=0 - if [ ! -z "$3" ] && [ ! -z "$4" ] + if [ -n "$3" ] && [ -n "$4" ] then SOCKET_PATH="$3" SOCKET_MODE="$4" diff --git a/tools/code_format/check_shellcheck_format.sh b/tools/code_format/check_shellcheck_format.sh index 8b26e7064ed40..fa62b3dc4695d 100755 --- a/tools/code_format/check_shellcheck_format.sh +++ b/tools/code_format/check_shellcheck_format.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -EXCLUDED_SHELLFILES=${EXCLUDED_SHELLFILES:-"^examples|^bin|^source|^bazel|^.github"} +EXCLUDED_SHELLFILES=${EXCLUDED_SHELLFILES:-"^.github|.rst$|.md$"} find_shell_files () {