linux-yocto: make kernel_checkout reentrant

The steps in do_kernel_checkout modify the source tree in WORKDIR.
If it is called multiple times, or interrupted, the tree is left
in an inconsistent state.

This change adds protections around branch names, and around the
manipulations of directories to ensure that it is safe to call
at any point.

(From OE-Core rev: f937977f241e786c5a7438449ed4c9da4c55829b)

Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Bruce Ashfield 2012-02-28 16:09:58 -05:00 committed by Richard Purdie
parent 60eed3195c
commit 54d1f5fc3e
1 changed files with 20 additions and 13 deletions

View File

@ -139,17 +139,17 @@ do_patch() {
} }
do_kernel_checkout() { do_kernel_checkout() {
# we build out of {S}, so ensure that ${S} is clean and present
rm -rf ${S}
mkdir -p ${S}/.git
set +e set +e
# A linux yocto SRC_URI should use the bareclone option. That # A linux yocto SRC_URI should use the bareclone option. That
# ensures that all the branches are available in the WORKDIR version # ensures that all the branches are available in the WORKDIR version
# of the repository. If it wasn't passed, we should detect it, and put # of the repository. If it wasn't passed, we should detect it, and put
# out a useful error message # out a useful error message
if [ -d "${WORKDIR}/git/.git" ]; then if [ -d "${WORKDIR}/git/" ] && [ -d "${WORKDIR}/git/.git" ]; then
# we build out of {S}, so ensure that ${S} is clean and present
rm -rf ${S}
mkdir -p ${S}/.git
echo "WARNING. ${WORKDIR}/git is not a bare clone." echo "WARNING. ${WORKDIR}/git is not a bare clone."
echo "Ensure that the SRC_URI includes the 'bareclone=1' option." echo "Ensure that the SRC_URI includes the 'bareclone=1' option."
@ -158,6 +158,7 @@ do_kernel_checkout() {
mv ${WORKDIR}/git/.git ${S} mv ${WORKDIR}/git/.git ${S}
rm -rf ${WORKDIR}/git/ rm -rf ${WORKDIR}/git/
cd ${S} cd ${S}
if [ -n "${YOCTO_KERNEL_META_DATA}" ] && [ -n "${KMETA}" ]; then
git branch -a | grep -q ${KMETA} git branch -a | grep -q ${KMETA}
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR. The branch '${KMETA}' is required and was not" echo "ERROR. The branch '${KMETA}' is required and was not"
@ -165,6 +166,7 @@ do_kernel_checkout() {
echo "kernel repository" echo "kernel repository"
exit 1 exit 1
fi fi
fi
if [ -z "${YOCTO_KERNEL_EXTERNAL_BRANCH}" ] && [ -n "${KBRANCH}" ] ; then if [ -z "${YOCTO_KERNEL_EXTERNAL_BRANCH}" ] && [ -n "${KBRANCH}" ] ; then
git branch -a | grep -q ${KBRANCH} git branch -a | grep -q ${KBRANCH}
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -174,7 +176,12 @@ do_kernel_checkout() {
exit 1 exit 1
fi fi
fi fi
else fi
if [ -d "${WORKDIR}/git/" ] && [ ! -d "${WORKDIR}/git/.git" ]; then
# we build out of {S}, so ensure that ${S} is clean and present
rm -rf ${S}
mkdir -p ${S}/.git
mv ${WORKDIR}/git/* ${S}/.git mv ${WORKDIR}/git/* ${S}/.git
rm -rf ${WORKDIR}/git/ rm -rf ${WORKDIR}/git/
cd ${S} cd ${S}