summaryrefslogtreecommitdiff
path: root/tools/ci-build
blob: 8e0969cdc52a7d69be9f3bcde955a00862d57a32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/sh
#**************************************************************************
#*                                                                        *
#*                                 OCaml                                  *
#*                                                                        *
#*          Damien Doligez, projet Gallium, INRIA Rocquencourt            *
#*                                                                        *
#*   Copyright 2014 Institut National de Recherche en Informatique et     *
#*     en Automatique.                                                    *
#*                                                                        *
#*   All rights reserved.  This file is distributed under the terms of    *
#*   the GNU Lesser General Public License version 2.1, with the          *
#*   special exception on linking described in the file LICENSE.          *
#*                                                                        *
#**************************************************************************

# This script is run on our continuous-integration servers to recompile
# from scratch and run the test suite.

# arguments:
# 1. architecture: bsd, macos, linux, cygwin, mingw, mingw64, msvc, msvc64
# 2. directory in which to build (trunk, 4.02, etc)
#    for windows, this is relative to $HOME/jenkins-workspace
#    for bsd, macos, linux, this is ignored and the build is always in .
# 3. options:
#    -conf configure-option  add configure-option to configure cmd line
#    -patch1 file-name       apply patch with -p1
#    -newmakefiles           do not use Makefile.nt even for Windows

error () {
  echo "$1" >&2
  exit 3
}

quote1 () {
  printf "'%s'" "`printf %s "$1" | sed -e "s/'/'\\\\\\\\''/g"`";
}

#########################################################################
# be verbose
set -x

#########################################################################
# "Parse" mandatory command-line arguments.

arch="$1"
branch="$2"
shift 2

#########################################################################
# If we are called from a Windows batch script, we must set up the
# Unix environment variables (e.g. PATH).

case "$arch" in
  bsd|macos|linux) ;;
  cygwin|mingw|mingw64)
    . /etc/profile
    . "$HOME/.profile"
  ;;
  msvc)
    . /etc/profile
    . "$HOME/.profile"
    . "$HOME/.msenv32"
  ;;
  msvc64)
    . /etc/profile
    . "$HOME/.profile"
    . "$HOME/.msenv64"
  ;;
  *) error "unknown architecture: $arch";;
esac

#########################################################################

# be verbose and stop on error
set -ex

#########################################################################
# set up variables

# default values
make=make
instdir="$HOME/ocaml-tmp-install"
docheckout=false
makefile=Makefile
configure=unix

case "$arch" in
  bsd)
    make=gmake
    workdir=.
  ;;
  macos)
    workdir=.
  ;;
  linux)
    workdir=.
  ;;
  cygwin)
    workdir="$HOME/jenkins-workspace/$branch"
    docheckout=true
  ;;
  mingw)
    instdir=/cygdrive/c/ocamlmgw
    workdir="$HOME/jenkins-workspace/$branch"
    docheckout=true
    makefile=Makefile.nt
    configure=nt
  ;;
  mingw64)
    instdir=/cygdrive/c/ocamlmgw64
    workdir="$HOME/jenkins-workspace/$branch"
    docheckout=true
    makefile=Makefile.nt
    configure=nt
  ;;
  msvc)
    instdir=/cygdrive/c/ocamlms
    workdir="$HOME/jenkins-workspace/$branch"
    docheckout=true
    makefile=Makefile.nt
    configure=nt
  ;;
  msvc64)
    instdir=/cygdrive/c/ocamlms64
    workdir="$HOME/jenkins-workspace/$branch"
    docheckout=true
    makefile=Makefile.nt
    configure=nt
  ;;
  *) error "unknown architecture: $arch";;
esac

#########################################################################
# Go to the right directory

pwd
cd "$workdir"

#########################################################################
# parse optional command-line arguments (has to be done after the "cd")
# Configure options are not allowed to have spaces or special characters
# for the moment. We'll fix that when needed.
confoptions=""
while [ $# -gt 0 ]; do
  case $1 in
    -conf) confoptions="$confoptions `quote1 "$2"`"; shift;;
    -patch1) patch -f -p1 <"$2"; shift;;
    -newmakefiles) makefile=Makefile;;
    *) error "unknown option $1";;
  esac
  shift
done

#########################################################################
# Do the work

# Tell gcc to use only ASCII in its diagnostic outputs.
export LC_ALL=C

$make -f $makefile distclean || :

if $docheckout; then
  git pull
fi

case $configure in
  unix) eval "./configure -prefix '$instdir' $confoptions";;
  nt)
    cp config/m-nt.h config/m.h
    cp config/s-nt.h config/s.h
    cp config/Makefile.$arch config/Makefile
  ;;
  *) error "internal error";;
esac

$make -f $makefile world.opt
$make -f $makefile install

rm -rf "$instdir"
cd testsuite
$make all