Skip to content

Commit fe51089

Browse files
committed
[Build]: Support to use the base image version when a package version not specified (sonic-net#10971)
Why I did it It is to fix issue: sonic-net#10952 [Build]: Support to use the base image version when a package version not specified
1 parent 5bd7cf9 commit fe51089

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/sonic-build-hooks/scripts/buildinfo_base.sh

+53
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,59 @@ release_apt_installation_lock()
256256
rm -f $DPKG_INSTALLTION_LOCK_FILE
257257
}
258258

259+
update_preference_deb()
260+
{
261+
local version_file="$VERSION_PATH/versions-deb"
262+
if [ -f "$version_file" ]; then
263+
rm -f $VERSION_DEB_PREFERENCE
264+
for pacakge_version in $(cat "$version_file"); do
265+
package=$(echo $pacakge_version | awk -F"==" '{print $1}')
266+
version=$(echo $pacakge_version | awk -F"==" '{print $2}')
267+
echo -e "Package: $package\nPin: version $version\nPin-Priority: 999\n\n" >> $VERSION_DEB_PREFERENCE
268+
done
269+
fi
270+
}
271+
272+
update_version_file()
273+
{
274+
local version_name=$1
275+
local pre_version_file="$(ls $PRE_VERSION_PATH/${version_name}-* 2>/dev/null | head -n 1)"
276+
local version_file="$VERSION_PATH/$1"
277+
if [ ! -f "$pre_version_file" ]; then
278+
return 0
279+
fi
280+
local pacakge_versions="$(cat $pre_version_file)"
281+
[ -f "$version_file" ] && pacakge_versions="$pacakge_versions $(cat $version_file)"
282+
declare -A versions
283+
for pacakge_version in $pacakge_versions; do
284+
package=$(echo $pacakge_version | awk -F"==" '{print $1}')
285+
version=$(echo $pacakge_version | awk -F"==" '{print $2}')
286+
if [ -z "$package" ] || [ -z "$version" ]; then
287+
continue
288+
fi
289+
versions[$package]=$version
290+
done
291+
292+
tmp_file=$(mktemp)
293+
for package in "${!versions[@]}"; do
294+
echo "$package==${versions[$package]}" >> $tmp_file
295+
done
296+
sort -u $tmp_file > $version_file
297+
rm -f $tmp_file
298+
299+
if [[ "${version_name}" == *-deb ]]; then
300+
update_preference_deb
301+
fi
302+
}
303+
304+
update_version_files()
305+
{
306+
local version_names="versions-deb versions-py2 versions-py3"
307+
for version_name in $version_names; do
308+
update_version_file $version_name
309+
done
310+
}
311+
259312
ENABLE_VERSION_CONTROL_DEB=$(check_version_control "deb")
260313
ENABLE_VERSION_CONTROL_PY2=$(check_version_control "py2")
261314
ENABLE_VERSION_CONTROL_PY3=$(check_version_control "py3")

src/sonic-build-hooks/scripts/pre_run_buildinfo

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mkdir -p $LOG_PATH
1111
[ -d $POST_VERSION_PATH ] && rm -rf $POST_VERSION_PATH
1212
mkdir -p $POST_VERSION_PATH
1313
collect_version_files $PRE_VERSION_PATH
14+
update_version_files
1415
symlink_build_hooks
1516
set_reproducible_mirrors
1617

0 commit comments

Comments
 (0)