summaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-10-23 06:58:31 +0000
committerpaltherr <paltherr@epfl.ch>2003-10-23 06:58:31 +0000
commitca433daf1ec2bd62c3cb4c17431a1fcd4eaca430 (patch)
treeaaf015aa09d7bda5a8357656091bd1865ce9979c /support
parentfa860129191cbb88541d069ba014d2c5237e1d54 (diff)
downloadscala-ca433daf1ec2bd62c3cb4c17431a1fcd4eaca430.tar.gz
scala-ca433daf1ec2bd62c3cb4c17431a1fcd4eaca430.tar.bz2
scala-ca433daf1ec2bd62c3cb4c17431a1fcd4eaca430.zip
- Added version manager
Diffstat (limited to 'support')
-rwxr-xr-xsupport/scripts/version-manager10
-rw-r--r--support/scripts/version-manager.sh149
2 files changed, 159 insertions, 0 deletions
diff --git a/support/scripts/version-manager b/support/scripts/version-manager
new file mode 100755
index 0000000000..7c4d8f3d38
--- /dev/null
+++ b/support/scripts/version-manager
@@ -0,0 +1,10 @@
+#!/bin/bash
+########################################################-*-Shell-script-*-####
+# Version-Manager Command
+##############################################################################
+# $Id$
+
+source $0.sh;
+${0##*/} "$@";
+
+##############################################################################
diff --git a/support/scripts/version-manager.sh b/support/scripts/version-manager.sh
new file mode 100644
index 0000000000..8a0ce12df1
--- /dev/null
+++ b/support/scripts/version-manager.sh
@@ -0,0 +1,149 @@
+########################################################-*-Shell-script-*-####
+# Version-Manager Function
+##############################################################################
+# $Id$
+
+source ${0%/*}/stdlib.sh;
+
+##############################################################################
+# version-manager
+
+function version-manager-usage() {
+ echo "Usage: $program <version-file> update";
+ echo " $program <version-file> increment";
+ echo " $program <version-file> set <version-value>";
+}
+
+function version-manager-args() {
+ case "$1" in
+ -? | -h | --help ) $program-usage; exit 0;;
+ --verbose ) verbose=true; return 1;;
+ --version ) echo "$program (bash script) $version";exit 0;;
+ -* ) args-option-unknown "$@";;
+ * ) args-append-array args "$@";;
+ esac;
+}
+
+function version-manager-compose() {
+ local variable="$1"; shift 1;
+ local value="$1.$2.$3-b$4"; shift 4;
+ eval "$variable=\"\$value\"";
+}
+
+function version-manager-decompose() {
+ [ $# = 2 ] || abort "internal error";
+ local array="$1"; shift 1;
+ local value="$1"; shift 1;
+ local v0=`expr "$value" : '\([0-9]*\)\.[0-9]*\.[0-9]*-b[0-9]*$'`;
+ local v1=`expr "$value" : '[0-9]*\.\([0-9]*\)\.[0-9]*-b[0-9]*$'`;
+ local v2=`expr "$value" : '[0-9]*\.[0-9]*\.\([0-9]*\)-b[0-9]*$'`;
+ local v3=`expr "$value" : '[0-9]*\.[0-9]*\.[0-9]*-b\([0-9]*\)$'`;
+ eval "$array[0]=\"\$v0\"";
+ eval "$array[1]=\"\$v1\"";
+ eval "$array[2]=\"\$v2\"";
+ eval "$array[3]=\"\$v3\"";
+}
+
+function version-manager-check-syntax() {
+ [ $# = 1 ] || abort "internal error";
+ local value="$1"; shift 1;
+ expr "$value" : '[0-9]*\.[0-9]*\.[0-9]*-b[0-9]*$' 1> /dev/null 2>&1;
+}
+
+function version-manager-check-order() {
+ [ $# = 8 ] || abort "internal error";
+ local l0="$1"; local l1="$2"; local l2="$3"; local l3="$4"; shift 4;
+ local r0="$1"; local r1="$2"; local r2="$3"; local r3="$4"; shift 4;
+ [ $l0 -lt $r0 ] && return 0; [ $l0 -gt $r0 ] && return 1;
+ [ $l1 -lt $r1 ] && return 0; [ $l1 -gt $r1 ] && return 1;
+ [ $l2 -lt $r2 ] && return 0; [ $l2 -gt $r2 ] && return 1;
+ [ $l3 -lt $r3 ] && return 0; [ $l3 -gt $r3 ] && return 1;
+ return 1;
+}
+
+function version-manager() {
+ local program="$FUNCNAME";
+ local version='$Revision$';
+ local -a args;
+ args-loop "$@";
+
+ # get file name and command name
+ [ ${#args[0]} -ge 2 ] || { $program-usage 1>&2; exit 1; }
+ local file="${args[0]}";
+ local command="${args[1]}";
+
+ # check command name and argument count
+ case "$command" in
+ update ) local nargs=0;;
+ increment ) local nargs=0;;
+ set ) local nargs=1;;
+ * ) $program-usage 1>&2; exit 1;;
+ esac;
+ [ ${#args[@]} = $[$nargs+2] ] || { $program-usage 1>&2; exit 1; }
+
+ # check new value syntax, if command is "set"
+ if [ "$command" = "set" ]; then
+ local new_value="${args[2]}";
+ if ! $program-check-syntax "$new_value-b0"; then
+ local -a error;
+ error[0]="version value '$new_value' does not conform";
+ error[1]="to version syntax <int>.<int>.<int>";
+ abort "${error[*]}";
+ fi;
+ new_value="$new_value-b0";
+ fi;
+
+ # check file existence
+ [ -f "$file" ] || abort "could not find file '$file'";
+
+ # update version file
+ run rm -f "$file";
+ runO /dev/null cvs update "$file";
+
+ # get old value
+ local old_value=`tail -1 "$file"`;
+
+ # check old value syntax
+ if ! $program-check-syntax "$old_value"; then
+ local -a error;
+ error[0]="version value '$old_value' in file '$file' does not conform";
+ error[1]="to version syntax <int>.<int>.<int>-b<int>";
+ abort "${error[*]}";
+ fi;
+
+ # terminate if command is "update"
+ [ "$command" = "update" ] && exit 0;
+
+ # compute old and new arrays
+ local -a old_array;
+ local -a new_array;
+ $program-decompose old_array "$old_value";
+ if [ "$command" = "increment" ]; then
+ $program-decompose new_array "$old_value";
+ new_array[3]=$[${new_array[3]}+1];
+ else
+ $program-decompose new_array "$new_value";
+ fi;
+
+ # check order of old and new values
+ if ! $program-check-order "${old_array[@]}" "${new_array[@]}"; then
+ abort "new version must be greater than '$old_value'";
+ fi;
+
+ # compute new value
+ local new_value;
+ $program-compose new_value "${new_array[@]}";
+
+ # rewrite version file
+ runO "$file~" sed -es@"$old_value"@"$new_value"@ "$file";
+ run mv "$file~" "$file";
+
+ # commit version file
+ runO /dev/null cvs commit -m "Set version to $new_value" "$file";
+
+ if [ "$command" = "set" ]; then
+ echo "Successfully changed version to $new_value";
+ fi;
+}
+
+##############################################################################