Skip to content

Commit

Permalink
[Build]: support to collect version when purging debian package (soni…
Browse files Browse the repository at this point in the history
…c-net#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.
  • Loading branch information
xumia authored and qiluo-msft committed Mar 21, 2022
1 parent 8a38da9 commit 1851827
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/sonic-build-hooks/hooks/apt-get
Original file line number Diff line number Diff line change
Expand Up @@ -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

18 changes: 15 additions & 3 deletions src/sonic-build-hooks/scripts/collect_version_files
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions src/sonic-build-hooks/scripts/post_run_buildinfo
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/sonic-build-hooks/scripts/pre_run_buildinfo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1851827

Please sign in to comment.