Skip to content

Commit f9005e3

Browse files
authored
[Build]: Support to use the base image version when a package version not specified (#10971) (#10975)
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 6ebe5e6 commit f9005e3

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
@@ -264,6 +264,59 @@ release_apt_installation_lock()
264264
rm -f $DPKG_INSTALLTION_LOCK_FILE
265265
}
266266

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