tools/refresh.sh: support to refresh all configuration by pseudo config

This commit is contained in:
Xiang Xiao 2020-01-23 04:07:43 +08:00 committed by Gregory Nutt
parent 1658d75005
commit 4bd4f3b424

View File

@ -37,7 +37,7 @@ WD=`test -d ${0%/*} && cd ${0%/*}; pwd`
USAGE="USAGE: $0 [options] <board>:<config>"
ADVICE="Try '$0 --help' for more information"
unset CONFIG
unset CONFIGS
silent=n
defaults=n
prompt=y
@ -80,40 +80,17 @@ while [ ! -z "$1" ]; do
echo " The board directory under nuttx/boards"
echo " <config>"
echo " The board configuration directory under nuttx/boards/<board>/configs"
echo " Note: all configuration is refreshed if <board>:<config> equals all."
exit 0
;;
* )
CONFIG=$1
CONFIGS=$1
break
;;
esac
shift
done
# Get the board configuration
if [ -z "${CONFIG}" ]; then
echo "ERROR: No configuration provided"
echo $USAGE
echo $ADVICE
exit 1
fi
CONFIGSUBDIR=`echo ${CONFIG} | cut -s -d':' -f2`
if [ -z "${CONFIGSUBDIR}" ]; then
CONFIGSUBDIR=`echo ${CONFIG} | cut -s -d'/' -f2`
if [ -z "${CONFIGSUBDIR}" ]; then
echo "ERROR: Malformed configuration: ${CONFIG}"
echo $USAGE
echo $ADVICE
exit 1
else
BOARDSUBDIR=`echo ${CONFIG} | cut -d'/' -f1`
fi
else
BOARDSUBDIR=`echo ${CONFIG} | cut -d':' -f1`
fi
# Where are we
MYNAME=`basename $0`
@ -127,15 +104,7 @@ if [ ! -x tools/${MYNAME} ] ; then
exit 1
fi
# Set up the environment
BOARDDIR=boards/*/*/$BOARDSUBDIR
SCRIPTSDIR=$BOARDDIR/scripts
MAKEDEFS1=$SCRIPTSDIR/Make.defs
CONFIGDIR=$BOARDDIR/configs/$CONFIGSUBDIR
DEFCONFIG=$CONFIGDIR/defconfig
MAKEDEFS2=$CONFIGDIR/Make.defs
# If the cmpconfig executable does not exist, then build it
CMPCONFIG_TARGET=cmpconfig
CMPCONFIG1=tools/cmpconfig
@ -143,36 +112,6 @@ CMPCONFIG2=tools/cmpconfig.exe
CMPCONFIGMAKEFILE=Makefile.host
CMPCONFIGMAKEDIR=tools
# Check the board configuration directory
if [ ! -d $BOARDDIR ]; then
echo "No board directory found at $BOARDDIR"
exit 1
fi
if [ ! -d $CONFIGDIR ]; then
echo "No configuration directory found at $CONFIGDIR"
exit 1
fi
if [ ! -r $DEFCONFIG ]; then
echo "No readable defconfig file at $DEFCONFIG"
exit 1
fi
if [ -r $MAKEDEFS1 ]; then
MAKEDEFS=$MAKEDEFS1
else
if [ -r $MAKEDEFS2 ]; then
MAKEDEFS=$MAKEDEFS2
else
echo "No readable Make.defs file at $MAKEDEFS1 or $MAKEDEFS2"
exit 1
fi
fi
# If the cmpconfig executable does not exist, then build it
if [ -x ${CMPCONFIG1} ]; then
CMPCONFIG=${CMPCONFIG1}
else
@ -195,70 +134,140 @@ else
fi
fi
# Copy the .config and Make.defs to the toplevel directory
# Get the board configuration
rm -f SAVEconfig
if [ -e .config ]; then
mv .config SAVEconfig || \
{ echo "ERROR: Failed to move .config to SAVEconfig"; exit 1; }
if [ -z "${CONFIGS}" ]; then
echo "ERROR: No configuration provided"
echo $USAGE
echo $ADVICE
exit 1
fi
cp -a $DEFCONFIG .config || \
{ echo "ERROR: Failed to copy $DEFCONFIG to .config"; exit 1; }
rm -f SAVEMake.defs
if [ -e Make.defs ]; then
mv Make.defs SAVEMake.defs || \
{ echo "ERROR: Failed to move Make.defs to SAVEMake.defs"; exit 1; }
if [ "X${CONFIGS}" == "Xall" ]; then
CONFIGS=`find boards -name defconfig | cut -d'/' -f4,6`
fi
cp -a $MAKEDEFS Make.defs || \
{ echo "ERROR: Failed to copy $MAKEDEFS to Make.defs"; exit 1; }
for CONFIG in ${CONFIGS}; do
echo "Refresh ${CONFIG}"
# Then run oldconfig or oldefconfig
# Set up the environment
if [ "X${defaults}" == "Xy" ]; then
make olddefconfig
else
make oldconfig
fi
CONFIGSUBDIR=`echo ${CONFIG} | cut -s -d':' -f2`
if [ -z "${CONFIGSUBDIR}" ]; then
CONFIGSUBDIR=`echo ${CONFIG} | cut -s -d'/' -f2`
if [ -z "${CONFIGSUBDIR}" ]; then
echo "ERROR: Malformed configuration: ${CONFIG}"
echo $USAGE
echo $ADVICE
exit 1
else
BOARDSUBDIR=`echo ${CONFIG} | cut -d'/' -f1`
fi
else
BOARDSUBDIR=`echo ${CONFIG} | cut -d':' -f1`
fi
# Run savedefconfig to create the new defconfig file
BOARDDIR=boards/*/*/$BOARDSUBDIR
SCRIPTSDIR=$BOARDDIR/scripts
MAKEDEFS1=$SCRIPTSDIR/Make.defs
make savedefconfig
CONFIGDIR=$BOARDDIR/configs/$CONFIGSUBDIR
DEFCONFIG=$CONFIGDIR/defconfig
MAKEDEFS2=$CONFIGDIR/Make.defs
# Show differences
# Check the board configuration directory
# sed -i -e "s/^CONFIG_APPS_DIR/# CONFIG_APPS_DIR/g" defconfig
$CMPCONFIG $DEFCONFIG defconfig
if [ ! -d $BOARDDIR ]; then
echo "No board directory found at $BOARDDIR"
exit 1
fi
# Save the refreshed configuration
if [ ! -d $CONFIGDIR ]; then
echo "No configuration directory found at $CONFIGDIR"
exit 1
fi
if [ "X${prompt}" == "Xy" ]; then
read -p "Save the new configuration (y/n)?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
if [ ! -r $DEFCONFIG ]; then
echo "No readable defconfig file at $DEFCONFIG"
exit 1
fi
if [ -r $MAKEDEFS1 ]; then
MAKEDEFS=$MAKEDEFS1
else
if [ -r $MAKEDEFS2 ]; then
MAKEDEFS=$MAKEDEFS2
else
echo "No readable Make.defs file at $MAKEDEFS1 or $MAKEDEFS2"
exit 1
fi
fi
# Copy the .config and Make.defs to the toplevel directory
rm -f SAVEconfig
if [ -e .config ]; then
mv .config SAVEconfig || \
{ echo "ERROR: Failed to move .config to SAVEconfig"; exit 1; }
fi
cp -a $DEFCONFIG .config || \
{ echo "ERROR: Failed to copy $DEFCONFIG to .config"; exit 1; }
rm -f SAVEMake.defs
if [ -e Make.defs ]; then
mv Make.defs SAVEMake.defs || \
{ echo "ERROR: Failed to move Make.defs to SAVEMake.defs"; exit 1; }
fi
cp -a $MAKEDEFS Make.defs || \
{ echo "ERROR: Failed to copy $MAKEDEFS to Make.defs"; exit 1; }
# Then run oldconfig or oldefconfig
if [ "X${defaults}" == "Xy" ]; then
make olddefconfig
else
make oldconfig
fi
# Run savedefconfig to create the new defconfig file
make savedefconfig
# Show differences
# sed -i -e "s/^CONFIG_APPS_DIR/# CONFIG_APPS_DIR/g" defconfig
$CMPCONFIG $DEFCONFIG defconfig
# Save the refreshed configuration
if [ "X${prompt}" == "Xy" ]; then
read -p "Save the new configuration (y/n)?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Saving the new configuration file"
mv defconfig $DEFCONFIG || \
{ echo "ERROR: Failed to move defconfig to $DEFCONFIG"; exit 1; }
chmod 644 $DEFCONFIG
fi
else
echo "Saving the new configuration file"
mv defconfig $DEFCONFIG || \
{ echo "ERROR: Failed to move defconfig to $DEFCONFIG"; exit 1; }
chmod 644 $DEFCONFIG
fi
else
echo "Saving the new configuration file"
mv defconfig $DEFCONFIG || \
{ echo "ERROR: Failed to move defconfig to $DEFCONFIG"; exit 1; }
chmod 644 $DEFCONFIG
fi
# Restore any previous .config and Make.defs files
# Restore any previous .config and Make.defs files
if [ -e SAVEconfig ]; then
mv SAVEconfig .config || \
{ echo "ERROR: Failed to move SAVEconfig to .config"; exit 1; }
fi
if [ -e SAVEconfig ]; then
mv SAVEconfig .config || \
{ echo "ERROR: Failed to move SAVEconfig to .config"; exit 1; }
fi
if [ -e SAVEMake.defs ]; then
mv SAVEMake.defs Make.defs || \
{ echo "ERROR: Failed to move SAVEMake.defs to Make.defs"; exit 1; }
fi
if [ -e SAVEMake.defs ]; then
mv SAVEMake.defs Make.defs || \
{ echo "ERROR: Failed to move SAVEMake.defs to Make.defs"; exit 1; }
fi
done