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 <daniels@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31602>
This commit is contained in:
Daniel Stone
2024-09-10 18:49:51 +01:00
parent 8316654dac
commit ef175ea594
11 changed files with 65 additions and 28 deletions

View File

@@ -1,5 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2086 # we want word splitting # 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" section_start cuttlefish_setup "cuttlefish: setup"
set -xe set -xe

View File

@@ -1,5 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2086 # we want word splitting # 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" section_start test_setup "deqp: preparing test setup"

View File

@@ -1,5 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2086 # we want word splitting # shellcheck disable=SC2086 # we want word splitting
# shellcheck disable=SC1091 # paths only become valid at runtime
. "${SCRIPTS_DIR}/setup-test-env.sh"
set -ex set -ex

View File

@@ -1,5 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2086 # we want word splitting # 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" section_start prepare_rootfs "Preparing root filesystem"

View File

@@ -1,6 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC1003 # works for us now... # shellcheck disable=SC1003 # works for us now...
# shellcheck disable=SC2086 # we want word splitting # 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" section_switch meson-cross-file "meson: cross file generate"

View File

@@ -1,5 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2086 # we want word splitting # shellcheck disable=SC2086 # we want word splitting
# shellcheck disable=SC1091 # paths only become valid at runtime
. "${SCRIPTS_DIR}/setup-test-env.sh"
set -ex set -ex

View File

@@ -1,6 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2035 # FIXME glob # shellcheck disable=SC2035 # FIXME glob
# shellcheck disable=SC2086 # we want word splitting # 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" section_start traces_prepare "traces: preparing test setup"

View File

@@ -1,6 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2038 # TODO: rewrite the find # shellcheck disable=SC2038 # TODO: rewrite the find
# shellcheck disable=SC2086 # we want word splitting # 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" section_switch prepare-artifacts "artifacts: prepare"

View File

@@ -1,6 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC1091 # paths only become valid at runtime
set -e set -e
. "${SCRIPTS_DIR}/setup-test-env.sh"
ARTIFACTSDIR=$(pwd)/shader-db ARTIFACTSDIR=$(pwd)/shader-db
mkdir -p "$ARTIFACTSDIR" mkdir -p "$ARTIFACTSDIR"
export DRM_SHIM_DEBUG=true export DRM_SHIM_DEBUG=true

View File

@@ -3,7 +3,9 @@
# shellcheck disable=SC2086 # we want word splitting # shellcheck disable=SC2086 # we want word splitting
# shellcheck disable=SC2155 # mktemp usually not failing # shellcheck disable=SC2155 # mktemp usually not failing
function x_off { shopt -s expand_aliases
function _x_off {
if [[ "$-" == *"x"* ]]; then if [[ "$-" == *"x"* ]]; then
state_x=1 state_x=1
set +x set +x
@@ -12,6 +14,8 @@ function x_off {
fi fi
} }
alias x_off='{ _x_off; } >/dev/null 2>/dev/null'
# TODO: implement x_on ! # TODO: implement x_on !
export JOB_START_S=$(date -u +"%s" -d "${CI_JOB_STARTED_AT:?}") export JOB_START_S=$(date -u +"%s" -d "${CI_JOB_STARTED_AT:?}")
@@ -27,7 +31,7 @@ function error {
RED="\e[0;31m" RED="\e[0;31m"
ENDCOLOR="\e[0m" ENDCOLOR="\e[0m"
# we force the following to be not in a section # we force the following to be not in a section
section_end $CURRENT_SECTION _section_end $CURRENT_SECTION
CURR_MINSEC=$(get_current_minsec) CURR_MINSEC=$(get_current_minsec)
echo -e "\n${RED}[${CURR_MINSEC}] ERROR: $*${ENDCOLOR}\n" echo -e "\n${RED}[${CURR_MINSEC}] ERROR: $*${ENDCOLOR}\n"
@@ -38,7 +42,7 @@ function trap_err {
error ${CURRENT_SECTION:-'unknown-section'}: ret code: $* error ${CURRENT_SECTION:-'unknown-section'}: ret code: $*
} }
function build_section_start { function _build_section_start {
local section_params=$1 local section_params=$1
shift shift
local section_name=$1 local section_name=$1
@@ -50,60 +54,62 @@ function build_section_start {
CURR_MINSEC=$(get_current_minsec) 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" 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 { function _section_start {
x_off 2>/dev/null _build_section_start "[collapsed=true]" $*
build_section_start "[collapsed=true]" $*
[ "$state_x" -eq 0 ] || set -x [ "$state_x" -eq 0 ] || set -x
} }
alias section_start="x_off; _section_start"
function uncollapsed_section_start { function _uncollapsed_section_start {
x_off 2>/dev/null _build_section_start "" $*
build_section_start "" $*
[ "$state_x" -eq 0 ] || set -x [ "$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" echo -e "\e[0Ksection_end:$(date +%s):$1\r\e[0K"
CURRENT_SECTION="" CURRENT_SECTION=""
} }
alias build_section_end="x_off; _build_section_end"
function section_end { function _section_end {
x_off >/dev/null _build_section_end $*
build_section_end $*
[ "$state_x" -eq 0 ] || set -x [ "$state_x" -eq 0 ] || set -x
} }
alias section_end="x_off; _section_end"
function section_switch { function _section_switch {
x_off 2>/dev/null
if [ -n "$CURRENT_SECTION" ] if [ -n "$CURRENT_SECTION" ]
then then
build_section_end $CURRENT_SECTION _build_section_end $CURRENT_SECTION
fi fi
build_section_start "[collapsed=true]" $* _build_section_start "[collapsed=true]" $*
[ "$state_x" -eq 0 ] || set -x [ "$state_x" -eq 0 ] || set -x
} }
alias section_switch="x_off; _section_switch"
function uncollapsed_section_switch { function _uncollapsed_section_switch {
x_off 2>/dev/null
if [ -n "$CURRENT_SECTION" ] if [ -n "$CURRENT_SECTION" ]
then then
build_section_end $CURRENT_SECTION _build_section_end $CURRENT_SECTION
fi fi
build_section_start "" $* _build_section_start "" $*
[ "$state_x" -eq 0 ] || set -x [ "$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 get_current_minsec
export -f error export -f error
export -f trap_err export -f trap_err
export -f build_section_start export -f _build_section_start
export -f section_start export -f _section_start
export -f build_section_end export -f _build_section_end
export -f section_end export -f _section_end
export -f section_switch export -f _section_switch
export -f uncollapsed_section_switch export -f _uncollapsed_section_switch
# Freedesktop requirement (needed for Wayland) # Freedesktop requirement (needed for Wayland)
[ -n "${XDG_RUNTIME_DIR:-}" ] || export XDG_RUNTIME_DIR="$(mktemp -p "$PWD" -d xdg-runtime-XXXXXX)" [ -n "${XDG_RUNTIME_DIR:-}" ] || export XDG_RUNTIME_DIR="$(mktemp -p "$PWD" -d xdg-runtime-XXXXXX)"

View File

@@ -1,4 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC1091 # paths only become valid at runtime
. "${SCRIPTS_DIR}/setup-test-env.sh"
set -e set -e