diff --git a/tools/packaging/scripts/apply_patches.sh b/tools/packaging/scripts/apply_patches.sh index ada89e76ec..98d5b02816 100755 --- a/tools/packaging/scripts/apply_patches.sh +++ b/tools/packaging/scripts/apply_patches.sh @@ -45,6 +45,6 @@ if [ -d "$patches_dir" ]; then done else echo "INFO: Patches directory does not exist: ${patches_dir}" - echo "INFO: Create a ${patches_dir}/no_patches file if the current qemu version has no patches" + echo "INFO: Create a ${patches_dir}/no_patches file if the current version has no patches" exit 1; fi diff --git a/tools/packaging/scripts/patch_qemu.sh b/tools/packaging/scripts/patch_qemu.sh new file mode 100755 index 0000000000..91fa5d76a6 --- /dev/null +++ b/tools/packaging/scripts/patch_qemu.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# +# Copyright (c) 2021 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +set -o errexit +set -o nounset +set -o pipefail +set -o errtrace + +script_dir=$(dirname $(readlink -f "$0")) +handle_error() { + local exit_code="${?}" + local line_number="${1:-}" + echo "error:" + echo "Failed at $line_number: ${BASH_COMMAND}" + exit "${exit_code}" +} +trap 'handle_error $LINENO' ERR + +usage(){ + echo "$0 " +} + +qemu_version="${1:-}" +[ "${qemu_version}" == "" ] && usage && exit 1 + +patches_dir="${2:-}" +[ "${patches_dir}" == "" ] && usage && exit 1 + +apply_patches="${script_dir}/apply_patches.sh" + +stable_branch=$(cat VERSION | awk 'BEGIN{FS=OFS="."}{print $1 "." $2 ".x"}') +patch_version=$(cat VERSION | awk 'BEGIN{FS=OFS="."}{print $3}') + +if (( $patch_version >= 50));then + echo "Found qemu dev version: Qemu uses patch version +50 to identify new development tree." + echo "Patches for base version ${stable_branch} are not used for $(cat VERSION)" +else + echo "Apply patches for base version ${stable_branch}" + "${apply_patches}" "${patches_dir}/${stable_branch}" +fi + +echo "Apply patches for specific qemu version ${qemu_version}" +"${apply_patches}" "${patches_dir}/tag_patches/${qemu_version}" diff --git a/tools/packaging/static-build/qemu/Dockerfile b/tools/packaging/static-build/qemu/Dockerfile index 0165bcbc77..240b2464c5 100644 --- a/tools/packaging/static-build/qemu/Dockerfile +++ b/tools/packaging/static-build/qemu/Dockerfile @@ -63,13 +63,9 @@ RUN git clone https://github.com/qemu/keycodemapdb.git ui/keycodemapdb ADD scripts/configure-hypervisor.sh /root/configure-hypervisor.sh ADD qemu /root/kata_qemu ADD scripts/apply_patches.sh /root/apply_patches.sh +ADD scripts/patch_qemu.sh /root/patch_qemu.sh -RUN echo "Apply patches for base version" -RUN stable_branch=$(cat VERSION | awk 'BEGIN{FS=OFS="."}{print $1 "." $2 ".x"}') && \ - /root/apply_patches.sh "/root/kata_qemu/patches/${stable_branch}" - -RUN echo "Apply patches for specific qemu version" -RUN /root/apply_patches.sh "/root/kata_qemu/patches/tag_patches/${QEMU_VERSION}" +RUN /root/patch_qemu.sh "${QEMU_VERSION}" "/root/kata_qemu/patches" ARG PREFIX ARG BUILD_SUFFIX