shellfiles/common.sh.in
author Claus Gittinger <cg@exept.de>
Thu, 28 Mar 2019 13:54:38 +0100
changeset 542 aa25a71be62a
parent 160 fadfbf804005
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
# ### START OF common.sh.in ##########################################
jan@159
     2
#
jan@159
     3
# Common set of function to build a project. 
jan@159
     4
# 
jan@159
     5
 
jan@159
     6
jan@159
     7
# Determine operating system, bit simple but works
jan@159
     8
if [ "$OS" == "Windows_NT" ]; then
jan@159
     9
    WIN32=1
jan@159
    10
    UNIX=0
jan@159
    11
else
jan@159
    12
    WIN32=0
jan@159
    13
    UNIX=1
jan@159
    14
fi
jan@159
    15
jan@159
    16
# =====================================================
jan@159
    17
# Utility functions
jan@159
    18
# =====================================================
jan@159
    19
jan@159
    20
jan@159
    21
# Simple logging functions
jan@159
    22
function info {
jan@159
    23
    echo "[INF] $1"
jan@159
    24
    if [ ! -z "$2" ]; then
jan@159
    25
        echo "      $2"
jan@159
    26
    fi
jan@159
    27
}
jan@159
    28
jan@159
    29
function error {
jan@159
    30
    echo     "[ERR] $1"
jan@159
    31
    if [ ! -z "$2" ]; then
jan@159
    32
        echo "      $2"
jan@159
    33
    fi
jan@159
    34
    exit 1
jan@159
    35
}
jan@159
    36
jan@159
    37
# Run make in current directory. Caller should cd to target 
jan@159
    38
# directory before calling this method.
jan@159
    39
function mk {
jan@159
    40
    if [ "$WIN32" == "1" ]; then
jan@159
    41
    	cmd /C bmake.bat $1 $2
jan@159
    42
    else
jan@160
    43
    	if [ -f Makefile.init ]; then
jan@160
    44
            make -f Makefile.init || error "Failed to make package"
jan@160
    45
        else
jan@160
    46
            error "No Makefile.init found"
jan@159
    47
    	fi
jan@159
    48
    	make $1 $2 || error "Make failed"
jan@159
    49
    fi
jan@159
    50
}
jan@159
    51
jan@159
    52
# Run tests for package specified in first argument. 
jan@159
    53
function sunit {    
jan@159
    54
    pushd stx/goodies/builder/reports
jan@159
    55
    info "Running tests for $1"
jan@159
    56
    if [ "$WIN32" == "1" ]; then
jan@159
    57
        cmd /C report-runner.bat -D ../../../.. -r Builder::TestReport -p "$1" || error "Failed to run reports"
jan@159
    58
    else
jan@159
    59
        (echo "" | ./report-runner.sh -D ../../../.. -r Builder::TestReport -p "$1") || error "Failed to run reports"
jan@159
    60
    fi
jan@159
    61
    popd
jan@159
    62
}
jan@159
    63
jan@159
    64
# Main function. Performs complete build or given task
jan@159
    65
function main {
jan@159
    66
    pushd "$BUILD"
jan@159
    67
    if [ -z "$1" ]; then
jan@159
    68
    	info "Checking out..."
jan@159
    69
    	checkout
jan@159
    70
    	info "Compiling..."
jan@159
    71
    	compile
jan@159
    72
    	info "Running tests..."
jan@159
    73
    	runtests
jan@159
    74
    else
jan@159
    75
        case "$1" in
jan@159
    76
            checkout)
jan@159
    77
    	        info "Checking out..."
jan@159
    78
    	        checkout;;
jan@159
    79
            compile)
jan@159
    80
                info "Compiling..."
jan@159
    81
    	        compile;;
jan@159
    82
            tests)
jan@159
    83
    	        info "Running tests..."
jan@159
    84
    	        runtests;;
jan@159
    85
            test)
jan@159
    86
    	        info "Running tests..."
jan@159
    87
    	        runtests;;
jan@159
    88
            *)
jan@159
    89
                error "Invalid command ($1)"
jan@159
    90
        esac
jan@159
    91
    fi
jan@159
    92
    popd
jan@159
    93
    exit 0
jan@159
    94
}
jan@159
    95
jan@159
    96
# Setup...
jan@159
    97
jan@159
    98
if [ "$WIN32" == "1" ]; then
jan@159
    99
    # WINDOWS
jan@159
   100
    # MUST export this, otherwise libjpeg fails to build!!!"
jan@159
   101
    if [ -z "$BCB"]; then
jan@159
   102
        export BCB="C:\Borland\BCC55"
jan@159
   103
    fi
jan@159
   104
    # To make cvs/ssh happy
jan@159
   105
    if [ -z "$CVS_RSH" ]; then
jan@159
   106
        export CVS_RSH=plink
jan@159
   107
    fi
jan@159
   108
    # Set home
jan@159
   109
    export HOME=$USERPROFILE
jan@159
   110
else
jan@159
   111
    # LINUX
jan@159
   112
    # to get Mercurial on build slave
jan@159
   113
    export PATH=$PATH:/home/vrany/bin
jan@159
   114
fi
jan@159
   115
jan@159
   116
if [ -z "$CVSROOT" ]; then
jan@159
   117
    error "CVSROOT not set!"
jan@159
   118
fi
jan@159
   119
jan@159
   120
# Sorry, it's lot easier for all to have all the messages in EN :-)
jan@159
   121
export LANG=en_GB.UTF-8
jan@159
   122
jan@159
   123
# When run interactively, Jenkins env variables
jan@159
   124
# may not be set...
jan@159
   125
if [ -z "$WORKSPACE" ]; then
jan@159
   126
  WORKSPACE="$PWD"
jan@159
   127
    INTERACTIVE=1
jan@159
   128
else
jan@159
   129
    INTERACTIVE=0
jan@159
   130
fi
jan@159
   131
jan@159
   132
if [ "$INTERACTIVE" == "0" ]; then
jan@159
   133
  if [ "$WIN32" == "1" ]; then
jan@159
   134
    WORKSPACE="$PWD"
jan@159
   135
  fi
jan@159
   136
fi
jan@159
   137
jan@159
   138
if [ -z "$BUILD_NUMBER" ]; then
jan@159
   139
    BUILD_NUMBER=$(date +%Y_%m_%d_interactive)
jan@159
   140
fi
jan@159
   141
jan@160
   142
BUILD="$PWD"
jan@159
   143
jan@159
   144
jan@159
   145
echo "INFO: BUILD=\"$BUILD\""
jan@159
   146
jan@159
   147
if [ -d "$BUILD" ]; then
jan@160
   148
    if [ "$BUILD" != "$PWD" ]; then
jan@159
   149
        info "Build directory already exists!"
jan@159
   150
    fi
jan@159
   151
else
jan@159
   152
    mkdir -p "$BUILD"
jan@159
   153
fi
jan@159
   154
jan@159
   155
jan@159
   156
# ===================================================================
jan@159
   157
# Actual build functions. 
jan@159
   158
# ===================================================================
jan@159
   159
#
jan@159
   160
# User scripts should override following functions to define a build
jan@159
   161
jan@159
   162
function checkout {
jan@159
   163
    error "You have to override function 'checkout'"
jan@159
   164
}
jan@159
   165
jan@159
   166
function compile {
jan@159
   167
    error "You have to override function 'compile'"
jan@159
   168
}
jan@159
   169
jan@159
   170
function runtests {
jan@159
   171
    info "No tests specified" "To do so, override function runtests"
jan@159
   172
}
jan@159
   173
jan@159
   174
# ### END OF common.sh.in ############################################