t / perf / runon commit perf/run: update get_var_from_env_or_config() for subsections (9ba95ed)
   1#!/bin/sh
   2
   3case "$1" in
   4        --help)
   5                echo "usage: $0 [--config file] [other_git_tree...] [--] [test_scripts]"
   6                exit 0
   7                ;;
   8        --config)
   9                shift
  10                GIT_PERF_CONFIG_FILE=$(cd "$(dirname "$1")"; pwd)/$(basename "$1")
  11                export GIT_PERF_CONFIG_FILE
  12                shift ;;
  13esac
  14
  15die () {
  16        echo >&2 "error: $*"
  17        exit 1
  18}
  19
  20run_one_dir () {
  21        if test $# -eq 0; then
  22                set -- p????-*.sh
  23        fi
  24        echo "=== Running $# tests in ${GIT_TEST_INSTALLED:-this tree} ==="
  25        for t in "$@"; do
  26                ./$t $GIT_TEST_OPTS
  27        done
  28}
  29
  30unpack_git_rev () {
  31        rev=$1
  32        echo "=== Unpacking $rev in build/$rev ==="
  33        mkdir -p build/$rev
  34        (cd "$(git rev-parse --show-cdup)" && git archive --format=tar $rev) |
  35        (cd build/$rev && tar x)
  36}
  37
  38build_git_rev () {
  39        rev=$1
  40        for config in config.mak config.mak.autogen config.status
  41        do
  42                if test -e "../../$config"
  43                then
  44                        cp "../../$config" "build/$rev/"
  45                fi
  46        done
  47        echo "=== Building $rev ==="
  48        (
  49                cd build/$rev &&
  50                if test -n "$GIT_PERF_MAKE_COMMAND"
  51                then
  52                        sh -c "$GIT_PERF_MAKE_COMMAND"
  53                else
  54                        make $GIT_PERF_MAKE_OPTS
  55                fi
  56        ) || die "failed to build revision '$mydir'"
  57}
  58
  59run_dirs_helper () {
  60        mydir=${1%/}
  61        shift
  62        while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
  63                shift
  64        done
  65        if test $# -gt 0 -a "$1" = --; then
  66                shift
  67        fi
  68        if [ ! -d "$mydir" ]; then
  69                rev=$(git rev-parse --verify "$mydir" 2>/dev/null) ||
  70                die "'$mydir' is neither a directory nor a valid revision"
  71                if [ ! -d build/$rev ]; then
  72                        unpack_git_rev $rev
  73                fi
  74                build_git_rev $rev
  75                mydir=build/$rev
  76        fi
  77        if test "$mydir" = .; then
  78                unset GIT_TEST_INSTALLED
  79        else
  80                GIT_TEST_INSTALLED="$mydir/bin-wrappers"
  81                # Older versions of git lacked bin-wrappers; fallback to the
  82                # files in the root.
  83                test -d "$GIT_TEST_INSTALLED" || GIT_TEST_INSTALLED=$mydir
  84                export GIT_TEST_INSTALLED
  85        fi
  86        run_one_dir "$@"
  87}
  88
  89run_dirs () {
  90        while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
  91                run_dirs_helper "$@"
  92                shift
  93        done
  94}
  95
  96get_subsections () {
  97        section="$1"
  98        test -z "$GIT_PERF_CONFIG_FILE" && return
  99        git config -f "$GIT_PERF_CONFIG_FILE" --name-only --get-regex "$section\..*\.[^.]+" |
 100        sed -e "s/$section\.\(.*\)\..*/\1/" | sort | uniq
 101}
 102
 103get_var_from_env_or_config () {
 104        env_var="$1"
 105        conf_sec="$2"
 106        conf_var="$3"
 107        # $4 can be set to a default value
 108
 109        # Do nothing if the env variable is already set
 110        eval "test -z \"\${$env_var+x}\"" || return
 111
 112        test -z "$GIT_PERF_CONFIG_FILE" && return
 113
 114        # Check if the variable is in the config file
 115        if test -n "$GIT_PERF_SUBSECTION"
 116        then
 117                var="$conf_sec.$GIT_PERF_SUBSECTION.$conf_var"
 118                conf_value=$(git config -f "$GIT_PERF_CONFIG_FILE" "$var") &&
 119                eval "$env_var=\"$conf_value\"" && return
 120        fi
 121        var="$conf_sec.$conf_var"
 122        conf_value=$(git config -f "$GIT_PERF_CONFIG_FILE" "$var") &&
 123        eval "$env_var=\"$conf_value\"" && return
 124
 125        test -n "${4+x}" && eval "$env_var=\"$4\""
 126}
 127
 128get_var_from_env_or_config "GIT_PERF_REPEAT_COUNT" "perf" "repeatCount" 3
 129export GIT_PERF_REPEAT_COUNT
 130
 131get_var_from_env_or_config "GIT_PERF_DIRS_OR_REVS" "perf" "dirsOrRevs"
 132set -- $GIT_PERF_DIRS_OR_REVS "$@"
 133
 134get_var_from_env_or_config "GIT_PERF_MAKE_COMMAND" "perf" "makeCommand"
 135get_var_from_env_or_config "GIT_PERF_MAKE_OPTS" "perf" "makeOpts"
 136
 137GIT_PERF_AGGREGATING_LATER=t
 138export GIT_PERF_AGGREGATING_LATER
 139
 140cd "$(dirname $0)"
 141. ../../GIT-BUILD-OPTIONS
 142
 143if test $# = 0 -o "$1" = -- -o -f "$1"; then
 144        set -- . "$@"
 145fi
 146run_dirs "$@"
 147./aggregate.perl "$@"