repo: added src-rev script to update source revisions

BugzID: 74523
Signed-off-by: Marc Mattmueller <marc.mattmueller@netmodule.com>
This commit is contained in:
Marc Mattmueller 2021-09-30 11:59:20 +02:00 committed by Gitea
parent d530642b18
commit 85ca7a099e
4 changed files with 176 additions and 0 deletions

View File

@ -35,6 +35,9 @@ LICENSE_CREATE_PACKAGE = "1"
INHERIT += "buildhistory buildstats-summary"
# enable upstream check to use head of branch:
UPSTREAM_CHECK_COMMITS = "1"
YOCTOROOT = "${@os.path.abspath(os.path.join("${TOPDIR}", os.pardir))}"
PREMIRRORS_prepend = "\

View File

@ -35,6 +35,9 @@ LICENSE_CREATE_PACKAGE = "1"
INHERIT += "buildhistory buildstats-summary"
# enable upstream check to use head of branch:
UPSTREAM_CHECK_COMMITS = "1"
YOCTOROOT = "${@os.path.abspath(os.path.join("${TOPDIR}", os.pardir))}"
PREMIRRORS_prepend = "\

View File

@ -35,6 +35,9 @@ LICENSE_CREATE_PACKAGE = "1"
INHERIT += "buildhistory buildstats-summary"
# enable upstream check to use head of branch:
UPSTREAM_CHECK_COMMITS = "1"
YOCTOROOT = "${@os.path.abspath(os.path.join("${TOPDIR}", os.pardir))}"
PREMIRRORS_prepend = "\

167
src-rev.sh Executable file
View File

@ -0,0 +1,167 @@
#!/bin/bash
SCRIPT_PARAMS="$*"
SCRIPT_PATHNAME=$(realpath ${0})
SCRIPT_NAME=$(basename ${SCRIPT_PATHNAME})
SCRIPT_PATH=$(dirname ${SCRIPT_PATHNAME})
YOCTO_DIR="${YOCTO_DIR:-$SCRIPT_PATH}"
export LOGFILE=/dev/null
export IS_REPLACE_SRCREV=false
export IS_VERBOSE=false
export IS_DISPLAY=false
#**********************************************************************************************
# local helper functions
#**********************************************************************************************
#----------------------------------------------------------------------------------------------
function printUsage()
{
echo -e "\nUsage: ${SCRIPT_NAME} [OPTIONS]\n"
echo -e ""
echo -e " OPTIONS:"
echo -e " -r|--replace replace SRCREVs"
echo -e " -d|--display display found SRVREVs"
echo -e " -l|--log=LOGFILE write command output to LOGFILE (default = $LOGFILE)"
echo -e " -h|--help Show this help"
echo -e " -v|--verbose Set script to verbose"
}
#----------------------------------------------------------------------------------------------
function logMessage()
{
local msg="${1}"
echo "${msg}" >> $LOGFILE
}
#----------------------------------------------------------------------------------------------
function printMessage()
{
local msg="${1}"
logMessage "${msg}"
if [[ "${IS_VERBOSE}" == "false" ]]; then
return
fi
echo "${msg}"
}
#----------------------------------------------------------------------------------------------
function checkingEnvironment()
{
printMessage "> checking environment for devtool..."
isEnvLoaded=$(which devtool | wc -l)
logMessage "> isEnvLoaded=${isEnvLoaded}"
if [[ "${isEnvLoaded}" == "0" ]]; then
logMessage "Yocto environment not loaded (devtool not found) --> exiting"
echo "Yocto environment not loaded (devtool not found) --> exiting"
exit 1
fi
}
#----------------------------------------------------------------------------------------------
function displayItem()
{
local bbfile="${1}"
local recipeName="${2}"
local revision="${3}"
printMessage "Recipe: $recipe"
printMessage "New Revision: $newrev"
printMessage "BB File: $bbfile"
if [[ "${IS_DISPLAY}" == "true" && "${IS_VERBOSE}" == "false" ]]; then
echo "Recipe: $recipe"
echo "New Revision: $newrev"
echo "BB File: $bbfile"
fi
}
#**********************************************************************************************
# main
#**********************************************************************************************
O=$(getopt -o hl:vrd --long help,log:,verbose,replace,display -- "$@") || exit 1
if [ $? != 0 ]; then
echo "ERROR: Could not parse command line options"
exit 1
fi
eval set -- "$O"
while true; do
case "${1}" in
-v|--verbose)
export IS_VERBOSE=true
shift
;;
-d|--display)
export IS_DISPLAY=true
shift
;;
-r|--replace)
export IS_REPLACE_SRCREV=true
shift
;;
-l|--log)
export LOGFILE="${2}"
export LOGFILE=$(realpath "${LOGFILE}")
shift 2
;;
-h|--help)
export IS_VERBOSE=false
printUsage
exit 0
;;
--)
shift
break
;;
*)
printUsage; exit 0 ;;
esac
done
echo "${SCRIPT_NAME} called with ${SCRIPT_PARAMS}" > $LOGFILE
checkingEnvironment
printMessage "> get bbfiles..."
bbfiles=$(find ${YOCTO_DIR}/meta-netmodule* -name "*.bb" | xargs -i sh -c "grep -q SRCREV {} && echo {}")
logMessage "${bbfiles}"
printMessage "> getting recipes residing in bbfiles..."
recipes=$(echo "$bbfiles" | xargs -i basename {} | sed 's/_.*//' | sed 's/\.bb//')
logMessage "${recipes}"
printMessage "> getting check-upgrade-status..."
newcommits=$(devtool check-upgrade-status $recipes 2>&1 | grep "new commits")
IFS=$'\n'
for newcommit in $newcommits; do
# We need to restore IFS for sed
IFS=$' \t\n'
# Get recipe name
recipe_name=$(echo $newcommit | cut -d " " -f 2)
# Get the last string in line
newrev=$(echo $newcommit | sed 's/.* //')
logMessage "> newCommit=${newcommit}; recipeName=${recipe_name}; newRev=${newrev}"
# i acts as bbfile index like bbfile[i]
i=1
found=0
for recipe in $recipes; do
if [ "$recipe" == "$recipe_name" ]; then
bbfile=$(echo $bbfiles | cut -d " " -f$i)
displayItem "${bbfile}" "${recipe}" "${newrev}"
found=1
if [ "${IS_REPLACE_SRCREV}" == "true" ]; then
printMessage " --> updating ${recipe} in ${bbfile} to ${newrev}"
sed -i "s/SRCREV.*/SRCREV ?= \"$newrev\"/g" $bbfile
fi
break
fi
i=$((i+1))
done
if [ "$found" == "0" ]; then
logMessage "Recipe ${recipe_name} not found --> exiting"
echo "Recipe ${recipe_name} not found"
exit 1
fi
logMessage "--------------------"
done
logMessage "> all recipes handled"
exit 0