diff options
Diffstat (limited to 'contrib/switch-config')
-rwxr-xr-x | contrib/switch-config | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/contrib/switch-config b/contrib/switch-config new file mode 100755 index 000000000..ad28464e7 --- /dev/null +++ b/contrib/switch-config @@ -0,0 +1,95 @@ +#!/bin/bash +# +# usage: switch-config [configuration] +# switch-config -l +# +# Script to switch the "current" configuration of the CVC4 builds directory +# to another one. Without an argument, it switches to the next alphabetically. +# With an argument, it switches to that configuration. With -l, it lists the +# available configurations. +# +# Only configurations in the "current" architecture (that for which the build directory is currently +# configured) are considered. +# +# This script is useful because it's faster that re-configuring. +# +# Script assumes it lives under contrib/ in the root of the CVC4 source +# tree. + +function usage { + echo "usage: `basename \"$0\"` [configuration]" + echo " `basename \"$0\"` -l" +} + +if [ $# -gt 1 ]; then + usage + exit 1 +fi + +cd `dirname "$0"`/.. + +if ! [ -d builds ]; then + echo "No configurations are available (no builds/ directory)." + exit +fi + +if ! [ -e builds/current ]; then + echo "Cannot get current configuration." + exit 1 +fi + +current=(`grep '^CURRENT_BUILD' builds/current | sed 's,^CURRENT_BUILD *= *\([^/]\+\)/\(.*\),\1 \2,'`) +arch=${current[0]} +build=${current[1]} + +builds=(`ls "builds/$arch/"`) + +if ! [ -d "builds/$arch" ] || ! [ -d "builds/$arch/$build" ] || [ ${#builds[@]} -eq 0 ]; then + echo "builds/ directory in malformed state." + echo "You might want to blow it away and start from scratch." + exit 1 +fi + +function switchto { + perl -pi -e 's,^CURRENT_BUILD *= *.*,CURRENT_BUILD = '$arch/$1',' builds/current + echo "Current build switched to \`$1'." +} + +if [ $# -eq 0 ]; then + first= + last= + setbuild= + for d in `ls "builds/$arch/"`; do + if [ -z "$first" ]; then first=$d; fi + if [ "$last" = "$build" ]; then setbuild=$d; break; fi + last=$d + done + if [ -z "$setbuild" ]; then setbuild=$first; fi + if [ "$setbuild" = "$build" ]; then + echo "There is only one build profile (\`$build'), and it is current." + else + switchto "$setbuild" + fi +else + case $1 in + -l) for config in `ls -1 "builds/$arch/"`; do + if [ "$config" = "$build" ]; then + echo "$config" '*' + else + echo "$config" + fi + done ;; + -*) usage; exit 1 ;; + *) if ! [ -d "builds/$arch/$1" ]; then + echo "Build \`$1' does not exist." + exit 1 + else + if [ "$1" = "$build" ]; then + echo "Build \`$1' is already the current build profile." + else + switchto "$1" + fi + fi ;; + esac +fi + |