summaryrefslogtreecommitdiff
path: root/tools/ci/inria/bootstrap
blob: 8fd10457cd26b53b4022a35253a6e54476777534 (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/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 Inria's continuous-integration servers to make sure
# it is possible to bootstrap the compiler.

# To know the slave's architecture, this script looks at the OCAML_ARCH
# environment variable. For a given node NODE, this variable can be defined
# in Jenkins at the following address:
# https://ci.inria.fr/ocaml/computer/NODE/configure

# Other environments variables that are honored:
#   OCAML_CONFIGURE_OPTIONS   additional options for configure
#   OCAML_JOBS                number of jobs to run in parallel (make -j)

# Command-line arguments:
# -conf configure-option  add configure-option to configure cmd line
# -patch1 file-name       apply patch with -p1
# -no-native              do not build "opt" and "opt.opt"
# -jNN                    pass "-jNN" option to make for parallel builds

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

arch_error() {
  configure_url="https://ci.inria.fr/ocaml/computer/${NODE_NAME}/configure"
  msg="Unknown architecture. Make sure the OCAML_ARCH environment"
  msg="$msg variable has been defined."
  msg="$msg\nSee ${configure_url}"
  error "$msg"
}

# Kill a task on Windows
# Errors are ignored
kill_task()
{
  task=$1
  taskkill /f /im ${task} /t || true
}

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

# Functions used to modify the source code

change_exe_magic_number() {
  old=`./runtime/ocamlrun -M`
  new="$1"
  echo Changing executable magic number from ${old} to ${new}
  # Change magic number in runtime/caml/exec.h
  sed -i 's/\x23define \+EXEC_MAGIC \+\x22'${old}\
'\x22/#define EXEC_MAGIC "'${new}'"/' runtime/caml/exec.h
  # Change magic number in utils/config.mlp
  sed -i 's/let \+exec_magic_number \+= \+\x22'${old}\
'\x22/let exec_magic_number = "'${new}'"/' utils/config.mlp
}

remove_primitive()
{
  echo Removing the \'sinh\' primitive
  patch -p1 < tools/ci/inria/remove-sinh-primitive.patch
}

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

#########################################################################
# Save the current directory (on cygwin, /etc/profile changes it)
jenkinsdir="$(pwd)"
echo jenkinsdir=${jenkinsdir}

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

case "${OCAML_ARCH}" in
  bsd|macos|linux) ;;
  cygwin|cygwin64|mingw|mingw64)
    . /etc/profile
    . "$HOME/.profile"
  ;;
  msvc)
    . /etc/profile
    . "$HOME/.profile"
    . "$HOME/.msenv32"
  ;;
  msvc64)
    . /etc/profile
    . "$HOME/.profile"
    . "$HOME/.msenv64"
  ;;
  solaris)
    echo This version of OCaml does not support Solaris. Exiting.
    exit
  ;;
  *) arch_error;;
esac

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

# be considerate towards other potential users of the test machine
case "${OCAML_ARCH}" in
  bsd|macos|linux) renice 10 $$ ;;
esac

# be verbose and stop on error
set -ex

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

# default values
make=make
instdir="$HOME/ocaml-tmp-install"
confoptions="${OCAML_CONFIGURE_OPTIONS}"
make_native=true
cleanup=false
check_make_alldepend=false
dorebase=false
jobs=''
build=''
host=''

case "${OCAML_ARCH}" in
  bsd) make=gmake ;;
  macos) ;;
  linux)
    check_make_alldepend=true
  ;;
  cygwin)
    cleanup=true
    check_make_alldepend=true
  ;;
  cygwin64)
    cleanup=true
    check_make_alldepend=true
    dorebase=true
  ;;
  mingw)
    build='--build=i686-pc-cygwin'
    host='--host=i686-w64-mingw32'
    instdir='C:/ocamlmgw'
    cleanup=true
    check_make_alldepend=true
  ;;
  mingw64)
    build='--build=x86_64-unknown-cygwin'
    host='--host=x86_64-w64-mingw32'
    instdir='C:/ocamlmgw64'
    cleanup=true
    check_make_alldepend=true
  ;;
  msvc)
    build='--build=i686-pc-cygwin'
    host='--host=i686-pc-windows'
    instdir='C:/ocamlms'
    configure=nt
    cleanup=true
  ;;
  msvc64)
    build='--build=x86_64-unknown-cygwin'
    host='--host=x86_64-pc-windows'
    instdir='C:/ocamlms64'
    configure=nt
    cleanup=true
  ;;
  *) arch_error;;
esac

# Make sure two builds won't use the same install directory
instdir="$instdir-$$"

case "${OCAML_JOBS}" in
  [1-9]|[1-9][0-9]) jobs="-j${OCAML_JOBS}" ;;
esac

#########################################################################
# On Windows, cleanup processes that may remain from previous run

if $cleanup; then
  tasks="tee ocamlrun program ocamltest ocamltest.opt"
  for task in ${tasks}; do kill_task ${task}.exe; done
fi

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

pwd
cd "$jenkinsdir"

#########################################################################
# parse optional command-line arguments (has to be done after the "cd")

while [ $# -gt 0 ]; do
  case $1 in
    -conf) confoptions="$confoptions `quote1 "$2"`"; shift;;
    -patch1) patch -f -p1 <"$2"; shift;;
    -no-native) make_native=false;;
    -j[1-9]|-j[1-9][0-9]) jobs="$1";;
    *) 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 -s distclean || :

# `make distclean` does not clean the files from previous versions that
# are not produced by the current version, so use `git clean` in addition.
git clean -f -d -x

# Also make a hard reset
git reset --hard HEAD

if $flambda; then
  confoptions="$confoptions -enable-flambda --enable-flambda-invariants"
fi
eval "./configure $build $host --prefix='$instdir' $confoptions"

$make world

change_exe_magic_number "CI-bootstrap"

remove_primitive

$make coreall
$make bootstrap