Skip to content

Commit 03532c8

Browse files
authored
[Build]: Support to use the base image version when a package version not specified (#10971) (#10974)
Why I did it It is to fix issue: #10952 [Build]: Support to use the base image version when a package version not specified
1 parent 5bf840d commit 03532c8

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
@@ -260,6 +260,59 @@ release_apt_installation_lock()
260260
rm -f $DPKG_INSTALLTION_LOCK_FILE
261261
}
262262

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