From ef175ea594624e264a82a19f6e3126a32e712256 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Tue, 10 Sep 2024 18:49:51 +0100 Subject: [PATCH] ci: Make section emission really quiet If you're emitting a section header under set -x, you will see: + section_start foo "foo" + x_off [the section header] This is kind of annoying. Instead of trying to squash it everywhere by dancing around local set +x management, play some extremely stupid tricks with shells to make sure we never emit it. Signed-off-by: Daniel Stone Part-of: --- .gitlab-ci/cuttlefish-runner.sh | 3 ++ .gitlab-ci/deqp-runner.sh | 3 ++ .gitlab-ci/gtest-runner.sh | 3 ++ .gitlab-ci/lava/lava-submit.sh | 3 ++ .gitlab-ci/meson/build.sh | 3 ++ .gitlab-ci/piglit/piglit-runner.sh | 3 ++ .gitlab-ci/piglit/piglit-traces.sh | 3 ++ .gitlab-ci/prepare-artifacts.sh | 3 ++ .gitlab-ci/run-shader-db.sh | 4 ++ .gitlab-ci/setup-test-env.sh | 62 ++++++++++++++++-------------- .gitlab-ci/vkd3d-runner.sh | 3 ++ 11 files changed, 65 insertions(+), 28 deletions(-) diff --git a/.gitlab-ci/cuttlefish-runner.sh b/.gitlab-ci/cuttlefish-runner.sh index 44da4a82fa7..b7c3c880666 100755 --- a/.gitlab-ci/cuttlefish-runner.sh +++ b/.gitlab-ci/cuttlefish-runner.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash # shellcheck disable=SC2086 # we want word splitting +# shellcheck disable=SC1091 # paths only become valid at runtime + +. "${SCRIPTS_DIR}/setup-test-env.sh" section_start cuttlefish_setup "cuttlefish: setup" set -xe diff --git a/.gitlab-ci/deqp-runner.sh b/.gitlab-ci/deqp-runner.sh index 09f8c85a4d9..f41e3d58d39 100755 --- a/.gitlab-ci/deqp-runner.sh +++ b/.gitlab-ci/deqp-runner.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash # shellcheck disable=SC2086 # we want word splitting +# shellcheck disable=SC1091 # paths only become valid at runtime + +. "${SCRIPTS_DIR}/setup-test-env.sh" section_start test_setup "deqp: preparing test setup" diff --git a/.gitlab-ci/gtest-runner.sh b/.gitlab-ci/gtest-runner.sh index 1cfa80fecc6..b55e581a341 100755 --- a/.gitlab-ci/gtest-runner.sh +++ b/.gitlab-ci/gtest-runner.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash # shellcheck disable=SC2086 # we want word splitting +# shellcheck disable=SC1091 # paths only become valid at runtime + +. "${SCRIPTS_DIR}/setup-test-env.sh" set -ex diff --git a/.gitlab-ci/lava/lava-submit.sh b/.gitlab-ci/lava/lava-submit.sh index db44a8e8ad3..4931c6f15cd 100755 --- a/.gitlab-ci/lava/lava-submit.sh +++ b/.gitlab-ci/lava/lava-submit.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash # shellcheck disable=SC2086 # we want word splitting +# shellcheck disable=SC1091 # paths only become valid at runtime + +. "${SCRIPTS_DIR}/setup-test-env.sh" section_start prepare_rootfs "Preparing root filesystem" diff --git a/.gitlab-ci/meson/build.sh b/.gitlab-ci/meson/build.sh index 479c4becb6d..bbe63e79c9b 100755 --- a/.gitlab-ci/meson/build.sh +++ b/.gitlab-ci/meson/build.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash # shellcheck disable=SC1003 # works for us now... # shellcheck disable=SC2086 # we want word splitting +# shellcheck disable=SC1091 # paths only become valid at runtime + +. "${SCRIPTS_DIR}/setup-test-env.sh" section_switch meson-cross-file "meson: cross file generate" diff --git a/.gitlab-ci/piglit/piglit-runner.sh b/.gitlab-ci/piglit/piglit-runner.sh index c8aef9f198d..b786e4b9082 100755 --- a/.gitlab-ci/piglit/piglit-runner.sh +++ b/.gitlab-ci/piglit/piglit-runner.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash # shellcheck disable=SC2086 # we want word splitting +# shellcheck disable=SC1091 # paths only become valid at runtime + +. "${SCRIPTS_DIR}/setup-test-env.sh" set -ex diff --git a/.gitlab-ci/piglit/piglit-traces.sh b/.gitlab-ci/piglit/piglit-traces.sh index 76a51f60387..b689294d061 100755 --- a/.gitlab-ci/piglit/piglit-traces.sh +++ b/.gitlab-ci/piglit/piglit-traces.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash # shellcheck disable=SC2035 # FIXME glob # shellcheck disable=SC2086 # we want word splitting +# shellcheck disable=SC1091 # paths only become valid at runtime + +. "${SCRIPTS_DIR}/setup-test-env.sh" section_start traces_prepare "traces: preparing test setup" diff --git a/.gitlab-ci/prepare-artifacts.sh b/.gitlab-ci/prepare-artifacts.sh index a1c67cf69ab..622e18bca21 100755 --- a/.gitlab-ci/prepare-artifacts.sh +++ b/.gitlab-ci/prepare-artifacts.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash # shellcheck disable=SC2038 # TODO: rewrite the find # shellcheck disable=SC2086 # we want word splitting +# shellcheck disable=SC1091 # paths only become valid at runtime + +. "${SCRIPTS_DIR}/setup-test-env.sh" section_switch prepare-artifacts "artifacts: prepare" diff --git a/.gitlab-ci/run-shader-db.sh b/.gitlab-ci/run-shader-db.sh index c4a9680a696..8a53c74b6b4 100755 --- a/.gitlab-ci/run-shader-db.sh +++ b/.gitlab-ci/run-shader-db.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash +# shellcheck disable=SC1091 # paths only become valid at runtime + set -e +. "${SCRIPTS_DIR}/setup-test-env.sh" + ARTIFACTSDIR=$(pwd)/shader-db mkdir -p "$ARTIFACTSDIR" export DRM_SHIM_DEBUG=true diff --git a/.gitlab-ci/setup-test-env.sh b/.gitlab-ci/setup-test-env.sh index c2b7f045130..a150bcaff92 100644 --- a/.gitlab-ci/setup-test-env.sh +++ b/.gitlab-ci/setup-test-env.sh @@ -3,7 +3,9 @@ # shellcheck disable=SC2086 # we want word splitting # shellcheck disable=SC2155 # mktemp usually not failing -function x_off { +shopt -s expand_aliases + +function _x_off { if [[ "$-" == *"x"* ]]; then state_x=1 set +x @@ -12,6 +14,8 @@ function x_off { fi } +alias x_off='{ _x_off; } >/dev/null 2>/dev/null' + # TODO: implement x_on ! export JOB_START_S=$(date -u +"%s" -d "${CI_JOB_STARTED_AT:?}") @@ -27,7 +31,7 @@ function error { RED="\e[0;31m" ENDCOLOR="\e[0m" # we force the following to be not in a section - section_end $CURRENT_SECTION + _section_end $CURRENT_SECTION CURR_MINSEC=$(get_current_minsec) echo -e "\n${RED}[${CURR_MINSEC}] ERROR: $*${ENDCOLOR}\n" @@ -38,7 +42,7 @@ function trap_err { error ${CURRENT_SECTION:-'unknown-section'}: ret code: $* } -function build_section_start { +function _build_section_start { local section_params=$1 shift local section_name=$1 @@ -50,60 +54,62 @@ function build_section_start { CURR_MINSEC=$(get_current_minsec) echo -e "\n\e[0Ksection_start:$(date +%s):$section_name$section_params\r\e[0K${CYAN}[${CURR_MINSEC}] $*${ENDCOLOR}\n" } +alias build_section_start="x_off; _build_section_start" -function section_start { - x_off 2>/dev/null - build_section_start "[collapsed=true]" $* +function _section_start { + _build_section_start "[collapsed=true]" $* [ "$state_x" -eq 0 ] || set -x } +alias section_start="x_off; _section_start" -function uncollapsed_section_start { - x_off 2>/dev/null - build_section_start "" $* +function _uncollapsed_section_start { + _build_section_start "" $* [ "$state_x" -eq 0 ] || set -x } +alias uncollapsed_section_start="x_off; _uncollapsed_section_start" -function build_section_end { +function _build_section_end { echo -e "\e[0Ksection_end:$(date +%s):$1\r\e[0K" CURRENT_SECTION="" } +alias build_section_end="x_off; _build_section_end" -function section_end { - x_off >/dev/null - build_section_end $* +function _section_end { + _build_section_end $* [ "$state_x" -eq 0 ] || set -x } +alias section_end="x_off; _section_end" -function section_switch { - x_off 2>/dev/null +function _section_switch { if [ -n "$CURRENT_SECTION" ] then - build_section_end $CURRENT_SECTION + _build_section_end $CURRENT_SECTION fi - build_section_start "[collapsed=true]" $* + _build_section_start "[collapsed=true]" $* [ "$state_x" -eq 0 ] || set -x } +alias section_switch="x_off; _section_switch" -function uncollapsed_section_switch { - x_off 2>/dev/null +function _uncollapsed_section_switch { if [ -n "$CURRENT_SECTION" ] then - build_section_end $CURRENT_SECTION + _build_section_end $CURRENT_SECTION fi - build_section_start "" $* + _build_section_start "" $* [ "$state_x" -eq 0 ] || set -x } +alias uncollapsed_section_switch="x_off; _uncollapsed_section_switch" -export -f x_off +export -f _x_off export -f get_current_minsec export -f error export -f trap_err -export -f build_section_start -export -f section_start -export -f build_section_end -export -f section_end -export -f section_switch -export -f uncollapsed_section_switch +export -f _build_section_start +export -f _section_start +export -f _build_section_end +export -f _section_end +export -f _section_switch +export -f _uncollapsed_section_switch # Freedesktop requirement (needed for Wayland) [ -n "${XDG_RUNTIME_DIR:-}" ] || export XDG_RUNTIME_DIR="$(mktemp -p "$PWD" -d xdg-runtime-XXXXXX)" diff --git a/.gitlab-ci/vkd3d-runner.sh b/.gitlab-ci/vkd3d-runner.sh index 1bb64aa432a..36737e18f6f 100755 --- a/.gitlab-ci/vkd3d-runner.sh +++ b/.gitlab-ci/vkd3d-runner.sh @@ -1,4 +1,7 @@ #!/usr/bin/env bash +# shellcheck disable=SC1091 # paths only become valid at runtime + +. "${SCRIPTS_DIR}/setup-test-env.sh" set -e