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