From 5798f5d05f239a26a554a69e2efe8158c973b632 Mon Sep 17 00:00:00 2001 From: Guilherme Gallo Date: Mon, 3 Mar 2025 19:56:32 -0300 Subject: [PATCH] Revert "ci: setup-test-env: Prefer functions over aliases" This reverts commit 1cc2c738bbf7099d6543700669910b6b81c8e96e We originally changed some aliases into functions so scripts could use them without needing to be sourced, keeping the environment cleaner. However, this broke `x_off`, which is supposed to stop debug logs (xtrace output) from showing in the console. The function version still triggered xtrace before disabling it, while the alias correctly redirected the logs to `/dev/null`. It also fixes the `bin/ci/update_tag.py` script to be able to reuse the aliases via double sourcing the setup-test-env.sh and the respective build script. Reported-by: Eric Engestrom Reviewed-by: Eric Engestrom Signed-off-by: Guilherme Gallo Part-of: --- .gitlab-ci/image-tags.yml | 2 +- .gitlab-ci/setup-test-env.sh | 95 ++++++++++-------------------------- bin/ci/update_tag.py | 2 +- 3 files changed, 28 insertions(+), 71 deletions(-) diff --git a/.gitlab-ci/image-tags.yml b/.gitlab-ci/image-tags.yml index e77ee3f3aee..3240431ea7f 100644 --- a/.gitlab-ci/image-tags.yml +++ b/.gitlab-ci/image-tags.yml @@ -23,7 +23,7 @@ variables: DEBIAN_BASE_TAG: "20250304-virglcrosvm" DEBIAN_X86_64_BUILD_IMAGE_PATH: "debian/x86_64_build" - DEBIAN_BUILD_TAG: "20250217-wrappers" + DEBIAN_BUILD_TAG: "20250303-setup-env" DEBIAN_X86_64_TEST_BASE_IMAGE: "debian/x86_64_test-base" DEBIAN_ARM32_TEST_BASE_IMAGE: "debian/arm32_test-base" diff --git a/.gitlab-ci/setup-test-env.sh b/.gitlab-ci/setup-test-env.sh index 9354d5b4ecf..8df29f9f938 100644 --- a/.gitlab-ci/setup-test-env.sh +++ b/.gitlab-ci/setup-test-env.sh @@ -13,15 +13,25 @@ function _x_store_state { fi } _x_store_state +alias x_store_state='{ _x_store_state; } >/dev/null 2>/dev/null' function _x_off { x_store_state set +x } +alias x_off='{ _x_off; } >/dev/null 2>/dev/null' function _x_restore { [ $previous_state_x -eq 0 ] || set -x } +alias x_restore='{ _x_restore; } >/dev/null 2>/dev/null' + +function _error_msg() ( + x_off + RED="\e[0;31m" + ENDCOLOR="\e[0m" + echo -e "${RED}$*${ENDCOLOR}" +) export JOB_START_S=$(date -u +"%s" -d "${CI_JOB_STARTED_AT:?}") @@ -44,27 +54,32 @@ function _build_section_start { echo -e "\n\e[0Ksection_start:$(date +%s):$section_name$section_params\r\e[0K${CYAN}[${CURR_MINSEC}] $*${ENDCOLOR}\n" x_restore } +alias build_section_start="x_off; _build_section_start" function _section_start { build_section_start "[collapsed=true]" $* x_restore } +alias section_start="x_off; _section_start" function _uncollapsed_section_start { build_section_start "" $* x_restore } +alias uncollapsed_section_start="x_off; _uncollapsed_section_start" function _build_section_end { echo -e "\e[0Ksection_end:$(date +%s):$1\r\e[0K" CURRENT_SECTION="" x_restore } +alias build_section_end="x_off; _build_section_end" function _section_end { build_section_end $* x_restore } +alias section_end="x_off; _section_end" function _section_switch { if [ -n "$CURRENT_SECTION" ] @@ -75,6 +90,7 @@ function _section_switch { build_section_start "[collapsed=true]" $* x_restore } +alias section_switch="x_off; _section_switch" function _uncollapsed_section_switch { if [ -n "$CURRENT_SECTION" ] @@ -85,79 +101,20 @@ function _uncollapsed_section_switch { build_section_start "" $* x_restore } +alias uncollapsed_section_switch="x_off; _uncollapsed_section_switch" -_error_msg() ( - x_off - RED="\e[0;31m" - ENDCOLOR="\e[0m" - echo -e "${RED}$*${ENDCOLOR}" -) - -function x_store_state { - _x_store_state >/dev/null 2>/dev/null -} - -function x_off { - _x_off >/dev/null 2>/dev/null -} - -function x_restore { - _x_restore >/dev/null 2>/dev/null -} - -function build_section_start { - x_off; _build_section_start "$@" -} - -function section_start { - x_off; _section_start "$@" -} - -function uncollapsed_section_start { - x_off; _uncollapsed_section_start "$@" -} - -function build_section_end { - x_off; _build_section_end "$@" -} - -function section_end { - x_off; _section_end "$@" -} - -function section_switch { - x_off; _section_switch "$@" -} - -function uncollapsed_section_switch { - x_off; _uncollapsed_section_switch "$@" -} - -# Export all functions -# Prefer functions over aliases, since aliases are not exportable -export -f build_section_end -export -f build_section_start -export -f section_end -export -f section_start -export -f section_switch -export -f uncollapsed_section_start -export -f uncollapsed_section_switch -export -f x_off -export -f x_restore -export -f x_store_state - -export -f _build_section_end -export -f _build_section_start -export -f _error_msg -export -f _section_end -export -f _section_start -export -f _section_switch -export -f _uncollapsed_section_start -export -f _uncollapsed_section_switch +export -f _x_store_state export -f _x_off export -f _x_restore -export -f _x_store_state export -f get_current_minsec +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 _error_msg + # Freedesktop requirement (needed for Wayland) [ -n "${XDG_RUNTIME_DIR:-}" ] || export XDG_RUNTIME_DIR="$(mktemp -p "$PWD" -d xdg-runtime-XXXXXX)" diff --git a/bin/ci/update_tag.py b/bin/ci/update_tag.py index 5a315085000..d626f2fb8ff 100755 --- a/bin/ci/update_tag.py +++ b/bin/ci/update_tag.py @@ -205,7 +205,7 @@ def run_build_script(component: str, check_only: bool = False) -> Optional[str]: # Run the build script result = subprocess.run( - ["bash", "-c", f"source {setup_env_script} && bash -x {build_script}"], + ["bash", "-c", f"source {setup_env_script} && source {build_script}"], env=os.environ | child_env, capture_output=True, text=True,