diff options
author | Martin Odersky <odersky@gmail.com> | 2012-04-13 16:27:46 -0700 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2012-04-13 16:27:46 -0700 |
commit | 2744be417e1f2c461068bb2daef9fa8f11822031 (patch) | |
tree | 06580aa466401d86d63176b2af429e9daaf047f9 /tools | |
parent | b5757577c520e6339e4278fa91f725e66561f73e (diff) | |
parent | 1d0610840bb7409f0da084d3cc94e4110dd2e2c4 (diff) | |
download | scala-2744be417e1f2c461068bb2daef9fa8f11822031.tar.gz scala-2744be417e1f2c461068bb2daef9fa8f11822031.tar.bz2 scala-2744be417e1f2c461068bb2daef9fa8f11822031.zip |
Merge branch 'master' into topic/sip18
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/binary-repo-lib.sh | 59 | ||||
-rwxr-xr-x | tools/cleanup-commit | 130 |
2 files changed, 180 insertions, 9 deletions
diff --git a/tools/binary-repo-lib.sh b/tools/binary-repo-lib.sh index 4c5497e803..a22747520c 100755 --- a/tools/binary-repo-lib.sh +++ b/tools/binary-repo-lib.sh @@ -88,12 +88,28 @@ pushJarFile() { # rm $jar } +getJarSha() { + local jar=$1 + if [[ ! -f "$jar" ]]; then + echo "" + elif which sha1sum 2>/dev/null >/dev/null; then + shastring=$(sha1sum "$jar") + echo "$shastring" | sed 's/ .*//' + elif which shasum 2>/dev/null >/dev/null; then + shastring=$(shasum "$jar") + echo "$shastring" | sed 's/ .*//' + else + shastring=$(openssl sha1 "$jar") + echo "$shastring" | sed 's/^.*= //' + fi +} + # Tests whether or not the .desired.sha1 hash matches a given file. # Arugment 1 - The jar file to test validity. # Returns: Empty string on failure, "OK" on success. isJarFileValid() { local jar=$1 - if [[ ! -f $jar ]]; then + if [[ ! -f "$jar" ]]; then echo "" else local jar_dir=$(dirname $jar) @@ -131,6 +147,27 @@ pushJarFiles() { fi } + +checkJarSha() { + local jar=$1 + local sha=$2 + local testsha=$(getJarSha "$jar") + if test "$sha" == "$testsha"; then + echo "OK" + fi +} + +makeCacheLocation() { + local uri=$1 + local sha=$2 + local cache_loc="$cache_dir/$uri" + local cdir=$(dirname $cache_loc) + if [[ ! -d "$cdir" ]]; then + mkdir -p "$cdir" + fi + echo "$cache_loc" +} + # Pulls a single binary artifact from a remote repository. # Argument 1 - The uri to the file that should be downloaded. # Argument 2 - SHA of the file... @@ -138,16 +175,19 @@ pushJarFiles() { pullJarFileToCache() { local uri=$1 local sha=$2 - local cache_loc=$cache_dir/$uri - local cdir=$(dirname $cache_loc) - if [[ ! -d $cdir ]]; then - mkdir -p $cdir - fi + local cache_loc="$(makeCacheLocation $uri)" # TODO - Check SHA of local cache is accurate. - if [[ ! -f $cache_loc ]]; then + if test -f "$cache_loc" && test "$(checkJarSha "$cache_loc" "$sha")" != "OK"; then + echo "Found bad cached file: $cache_loc" + rm -f "$cache_loc" + fi + if [[ ! -f "$cache_loc" ]]; then curlDownload $cache_loc ${remote_urlbase}/${uri} + if test "$(checkJarSha "$cache_loc" "$sha")" != "OK"; then + echo "Trouble downloading $uri. Please try pull-binary-libs again when your internet connection is stable." + exit 2 + fi fi - echo "$cache_loc" } # Pulls a single binary artifact from a remote repository. @@ -162,7 +202,8 @@ pullJarFile() { local version=${sha1% ?$jar_name} local remote_uri=${version}/${jar#$basedir/} echo "Resolving [${remote_uri}]" - local cached_file=$(pullJarFileToCache $remote_uri $version) + pullJarFileToCache $remote_uri $version + local cached_file=$(makeCacheLocation $remote_uri) cp $cached_file $jar } diff --git a/tools/cleanup-commit b/tools/cleanup-commit new file mode 100755 index 0000000000..400d434359 --- /dev/null +++ b/tools/cleanup-commit @@ -0,0 +1,130 @@ +#!/bin/bash + +## +## The cleanup-commit script +## ------------------------- +## This little script will cleanup your commit before you send it. You need to add the files to the staged area and +## run this script. It will automatically cleanup tabs and trailing spaces for the files you added and then add the +## clean versions to the staging area. +## +## Use at your own risk, I spent some time making the script error-proof so it will abort if sees any inconsistency, +## but of course playing around with your commit might break things. Btw, it saves the original file to file.bak. +## +## Happy hacking! +## + +ABORT="Ab0rT0p3r4+|0n" + +# +# Cleanup function +# +function cleanup { + echo Cleaning up $1... + # prepare the ground + rm -rf $1.bak + # compress <TAB> into double <BLANK> and eliminate trailing <BLANC>s + sed -i.bak -e 's/\t/ /g' -e 's/ *$//' $1 +} + + +# +# Get the git status for the current staged commit +# +FULLSTATUS=`git status --porcelain` + +if [ $? -ne 0 ] +then + echo "Unable to run git. Check if:" + echo " -- git is installed (you can run git in the command line)" + echo " -- the current directory is a valid git repository" + exit 1 +fi + +echo + +# +# Based on the status decide what files will get cleaned up +# +CLEANUP_FILES=`echo "$FULLSTATUS" | while read LINE +do + + STATUS=$(echo $LINE | sed 's/^\(..\).*$/\1/') + if [ $? -ne 0 ] + then + echo "Could not get the status for line: $LINE" + echo " -- you have the basic unix tools installed (grep, cut, sed)" + echo $ABORT # This goes to CLEANUP_FILES + exit 1 + fi + + FILES=$(echo $LINE | sed 's/^..//') + FILE1=$(echo $FILES | cut -d ' ' -f 1) + FILE2=$(echo $FILES | cut -d ' ' -f 3) + + case "$STATUS" in + [AMRDC]" ") + case "$STATUS" in + "A "|"M ") + echo $FILE1 + ;; + "R ") + echo $FILE2 + ;; + "D ") + #nothing to do + ;; + "C ") + echo $FILE1 + echo $FILE2 + ;; + esac + ;; + "??") + # File is not tracked, no need to do anything about it + # echo Untracked: $FILE1 + ;; + *) + echo "Unstable status of file $FILE1 (\"$STATUS\")" >&2 + echo "Aborting cleanup!" >&2 + echo $ABORT # This goes to CLEANUP_FILES + exit 1 + esac +done; echo $CLEANUP_FILES` + + +# +# Perform actual cleanup +# +case $CLEANUP_FILES in +*"$ABORT") + echo + exit 1 + ;; +"") + echo Nothing to do! + ;; +*) + cd $(git rev-parse --show-toplevel) + + if [ $? -ne 0 ] + then + echo Unexpected error: cannot cd to the repository root + echo Aborting cleanup! + exit 1 + fi + + echo "$CLEANUP_FILES" | while read FILE + do + cleanup $FILE + done + + cd - &>/dev/null + + echo + echo "Cleanup done: " + echo " - original files saved as .bak" + echo " - you can do \"git diff\" to see the changes the script did" + echo " - you can do \"git commit -a\" to commit the cleaned up files" + echo + ;; +esac |