From 92363eadbeff78e0a29344574115177e8c790cca Mon Sep 17 00:00:00 2001 From: xumia <59720581+xumia@users.noreply.github.com> Date: Mon, 21 Mar 2022 17:10:33 +0800 Subject: [PATCH] [Build]: support to collect version when purging debian package (#10287) Why I did it support to collect version when purging debian package Support to collect version multiple times How I did it Add the collection action before purging. --- src/sonic-build-hooks/hooks/apt-get | 5 +++++ .../scripts/collect_version_files | 18 +++++++++++++++--- .../scripts/post_run_buildinfo | 2 -- .../scripts/pre_run_buildinfo | 2 ++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/sonic-build-hooks/hooks/apt-get b/src/sonic-build-hooks/hooks/apt-get index 625b068436..bdff703d01 100755 --- a/src/sonic-build-hooks/hooks/apt-get +++ b/src/sonic-build-hooks/hooks/apt-get @@ -20,6 +20,11 @@ if [ "$INSTALL" == y ]; then [ "$lock_result" == y ] && release_apt_installation_lock exit $command_result else + if [[ "$1" == "purge" || "$@" == *" purge "* ]]; then + # When running the purge command, collect the debian versions + dpkg-query -W -f '${Package}==${Version}\n' >> $POST_VERSION_PATH/purge-versions-deb + chmod a+wr $POST_VERSION_PATH/purge-versions-deb + fi $REAL_COMMAND "$@" fi diff --git a/src/sonic-build-hooks/scripts/collect_version_files b/src/sonic-build-hooks/scripts/collect_version_files index b62beb4a21..570883701e 100755 --- a/src/sonic-build-hooks/scripts/collect_version_files +++ b/src/sonic-build-hooks/scripts/collect_version_files @@ -1,14 +1,26 @@ #!/bin/bash +. /usr/local/share/buildinfo/scripts/buildinfo_base.sh + TARGET_PATH=$1 +[ -z "$TARGET_PATH" ] && TARGET_PATH=$POST_VERSION_PATH ARCH=$(dpkg --print-architecture) DIST=$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2) ([ -z "$DIST" ] && grep -q jessie /etc/os-release) && DIST=jessie mkdir -p $TARGET_PATH chmod a+rw $TARGET_PATH -dpkg-query -W -f '${Package}==${Version}\n' > "${TARGET_PATH}/versions-deb-${DIST}-${ARCH}" -([ -x "/usr/local/bin/pip2" ] || [ -x "/usr/bin/pip2" ]) && pip2 freeze > "${TARGET_PATH}/versions-py2-${DIST}-${ARCH}" -([ -x "/usr/local/bin/pip3" ] || [ -x "/usr/bin/pip3" ]) && pip3 freeze > "${TARGET_PATH}/versions-py3-${DIST}-${ARCH}" + +dpkg-query -W -f '${Package}==${Version}\n' >> "${TARGET_PATH}/versions-deb-${DIST}-${ARCH}" +([ -x "/usr/local/bin/pip2" ] || [ -x "/usr/bin/pip2" ]) && pip2 freeze >> "${TARGET_PATH}/versions-py2-${DIST}-${ARCH}" +([ -x "/usr/local/bin/pip3" ] || [ -x "/usr/bin/pip3" ]) && pip3 freeze >> "${TARGET_PATH}/versions-py3-${DIST}-${ARCH}" + +## Add the the packages purged +[ -f $POST_VERSION_PATH/purge-versions-deb ] && cat $POST_VERSION_PATH/purge-versions-deb >> "${TARGET_PATH}/versions-deb-${DIST}-${ARCH}" + +## Print the unique and sorted result +sort -u "${TARGET_PATH}/versions-deb-${DIST}-${ARCH}" -o "${TARGET_PATH}/versions-deb-${DIST}-${ARCH}" +sort -u "${TARGET_PATH}/versions-py2-${DIST}-${ARCH}" -o "${TARGET_PATH}/versions-py2-${DIST}-${ARCH}" +sort -u "${TARGET_PATH}/versions-py3-${DIST}-${ARCH}" -o "${TARGET_PATH}/versions-py3-${DIST}-${ARCH}" exit 0 diff --git a/src/sonic-build-hooks/scripts/post_run_buildinfo b/src/sonic-build-hooks/scripts/post_run_buildinfo index 614389fd42..e0d84d35bb 100755 --- a/src/sonic-build-hooks/scripts/post_run_buildinfo +++ b/src/sonic-build-hooks/scripts/post_run_buildinfo @@ -2,8 +2,6 @@ . /usr/local/share/buildinfo/scripts/buildinfo_base.sh -[ -d $POST_VERSION_PATH ] && rm -rf $POST_VERSION_PATH - # Collect the version files collect_version_files $POST_VERSION_PATH diff --git a/src/sonic-build-hooks/scripts/pre_run_buildinfo b/src/sonic-build-hooks/scripts/pre_run_buildinfo index 3cf0cf7c8d..d9b927ab42 100755 --- a/src/sonic-build-hooks/scripts/pre_run_buildinfo +++ b/src/sonic-build-hooks/scripts/pre_run_buildinfo @@ -8,6 +8,8 @@ mkdir -p $BUILD_VERSION_PATH mkdir -p $LOG_PATH [ -d $PRE_VERSION_PATH ] && rm -rf $PRE_VERSION_PATH +[ -d $POST_VERSION_PATH ] && rm -rf $POST_VERSION_PATH +mkdir -p $POST_VERSION_PATH collect_version_files $PRE_VERSION_PATH symlink_build_hooks set_reproducible_mirrors