aboutsummaryrefslogtreecommitdiff
path: root/lib/globals.sh
blob: 92681035cf6fd4e8061390ef487e5fac3b0d47b8 (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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/bin/bash
# 
#   Copyright (C) 2013, 2014, 2015, 2016 Linaro, Inc
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# 

# These store all the data used for this test run that can be overwritten by
# command line options.

# Start by assuming it's a native build
build="${build}"
host="${host:-${build}}"
target="${host}"

# we need to read the date once, so that we don't have
# varying dates when midnight occurs during a build.
timestamp=$(date +%s)
date="$(date --date="@${timestamp}" "+%Y.%m.%d")"
hostgcc="$(which gcc)"
host_gcc_version="$(${hostgcc} -v 2>&1 | tail -1)"
binutils="default"
# This is the default clibrary and can be overridden on the command line.
clibrary="auto"
multilib_list="auto"
snapshots="default"
configfile="default"

manifest_version=1.6

# The default timeout.  If you're on a wireless network this
# might not be sufficient and can be overridden at the command
# line.
wget_timeout=10
wget_quiet=
# if output is on a terminal we use the default style (bar), otherwise
# we use the briefest available dot style to reduce the size of the logs
if [ -t 1 ]; then
    wget_progress_style=
else
    wget_progress_style=dot:giga
fi

# This doesn't do any real work, just prints the configure options and make commands
dryrun=no

# config values for the build machine
libc_version=
kernel=${kernel:+${kernel}}
build_arch=${build_arch:+${build_arch}}
hostname=${hostname:+${hostname}}
distribution=${distribution:+${distribution}}

# These are options flags to pass to make, usually just -j N as set by --parallel
extra_makeflags=

# These can be changed by environment variables
if test x"${SNAPSHOTS_URL:-}" != x -o x"${ABE_SNAPSHOTS:-}" != x; then
    snapshots="${SNAPSHOTS_URL:-}"
fi

force=no
verbose=1
network=""

# Don't modify this in this file unless you're adding to it.  This is the list
# of packages that have make check run against them.  It will be queried for
# content when the users passes --check <package> or --excludecheck <package>.
all_unit_tests="glibc newlib gcc gdb binutils"

# Packages to run make check (unit-test) on.  This variable is composed from
# all --check <package> and --excludecheck <package> switches.  Don't modify
# this parameter manually.
runtests=

# Container <user>@<ipaddress>:<ssh_port> to be used in cross-testing.
test_container=

release=""
with_packages="toolchain,sysroot,gdb"
building=yes
# Use system-provided GMP, MPFR, MPC and other prerequisite libraries
# instead of building from them from scratch.
use_system_libs=no

override_linker=
override_cflags=
override_ldflags=
declare -a extra_runtestflags
gcc_override_configure=
check_buffer_workaround=

sources_conf="${sources_conf:-${abe_path}/config/sources.conf}"

list_artifacts=""
build_config=""
bootstrap="no"
gcc_patch_file=""

rerun_failed_tests=false
gcc_compare_results=""
expected_failures=""
flaky_failures=""
failures_expiration_date=""

maintainer_mode=no

prefix=""

# source a user specific config file for commonly used configure options.
# These overide any of the above values.
if test -e ~/.aberc; then
    . ~/.aberc
fi

#
#
#

init_globals_and_PATH()
{
    # Prefix is the root for installing the toolchain.
    if [ -z "$prefix" ]; then
	prefix="$local_builds/destdir/$host"
    fi
    sysroots="$prefix"
    if [ x"$host" != x"$target" ]; then
	sysroots="$sysroots/$target"
    fi

    local host_bin
    # hosttools/ contains runtest (from dejagnu). We need it for testing
    # the toolchain.
    host_bin="$local_builds/hosttools/$host/bin"
    mkdir -p "$host_bin"

    export PATH="$host_bin:$PATH"
    notice "Setting globally PATH=$PATH"
}

import_manifest()
{
#    trace "$*"

    manifest=$1
    if test -f ${manifest} ; then
	local components="$(grep "^# Component data for " ${manifest} | cut -d ' ' -f 5)"

	clibrary="$(grep "^clibrary=" ${manifest} | cut -d '=' -f 2)"
	local ltarget="$(grep ^target= ${manifest}  | cut -d '=' -f 2)"
	if test x"${ltarget}" != x; then
	    target=${ltarget}
	fi

	local manifest_format="$(grep "^manifest_format" ${manifest} | cut -d '=' -f 2)"
	local fixup_mingw=false
	local fixup_linuxhost=true
	case "${manifest_format}" in
	    1.1) # no md5sums or id, but no special handling required
                 fixup_mingw=true ;;
	    1.2) # no manifest id, but no special handling required
                 fixup_mingw=true ;;
	    1.3) fixup_mingw=true ;;
	    1.4) ;;
	    1.5) ;;
	    1.6)
		# linuxhost_only flag is present since 1.6
		fixup_linuxhost=false ;;
	    *)
		error "Imported manifest version $manifest_format is not supported."
		return 1
		;;
	esac
	local variables=
	local i=0
	for i in ${components}; do
	    local md5sum="$(grep "^${i}_md5sum" ${manifest} | cut -d '=' -f 2)"
	    local url="$(grep "^${i}_url" ${manifest} | cut -d '=' -f 2)"
	    local branch="$(grep "^${i}_branch" ${manifest} | cut -d '=' -f 2)"
	    local filespec="$(grep "^${i}_filespec" ${manifest} | cut -d '=' -f 2)"
	    local static="$(grep "^${i}_staticlink" ${manifest} | cut -d '=' -f 2)"
	    local mingw_extraconf="$(grep "^${i}_mingw_extraconf" ${manifest} | cut -d '=' -f 2- | tr ' ' '%'| tr -d '\"')"
	    local mingw_only="$(grep "^${i}_mingw_only" ${manifest} | cut -d '=' -f 2)"
	    local linuxhost_only="$(grep "^${i}_linuxhost_only" ${manifest} | cut -d '=' -f 2)"
	    # Any embedded spaces in the value have to be converted to a '%'
	    # character. for component_init().
	    local makeflags="$(grep "^${i}_makeflags" ${manifest} | cut -d '=' -f 2-20 | tr ' ' '%')"
	    eval "makeflags=${makeflags}"
	    local configure="$(grep "^${i}_configure" ${manifest} | cut -d '=' -f 2-20 | tr ' ' '%'| tr -d '\"')"
	    eval "configure=${configure}"
	    local revision="$(grep "^${i}_revision" ${manifest} | cut -d '=' -f 2)"
	    if test "$(echo ${filespec} | grep -c \.tar\.)" -gt 0; then
		local version="$(echo ${filespec} | sed -e 's:\.tar\..*$::')"
		local dir=${version}
	    else
		local fixbranch="$(echo ${branch} | tr '/@' '_')"
		local dir=${filespec}~${fixbranch}${revision:+_rev_${revision}}
	    fi
	    local srcdir="${local_snapshots}/${dir}"
	    local builddir="${local_builds}/${host}/${target}/${i}-${dir}"
	    case "${i}" in
		glibc|eglibc)
		    # Glibc builds will fail if there is an @ in the path. This is
		    # unfortunate, as @ is used to deliminate the revision string.
		    builddir="$(echo "$builddir" | tr '@' '_')"
		    ;;
		gcc)
		    local configure=
		    local stage1_flags="$(grep ^gcc_stage1_flags= ${manifest} | cut -d '=' -f 2-20 | tr ' ' '%' | tr -d '\"')"
		    eval "stage1_flags=${stage1_flags}"
		    local stage2_flags="$(grep ^gcc_stage2_flags= ${manifest} | cut -d '=' -f 2-20 | tr ' ' '%' | tr -d '\"')"
		    eval "stage2_flags=${stage2_flags}"
		    ;;
		*)
		    ;;
	    esac

            # for old manifests, we have to fix up the missing parameters
            if ${fixup_mingw}; then
                mingw_extraconf=""
                case ${i} in
                    expat|python) mingw_only=yes ;;
                    *) mingw_only=no ;;
                esac
            fi

            if ${fixup_linuxhost}; then
                case ${i} in
                    qemu) linuxhost_only=yes ;;
                    *) linuxhost_only=no ;;
                esac
            fi

	    component_init $i \
			   ${branch:+BRANCH=${branch}} \
			   ${revision:+REVISION=${revision}} \
			   ${url:+URL=${url}} \
			   ${filespec:+FILESPEC=${filespec}} \
			   ${srcdir:+SRCDIR=${srcdir}} \
			   ${builddir:+BUILDDIR=${builddir}} \
			   ${stage1_flags:+STAGE1=\"${stage1_flags}\"} \
			   ${stage2_flags:+STAGE2=\"${stage2_flags}\"} \
			   ${configure:+CONFIGURE=\"${configure}\"} \
			   ${makeflags:+MAKEFLAGS=\"${makeflags}\"} \
			   ${static:+STATICLINK=${static}} \
			   ${md5sum:+MD5SUMS=${md5sum}} \
			   ${mingw_only:+MINGWEXTRACONF=\"${mingw_extraconf}\"} \
			   ${mingw_only:+MINGWONLY=${mingw_only}} \
			   ${linuxhost_only:+LINUXHOSTONLY=${linuxhost_only}}
	    if [ $? -ne 0 ]; then
		error "component_init failed while parsing manifest"
		build_failure
		return 1
	    fi

	    unset stage1_flags
	    unset stage2_flags
	    unset url
	    unset branch
	    unset filespec
	    unset static
	    unset makeflags
	    unset configure
	    unset md5sum
	    unset mingw_only
	    unset mingw_extraconf
	    unset linuxhost_only
	done
    else
	error "Manifest file '${manifest}' not found"
	build_failure
	return 1
    fi

    return 0
}

#
# get_component_list() returns the components which must be built in the
# current configuration
#
get_component_list()
{
    local is_target_linux=false
    if echo ${target} | grep -q -- "-linux-"; then
	is_target_linux=true
    fi

    local builds="dejagnu"

    if [ x"$use_system_libs" = x"no" ]; then
	builds="$builds gmp mpfr mpc"
    fi

    builds="${builds} binutils"

    if $is_target_linux; then
	builds="${builds} linux"
    fi

    if test x"${target}" != x"${build}"; then
        # Build a cross compiler

	# Non-mingw builds skip expat, python and libiconv, but
	# are here so that they are included in the manifest, so
	# linux and mingw manifests can be identical.
	builds="${builds} expat python libiconv"
	if ! is_host_mingw; then
	    builds="${builds} stage1"
	fi
	# As Mingw32 requires a cross compiler to be already built, so we
	# don't need to rebuild the sysroot.
	# ??? Then why do we have "libc" on the list?
	# ??? If we don't need "libc", then we also don't need "linux" added above.
        builds="${builds} libc stage2 gdb"
    else
	# Native build
        builds="${builds} stage2 libc gdb"
    fi
    if $is_target_linux; then
	builds="${builds} gdbserver"
    fi
    # We build QEMU user-mode and system-mode for cross-builds to run tests,
    # and for native (system-mode only) to test kernel boot.
    builds="${builds} qemu"

    # if this build is based on a manifest, then we must remove components from
    # the build list which aren't described by the manifest
    if [ x"${manifest}" != x"" ]; then
        local i
        for i in ${builds}; do
            local match=${i}
            match=${match/stage[12]/gcc}
            match=${match/libc/${clibrary}}
            if ! echo "${toolchain[*]}" | grep -q "\\<${match}\\>"; then
                builds=$(echo "${builds}" | sed -e "s/\\<${i}\\>//")
            fi
        done
    fi

    echo "${builds}"
}

#
# record_artifact() adds an artifact to the artifacts list file, if one
# was configured on the command line
#
record_artifact()
{
    local artifact=$1
    local path=$(readlink -m $2)
    if [ x"${path}" = x"" ]; then
        error "Artifact path '${2}' was invalid."
        return 1
    fi
    notice "Artifact ${artifact} created at ${path}."
    if [ "${list_artifacts:+set}" = "set" -a x"${dryrun}" != xyes ]; then
        echo "${artifact}=${path}" >> "${list_artifacts}"
    fi
}