summaryrefslogtreecommitdiff
path: root/MakeRelease.job
blob: c6781e7cee05e5d34678a4c851ac7d866a48366c (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
#!/bin/bash

usage() {
    echo "MakeRelease: [options]"
    echo "     --workspace - Specify an alternate workspace"
    echo "     --target XXX - Specify the target triplet to build"
    echo "     --date XXX - Specify a date, which becmes part pf the release name"
    echo "     --ref XXX - Specify a Git reference directory"
    echo "     --toolchainconfig XXX - [Optional] Explicitly define which toolchain"
    echo "                             to build, e.g., 'default', 'gcc5', 'gcc6'.  "
    echo "                             If not specified, 'default' is the default"
    echo "     --fileserver XXX - Specify the fileserver for tarballs"
    echo "     --manifest XXX - Optionally use a manifest as input"
    echo "     --glibc XXX - Specify Glibc version to build"
    echo "     --gcc XXX - Specify GCC version to build"
    echo "     --binutils XXX - Specify Binutils version to build"
    echo "     --help"
    exit
}

# Jenkins may run only using environment variables, a user needs to always
# supply some command line arguments.
if test $# -eq 0 -a x"${JENKINS_SERVER_COOKIE}" = x; then
    usage
fi

# Set defaults
if test x"${debug}" = x"true"; then
    export CONFIG_SHELL="/bin/bash -x"
else
    export CONFIG_SHELL="/bin/bash"
fi
target=""
ref="snapshots-ref"
fileserver="148.251.136.42"
extra=
toolchain_config=""
user_workspace="${WORKSPACE:-/home/${USER:-buildslave}/workspace}"
logfile=${user_workspace}/MakeRelease-${BUILD_NUMBER}.log

OPTS="`getopt -o r:t:f:d:w:m:l:g:u:h -l target:,ref:,date:,fileserver:,workspace:,toolchainconfig:,manifest:,glibc:,gcc:,binutils:,help`"
while test $# -gt 0; do
    case $1 in
	-w|--workspace) user_workspace=$2 ;;
	-t|--target) target=$2 ;;
	-d|--date) date=$2 ;;
	-r|--ref) ref=$2 ;;
	--toolchainconfig) toolchain_config=$2 ;;
        -f|--fileserver) fileserver=$2 ;;
        -m|--manifest) manifest_src=$2 ;;
        -l|--glibc) glibc_src=$2 ;;
        -g|--gcc) gcc_src=$2 ;;
        -u|--binutils) binutils_src=$2 ;;
        -h|--help) usage ;;
	--) break ;;
    esac
    shift
done

if test x"${target}" != x"native" -a x"${target}" != x; then
    platform="--target ${target}"
fi

shared="/home/buildslave/workspace/shared/"
abe_dir="$(dirname $0)/.."
user_snapshots="${user_workspace}/snapshots"

if test -e ${user_workspace}; then
    cat << EOF > ${user_workspace}/BUILD-INFO.txt
Format-Version: 0.5

Files-Pattern: *
License-Type: open
EOF
fi

# Create a build directory
if test ! -d ${user_workspace}/_build; then
    mkdir -p ${user_workspace}/_build
else
    rm -fr ${user_workspace}/_build/* ${user_workspace}/_build/sysroots/*
fi

# By default, always update all sources
update=""

if test x"${toolchain_config}" != x"" \
	-a x"${toolchain_config}" != x"default"; then
    # Note, we need to specify ../config/FOO because the build is done
    # inside _build directory 1 level up from ABE's top.
    extra="${extra} --extraconfigdir ../config/${toolchain_config}"
fi

guess="`${abe_dir}/config.guess`"
machine="`gcc -dumpmachine`"
if test x"${guess}" != x"${machine}"; then
    arch="`echo ${machine} | cut -d '-' -f 1`"
    CONFIG_SHELL="setarch ${arch} ${CONFIG_SHELL}"
fi

# Use the newly created build directory
cd ${user_workspace}/_build

if ! test -e host.conf; then
  $CONFIG_SHELL ${abe_dir}/configure --with-local-snapshots=${user_snapshots} \
      --with-git-reference-dir=${shared}/snapshots --with-fileserver=${fileserver} --with-remote-snapshots=${ref}

fi

if test x"${date}" != x; then
    release="${date}"    
fi

if test "`echo ${target} | grep -c linux`" -gt 0; then
    if test "`echo ${gcc_src} | grep -c -- '-[56][[:digit:]\.]*'`" -gt 0; then
	libc="--set libc=glibc"
    else
	libc="--set libc=eglibc"
    fi
else
    # ELF and EABI based targets are bare metal only
    libc="--set libc=newlib"
fi

manifest=${manifest:+--manifest ${manifest_src}}
glibc=${glibc_src:+glibc=${glibc_src}}
binutils=${binutils_src:+binutils=${binutils_src}}
gcc=${gcc_src:+gcc=${gcc_src}}
srcs="${gcc} ${binutils} ${glibc} ${manifest}"

# Build a binary release tarball
# Remove logfile if present (for some unknown reason)
rm -f ${logfile}
# Canadian cross builds require a Linux hosted cross compiler first
if test x"${canadian}" = x"true"; then
    $CONFIG_SHELL ${abe_dir}/abe.sh ${update} --release ${release} ${srcs} ${platform} --build all ${libc} ${extra} >> ${logfile}
    host="--host i686-w64-mingw32"
    rm -fr ${local_builds}/${host}/${target}/
else
    host=""
fi
$CONFIG_SHELL ${abe_dir}/abe.sh ${update} --release ${release} --tarbin ${srcs} ${platform} ${host} --build all ${libc} ${extra} >> ${logfile}

# force a failure if abe has build problems.
if test $? -gt 0; then
  exit 1
fi

# Copy the build log to the fileserver
if test -e ${logfile}; then
    echo "Compressing log file..."
    xz ${logfile}
    echo "Copying compressed log file ${logfile}.xz to ${fileserver}:${bases}..."
    scp ${logfile}.xz ${fileserver}:${bases}/
fi

# Copy the source build test results and tarballs to the fileserver
bases="/work/abe/baselines/${release}/${target}"
snaps="/home/abe/var/snapshots/"

# Copy the binary test results to the fileserver
gcc_ver="$(echo $gcc_src | sed -e "s/^gcc-linaro-\([0-9\.]\+\).*\$/gcc-linaro-\1/")"
if [ x"$gcc_ver" = x"$gcc_src" ]; then
    gcc_ver="$release"
fi
binaries="/work/space/binaries/${gcc_ver}/${target}"

manifest="`find ${user_workspace} -name \*manifest.txt`"
ssh ${fileserver} "if test ! -d ${binaries}; then mkdir -p ${binaries}; fi"
scp ${manifest} ${fileserver}:${binaries}/
tarballs="`find ${user_snapshots} -name \*${release}\*.xz -o -name \*${release}\*.asc`"
scp ${tarballs} ${fileserver}:${binaries}/

exit 0