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