Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to use btrfs to speed up Android development with a crontab job.
#!/bin/bash
# Delete old snapshots except the newest one
# Replace product and variant as needed
del_product () {
read -a FILES <<< `ls -dt $1_BUILD_$2_*`
unset FILES[0] # Do not delete newest
for dir in ${FILES[*]}
do
echo "Deleting $dir"
sudo btrfs subvolume delete $dir
done
}
del_product product variant
#!/bin/bash -x
dt=`date +"%Y%m%d"`
echo "Number of parameters: $#"
if [ "$#" -eq 4 ]; then
LOG_FILE=${dt}_$4
else
LOG_FILE=/tmp/log_${dt}.txt
fi
if [ "$#" -lt 3 ]; then
echo "Needs disk and product name and build variant."
echo "Parameters: $1 $2 $3 $4"
echo "Usage: $0 <btrfs dir> <product> <variant> [<log file>]"
exit 1
fi
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>$LOG_FILE 2>&1
BTRFS_DIR=$1
PRODUCT=$2
VARIANT=$3
GOLDEN_DIR=${BTRFS_DIR}/${PRODUCT}_BASE_VOL
BUILD_DIR=${BTRFS_DIR}/${PRODUCT}_BUILD_${VARIANT}
LUNCH=${PRODUCT}-${VARIANT}
echo $GOLDEN_DIR
echo $BUILD_DIR
echo $LUNCH
pushd $GOLDEN_DIR
if ! /usr/local/bin/repo sync -j 4 --force-sync; then
echo "Repo sync failed. Exiting."
exit 2
fi
# Make backup of old build dir just in case.
if [ -d $BUILD_DIR ]; then
mv $BUILD_DIR ${BUILD_DIR}_$dt
fi
# Create snapshot for building
/bin/btrfs subvolume snapshot $GOLDEN_DIR $BUILD_DIR
# Build SW
cd $BUILD_DIR
source build/envsetup.sh
lunch $LUNCH
cook all
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment