shellfiles/build_mercurial.sh
author Claus Gittinger <cg@exept.de>
Thu, 28 Mar 2019 13:54:38 +0100
changeset 542 aa25a71be62a
parent 159 40cdb9aa191d
permissions -rw-r--r--
#DOCUMENTATION by cg
class: stx_goodies_builder_quickSelfTest
class definition

class: stx_goodies_builder_quickSelfTest class
added:18 methods
jan@159
     1
#!/bin/bash 
jan@159
     2
# Simple Unix shell script to build Mercurial using Jenkins CI
jan@159
     3
# Designed to run under Cygwin as well. 
jan@158
     4
jan@158
     5
PROJECT="Mercurial Support"
jan@158
     6
jan@159
     7
jan@159
     8
# ### START OF common.sh.in ##########################################
jan@159
     9
#
jan@159
    10
# Common set of function to build a project. 
jan@159
    11
# 
jan@159
    12
 
jan@159
    13
jan@158
    14
# Determine operating system, bit simple but works
jan@158
    15
if [ "$OS" == "Windows_NT" ]; then
jan@158
    16
    WIN32=1
jan@158
    17
    UNIX=0
jan@158
    18
else
jan@158
    19
    WIN32=0
jan@158
    20
    UNIX=1
jan@158
    21
fi
jan@158
    22
jan@159
    23
# =====================================================
jan@158
    24
# Utility functions
jan@159
    25
# =====================================================
jan@158
    26
jan@159
    27
jan@159
    28
# Simple logging functions
jan@159
    29
function info {
jan@159
    30
    echo "[INF] $1"
jan@159
    31
    if [ ! -z "$2" ]; then
jan@159
    32
        echo "      $2"
jan@159
    33
    fi
jan@159
    34
}
jan@159
    35
jan@159
    36
function error {
jan@159
    37
    echo     "[ERR] $1"
jan@159
    38
    if [ ! -z "$2" ]; then
jan@159
    39
        echo "      $2"
jan@159
    40
    fi
jan@159
    41
    exit 1
jan@159
    42
}
jan@159
    43
jan@159
    44
# Run make in current directory. Caller should cd to target 
jan@159
    45
# directory before calling this method.
jan@158
    46
function mk {
jan@158
    47
    if [ "$WIN32" == "1" ]; then
jan@158
    48
    	cmd /C bmake.bat $1 $2
jan@158
    49
    else
jan@158
    50
    	if [ ! -f makefile ]; then
jan@158
    51
    	   if [ -f Makefile ]; then
jan@158
    52
    	   	make mf || error "Failed to generate makefile (make mf)"
jan@158
    53
    	   else
jan@158
    54
    	   	make -f Makefile.init mf || error "Failed to generate makefile (make -f Makefile.init mf)"
jan@158
    55
    	   fi
jan@158
    56
    	fi
jan@158
    57
    	make $1 $2 || error "Make failed"
jan@158
    58
    fi
jan@158
    59
}
jan@158
    60
jan@159
    61
# Run tests for package specified in first argument. 
jan@159
    62
function sunit {    
jan@158
    63
    pushd stx/goodies/builder/reports
jan@158
    64
    info "Running tests for $1"
jan@158
    65
    if [ "$WIN32" == "1" ]; then
jan@159
    66
        cmd /C report-runner.bat -D ../../../.. -r Builder::TestReport -p "$1" || error "Failed to run reports"
jan@158
    67
    else
jan@159
    68
        (echo "" | ./report-runner.sh -D ../../../.. -r Builder::TestReport -p "$1") || error "Failed to run reports"
jan@158
    69
    fi
jan@158
    70
    popd
jan@158
    71
}
jan@158
    72
jan@159
    73
# Main function. Performs complete build or given task
jan@158
    74
function main {
jan@158
    75
    pushd "$BUILD"
jan@158
    76
    if [ -z "$1" ]; then
jan@158
    77
    	info "Checking out..."
jan@158
    78
    	checkout
jan@158
    79
    	info "Compiling..."
jan@158
    80
    	compile
jan@158
    81
    	info "Running tests..."
jan@158
    82
    	runtests
jan@158
    83
    else
jan@158
    84
        case "$1" in
jan@158
    85
            checkout)
jan@158
    86
    	        info "Checking out..."
jan@158
    87
    	        checkout;;
jan@158
    88
            compile)
jan@158
    89
                info "Compiling..."
jan@158
    90
    	        compile;;
jan@158
    91
            tests)
jan@158
    92
    	        info "Running tests..."
jan@158
    93
    	        runtests;;
jan@158
    94
            test)
jan@158
    95
    	        info "Running tests..."
jan@158
    96
    	        runtests;;
jan@158
    97
            *)
jan@158
    98
                error "Invalid command ($1)"
jan@158
    99
        esac
jan@158
   100
    fi
jan@158
   101
    popd
jan@158
   102
    exit 0
jan@158
   103
}
jan@158
   104
jan@158
   105
# Setup...
jan@159
   106
jan@158
   107
if [ "$WIN32" == "1" ]; then
jan@158
   108
    # WINDOWS
jan@158
   109
    # MUST export this, otherwise libjpeg fails to build!!!"
jan@158
   110
    if [ -z "$BCB"]; then
jan@158
   111
        export BCB="C:\Borland\BCC55"
jan@158
   112
    fi
jan@158
   113
    # To make cvs/ssh happy
jan@158
   114
    if [ -z "$CVS_RSH" ]; then
jan@158
   115
        export CVS_RSH=plink
jan@158
   116
    fi
jan@158
   117
    # Set home
jan@158
   118
    export HOME=$USERPROFILE
jan@158
   119
else
jan@158
   120
    # LINUX
jan@158
   121
    # to get Mercurial on build slave
jan@158
   122
    export PATH=$PATH:/home/vrany/bin
jan@158
   123
fi
jan@158
   124
jan@158
   125
if [ -z "$CVSROOT" ]; then
jan@158
   126
    error "CVSROOT not set!"
jan@158
   127
fi
jan@158
   128
jan@158
   129
# Sorry, it's lot easier for all to have all the messages in EN :-)
jan@158
   130
export LANG=en_GB.UTF-8
jan@158
   131
jan@158
   132
# When run interactively, Jenkins env variables
jan@158
   133
# may not be set...
jan@158
   134
if [ -z "$WORKSPACE" ]; then
jan@158
   135
  WORKSPACE="$PWD"
jan@158
   136
    INTERACTIVE=1
jan@158
   137
else
jan@158
   138
    INTERACTIVE=0
jan@158
   139
fi
jan@158
   140
jan@158
   141
if [ "$INTERACTIVE" == "0" ]; then
jan@158
   142
  if [ "$WIN32" == "1" ]; then
jan@158
   143
    WORKSPACE="$PWD"
jan@158
   144
  fi
jan@158
   145
fi
jan@158
   146
jan@158
   147
if [ -z "$BUILD_NUMBER" ]; then
jan@158
   148
    BUILD_NUMBER=$(date +%Y_%m_%d_interactive)
jan@158
   149
fi
jan@158
   150
jan@158
   151
BUILD="."
jan@158
   152
jan@158
   153
jan@158
   154
echo "INFO: BUILD=\"$BUILD\""
jan@158
   155
jan@158
   156
if [ -d "$BUILD" ]; then
jan@158
   157
    if [ "$BUILD" != "." ]; then
jan@158
   158
        info "Build directory already exists!"
jan@158
   159
    fi
jan@158
   160
else
jan@158
   161
    mkdir -p "$BUILD"
jan@158
   162
fi
jan@158
   163
jan@159
   164
jan@159
   165
# ===================================================================
jan@159
   166
# Actual build functions. 
jan@159
   167
# ===================================================================
jan@159
   168
#
jan@159
   169
# User scripts should override following functions to define a build
jan@159
   170
jan@159
   171
function checkout {
jan@159
   172
    error "You have to override function 'checkout'"
jan@159
   173
}
jan@159
   174
jan@159
   175
function compile {
jan@159
   176
    error "You have to override function 'compile'"
jan@159
   177
}
jan@159
   178
jan@159
   179
function runtests {
jan@159
   180
    info "No tests specified" "To do so, override function runtests"
jan@159
   181
}
jan@159
   182
jan@159
   183
# ### END OF common.sh.in ############################################
jan@159
   184
jan@158
   185
# Checkout
jan@158
   186
function checkout {
jan@158
   187
    # Checkout stx
jan@158
   188
    if [ ! -d stx ]; then
jan@158
   189
      if ! cvs co stx; then
jan@158
   190
        error "CVS: Cannot checkout stx";
jan@158
   191
      fi
jan@159
   192
    #else
jan@159
   193
    #  (cd stx && cvs update -d)
jan@158
   194
    fi
jan@158
   195
jan@158
   196
    # Checkout stx:libscm
jan@158
   197
    repo="https://bitbucket.org/janvrany/stx-libscm"
jan@158
   198
    if [ ! -d stx/libscm ]; then
jan@158
   199
        hg clone "$repo" stx/libscm || error "HG: cannot clone stx:libscm"
jan@158
   200
    else
jan@158
   201
        hg --cwd stx/libscm pull "$repo" || error "HG: cannot pull stx:libscm"
jan@158
   202
        hg --cwd stx/libscm update || error "HG: cannot update stx:libscm"
jan@158
   203
    fi
jan@158
   204
}
jan@158
   205
jan@158
   206
jan@158
   207
# Compile
jan@158
   208
function compile {
jan@158
   209
    TARGETS1="stx stx/libscm/common stx/libscm/mercurial stx/librun"
jan@158
   210
    for target in $TARGETS1; do
jan@158
   211
      if ! (cd "$target" && mk); then
jan@158
   212
        echo "ERROR:  cannot $MAKE in $target"
jan@158
   213
        exit 3
jan@158
   214
      fi
jan@158
   215
    done
jan@158
   216
}
jan@158
   217
jan@158
   218
function runtests {
jan@158
   219
    sunit "stx:libscm/mercurial"
jan@158
   220
}
jan@158
   221
jan@158
   222
jan@158
   223
# Now, call main
jan@158
   224
main $1 $2 $3