summaryrefslogtreecommitdiff
path: root/tb/tb
blob: 46685cca6b91d8311f1a46ea12a3d8dc840f0c4e (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
#!/usr/bin/env bash
# -*- tab-width : 4; indent-tabs-mode : nil -*-
#
#    Copyright (C) 2011-2013 Norbert Thiebaud
#    License: GPLv3
#

#
# ATTENTION Developers: see tb_internal.sh for information
# about design, naming conventions etc...
#

# run debug=1 tb ... to debug
if [ -n "$debug" ] ; then
    set -x
fi

# get the absolute path to the directory containing the main script
tb_BIN_DIR=$(dirname "$0")
pushd ${tb_BIN_DIR} > /dev/null
tb_BIN_DIR=$(pwd)
popd > /dev/null

source "${tb_BIN_DIR?}/tb_internals.sh"

do_help()
{

cat <<EOF

tb : tinderbox script for libreoffice
=====================================

tb is a script to run un-attended build on multiple repos, for multiple branches
and for gerrit patch review system.

tb has two main mode of operation. a tinderbox (tb) mode and a gerrit mode.
It can also operate in 'dual' mode, doing both tb and gerrit mode.

In 'tb' mode, tb monitor a certain number of defined 'branches' for new commits.
When one or more new commits are detected on a monitored branches
tb initiate a build on that branch and typically inform a tinderbox-server
of the result of that build.

In 'gerrit' mode, tb poll a buildbot gerrit plugin for new patch to test build.
when such a task is found, tb checkout the patch concerned, test build it and
report the result to gerrit.

In 'dual' mode, tb alternate between the tb and gerrit mode. In dual mode
there are 3 different scheduling modes:
The 'fair' mode, which tries tb and gerrit build alternatively.
The tb-gerrit mode, in which tb does primarily tb build unless there is no such
build to do, in which case it does gerrit build until a new tb build is needed
The gerrit-tb mode, in which tb does primarily gerrit build unless there is no
such build to do, in which case it does tb build until a new gerrit build is
needed.

tb can only run any number of profile at the time.

The configuration is organized as:

  ~/.tb/config
       /meta/
       /phases.sh
       /profiles/<profile_name>/autogen.lastrun
       /profiles/<profile_name>/config
       /profiles/<profile_name>/false_negatives
       /profiles/<profile_name>/phases.sh

The configuration is obtained for a given profile by sourcing, in this order,

~/.tb/config
    /profiles/<profile_name>/config

Each build needs an autogen configuration for the building of libreoffice.

    /profiles/<profile_name>/autogen.lastrun

Some tb configuration parameters can be specified at the global level 'G',
some at the profile level 'P'
If a parameter is specified at multiple level then the lowest level prevail.
In other words:  P prevail over G.

The following variables can be specified in tb's configuration files.

TB_ACTIVE_PROFILES=<profile_name> [<profile_name> ...]
                                  List of active profile.
                                  This is a G level only parameter
                                  This provide a default value in case -p <profile> is not
                                  present on the command line, but is required.
TB_BIBISECT_DIR=<path> Location of a git bibisect repository
                       This is a tb-mode only parameter. This is ignored in gerrit mode
TB_BIBISECT_GC=[0|1] Indicate if a git gc should be run after each bibisect version
                     is stored
                     Default is 0.
                     This is a tb-mode only parameter. This is ignored in gerrit mode
TB_BIBISECT_PUSH=[0|1] Indicate if a git push should be issued after each bibisect
                       version is stored.
                       Default is 0.
                       This is a tb-mode only parameter. This is ignored in gerrit mode
TB_BIBISECT=[0|1] Indicate if a bibisect version should be saved.
                  Default is 0.
                  This is a tb-mode only parameter. This is ignored in gerrit mode
TB_BRANCH=<name>  name of the branch that profile monitor, used to query gerrit or to report to tinbuild
                  Default:"master"
TB_BUILD_DIR=<path> Directory to use as a build directory. If specified, it must exist.
                    Default to TB_GIT_DIR.
TB_LOCAL_REFSPEC=<ref> Name of the branch in the local repo
                       Default to the name of the branch in the configuration
                       This is a P-level only parameter
                       This is a tb-mode only parameter. This is ignored in gerrit mode
TB_MODE=(fair|fix)  Indicate the scheduling fairness to use
                    This is a G only parameter
                    in 'fair' mode active profiles are rotated such that
                    when a profile get build it goes at the end of the queue
                    for the next iteration... fix mean that profiles are attempted
                    in the order they are specified, always.
TB_REMOTE_REFSPEC=<ref> Name of the branch on the remote repo.
                        Default to the name of the branch in the configuration
                        This is a P-level only parameter
                        This is a tb-mode only parameter. This is ignored in gerrit mode
TB_TYPE=(gerrit|tb) Indicate if the profile describe a gerrit or tb build
                    This is a mandatory P-level only parameter
TB_GERRIT_HOST=<host> Gerrit host to contact in gerrit mode.
                     This parameter is mandatory to use a gerrit mode.
TB_GERRIT_TEST=(1|0) Indicate that this gerrit profile is for test only.
                     The get request to the gerrit buildbot plugin will be made
                     as 'test'. and therefore will not be consumed as real request.
TB_GIT_DIR=<path> Location of the libreoffice core git repo to use for a build.
                  This parameter is mandatory.
TB_INCREMENTAL=[0|1] Indicate that one wants to do incremental build, iow skip the clean phase
                     This apply only to tb build, as tb builds are normally progressive
                     in time, whereas gerrit builds can be all over the place...
                     This only make sense if each branch that is meant to be built incrementally
                     has its own build directory (which for now also mean its own git repo
                     at least until gbuildification is complete and the source tree is finally
                     treated as a read-only zone.
TB_LOGFILE=<path> File where tb will log message about its operation.
                  The file does not have to exist, but the path containing the file must.
                  This is only for message issued by tb itself.. this does no relate to build
                  logs.
TB_METADATA_DIR=<path> Directory where tb will store state information regarding the different
                      branches it monitors. In tb mode, tb is keeping track of the last
                      successful build point, in order to be able to notify the committers
                      involved in patches since that point in case of build failure.
                      tb also keeps track of the last time it uploaded a version
                      when such upload options is specified.
                      All the files used to keep track of theses are store in this directory,
                      tb will attempt to create the directory if it does not exist
                      This is G or P-level parameter only.
                      This parameter is mandatory.
TB_NAME=<name> Name of the tinderbox. see http://wiki/documentfoundation.org/Development/Tinderbox
               for naming conventions.
               This is G or P-level parameter only
               This parameter is mandatory.
TB_NICE=<prefix> Value to prepend to expensive command like MAKE to nice it
                 for example TB_NICE="nice ionice -c3"
TB_OWNER=<email> Email of the owner/operator of the tinderbox
                 This is G or P-level parameter only.
                 This parameter is mandatory.
TB_POLL_DELAY=<num_of_seconds> Delay in second between two attempts to pool the states of branches.
TB_POST_BUILD_DELAY=<num_of_seconds> Pause in second after a build.
                                     G Level parameter
TB_SMTP_HOST=<smtp_hostname> Hostname of the smtp server to use to send email.
                             This parameter is mandatory in tb mode
TB_SMTP_TLS=<auto|yes|no> Email TLS mode - auto-detect, enforce, or switch-off.
TB_SMTP_PASSWORD=<password> Password associated with TB_SMTP_USER.
                            This parameter is mandatory if TB_SMTP_USER is specified
TB_SMTP_USER=<username> Username to login to the smtp server.
                        If your smtp server does not require authentication, you can omit this.
TB_TINDERBOX_BRANCH=<name> Name associated with a branch on the tinderbox server.
                           The tinderbox server need to have a branch name associated with any
                           build report. The server only recognize a preset list of such names
                           and they do not necessarily match your local branch names.
                           This is a tb-mode only parameter. This is ignored in gerrit mode.
TB_TRIGGER_FILE=<absolute_filename> This is the location of a 'trigger' file.
                                    If specified the existence of that file will be
                                    tested, and a build for the associated branch
                                    will not be run unless the file exists.
                                    At the end of a successful build, the trigger
                                    file is removed by tb.
                                    This allows to trigger some build at periodic time with a cron
                                    For instance you could have a cron that touch a trigger file
                                    weekly to trigger a full localized build.
                                    This is a tb-mode only parameter. This is ignored in gerrit mode

In general, when a command line argument influence on of the parameter listed
above, it can only override a G-level specification. P-level take, for the most
part precedence of the command-line.

The rational is that tb is meant to be a un-attended long running job, Ideally
taking no argument what-so-ever.


Note for tinbuild2 user: tb does _not_ require a primer build. but it will not
send email to committers in case a failure until it has had a prior successful
build for a given branch.

EOF
}



#
# Main
#

case "$1" in
    help|--help)
        do_help "$@"
        exit $?
        ;;
    stop)
        touch ~/.tb/stop
        exit $?
        ;;
esac

set_factory_default

load_config

set_global_defaults

while [ "${1}" != "" ]; do
    parm=${1%%=*}
    arg=${1#*=}
    has_arg=
    if [ "${1}" != "${parm?}" ] ; then
        has_arg=1
    else
        arg=""
    fi

    case "${parm}" in
        -h|--help)  # display help
            do_help
            exit
            ;;
        -k)  # do not override the local autogen.lastrun if present
            tb_KEEP_AUTOGEN="1"
            ;;
        -p)  # profile to use to determine extra parameters (email mostly) and autogen arguments
            if [ -z "${has_arg}" ] ; then
                shift;
                arg="$1"
            fi
            if [ -z "${arg}" ] ; then
                die "Missing argument for option $parm"
            else
                if [ -z "${tb_ACTIVE_PROFILES}" ] ; then
                    tb_ACTIVE_PROFILES="${arg}"
                else
                    tb_ACTIVE_PROFILES="${tb_ACTIVE_PROFILES?} ${arg}"
                fi
            fi
            ;;
        -t )
            # test mode
            TB_TEST=1
            ;;
        -v)  # print more messages
            V=1
            ;;
        -z)
            # to run an initial build (without sending any email) to establish a 'baseline'
            # only the first profile is considered
            tb_ONE_SHOT="1"
            ;;
        -*)
            die "Invalid option $1"
            ;;
        *)
            die "Invalid argument $1"
            ;;
    esac
    shift
done

validate_active_profiles

# remove lingering stop semaphore file
rm -f ~/.tb/stop

if [ "${tb_ONE_SHOT}" = "1" ] ; then
    run_primer
else
    run_loop
fi