aboutsummaryrefslogtreecommitdiff
path: root/toolchain-tools
blob: a902d2462668556a9cd79b84260b13303ba0a0cf (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
#!/bin/bash
#
# This script is used to sync the upstream gcc repository, plus a series of
# other related toolchain repositories.
#
# It is highly dependant on the git setup Linaro has on its server. Setup that
# is done with gitolite and gitweb.
#
# How the mirrorin has been done:
# - mirrorin happens in /srv/mirror on the server
# - depending on the mirror type, we can create a git-svn clone in a separate
#   directory, add a new remote on the "original" repo, and then make sure
#   everything is pushed to the real bare repo.
#
# For more info: https://wiki.linaro.org/Platform/Systems/ToolchainsMirror
#

umask 0022  # cron runs us with 0002

GIT_BIN=`which git`
GITOLITE_BIN="/home/git/bin/gitolite"
REPOSITORIES_DIR="/srv/repositories"
TOOLCHAIN_DIR="$REPOSITORIES_DIR/toolchain"
GCC_REPO="$TOOLCHAIN_DIR/gcc.git"
BINUTILS_GDB_REPO="$TOOLCHAIN_DIR/binutils-gdb.git"
MIRROR_DIR="/srv/mirror"
GCC_MIRROR_DIR="$MIRROR_DIR/gcc.git/"
BZR_BRANCH="bzr/linaro-4.7-branch"
UPSTREAM_48_BRANCH="4.8-branch"
UPSTREAM_47_BRANCH="4.7-branch"
SVN_UPSTREAM_48_BRANCH="$MIRROR_DIR/linaro-gcc-4_8-branch"
SVN_UPSTREAM_47_BRANCH="$MIRROR_DIR/gcc-4_7-branch"
SVN_UPSTREAM_49_BRANCH="$MIRROR_DIR/linaro-gcc-4_9-branch"
LINARO_UPSTREAM_48_BRANCH="linaro-4.8-branch"
LINARO_UPSTREAM_49_BRANCH="linaro-4.9-branch"

NEW_GCC_MIRROR_DIR="$MIRROR_DIR/gcc"
NEW_GCC_TOOLCHAIN_DIR="$NEW_GCC_MIRROR_DIR/toolchain"
NEW_GCC_LOCAL_MIRROR="$NEW_GCC_TOOLCHAIN_DIR/gcc.git"
NEW_GCC_MIRROR_FETCH_DIR="$NEW_GCC_MIRROR_DIR/fetch"
NEW_GCC_BRANCHES_DIR="$NEW_GCC_MIRROR_FETCH_DIR/branches"
NEW_GCC_SVN_BRANCHES_DIR="$NEW_GCC_BRANCHES_DIR/svn"
NEW_GCC_UPSTREAM_DIR="$NEW_GCC_MIRROR_FETCH_DIR/gcc.git"

function errcho() {
    # Print on stderr passed messages.
    >&2 echo $1
}

function logiferr() {
    LOG=$($1 2>&1)
    STATUS=$?
    if [ ${STATUS} != 0 ]
    then
        errcho "CMD: '$1' exited with status ${STATUS}"
        if [ "${LOG}" != "" ]
        then
            errcho "WITH LOG OUTPUT: ${LOG}"
        fi
    fi
    return ${STATUS}
}

# Retry command which tends to have transient failures
function stubborn_do() {
    for i in 5 15 60 180 180; do
        LOG=$("$@" 2>&1)
        STATUS=$?
        if [ $STATUS -eq 0 ]; then
            return 0
        fi
        sleep $i
    done
    errcho "CMD: '$@' exited with status $STATUS"
    errcho "WITH LOG OUTPUT: '$LOG'"
    errcho "Last retry delay: ${i}s"
    return $STATUS
}

function new2_gcc() {
    if [ ! -d $MIRROR_DIR/gcc-upstream-pristine.git ]; then
        git clone --mirror git://gcc.gnu.org/git/gcc.git $MIRROR_DIR/gcc-upstream-pristine.git
    fi

    QUIET="${QUIET---quiet}"
    cd $MIRROR_DIR/gcc-upstream-pristine.git
    stubborn_do git fetch $QUIET
    # Set up gitolite environment for local push
    export GL_BYPASS_ACCESS_CHECKS=1
    export GL_LIBDIR=~/gitolite/src/lib
    git push $QUIET --force /srv/repositories/toolchain/gcc.git 'refs/heads/*' 'refs/tags/*' 2>&1 | grep -v "remote: Sending notification emails to"
}

function new_gcc() {
    new_gcc_update_upstream_mirror
    new_gcc_update_local_mirror
    new_gcc_update_svn_branches

    if [ $? -eq 0 ]; then
        cd $NEW_GCC_LOCAL_MIRROR
        # It's a mirror we are pushing, so no --all/--tag.
        logiferr "$GITOLITE_BIN push"

        if [ $? -ne 0 ]; then
            errcho "Error pushing to final destination"
        fi
    fi
}

function new_gcc_update_svn_branches() {
    # SVN branches need to be created manually.
    # Once cloned, the git-svn repo must have as the remote push origin the
    # path defined in $NEW_GCC_UPSTREAM_DIR
    if [ ! -d $NEW_GCC_SVN_BRANCHES_DIR ]; then
        return 0
    fi

    for git_svn_repo in `find $NEW_GCC_SVN_BRANCHES_DIR -type d -name ".git" -prune -exec dirname {} \;`; do
        cd $git_svn_repo
        branch_name=`basename $git_svn_repo`
        logiferr "$GIT_BIN svn rebase"

        if [ $? -ne 0 ]; then
            errcho "Error updating gcc svn branch $branch_name"
            return 1
        fi

        logiferr "$GIT_BIN push origin master:$branch_name"
        if [ $? -ne 0 ]; then
            errcho "Error pushing gcc svn branch $branch_name"
            return 1
        fi
    done

    return 0
}

function new_gcc_update_upstream_mirror() {
    if [ ! -d $NEW_GCC_UPSTREAM_DIR ]; then
        errcho "Missing upstream gcc mirror, cloning it..."

        mkdir -p $NEW_GCC_MIRROR_FETCH_DIR
        cd $NEW_GCC_MIRROR_FETCH_DIR

        logiferr "$GIT_BIN clone -q --mirror git://gcc.gnu.org/git/gcc.git"

        if [ $? -ne 0 ]; then
            errcho "Error creating gcc upstream mirror (fetch)"
            return 1
        fi

    fi

    cd $NEW_GCC_UPSTREAM_DIR
    logiferr "$GIT_BIN remote update"

    if [ $? -ne 0 ]; then
        errcho "Error updating gcc upstream mirror (fetch)"
        return 1
    fi

    return 0
}

function new_gcc_update_local_mirror() {
    if [ ! -d $NEW_GCC_LOCAL_MIRROR ]; then
        errcho "Missing local gcc mirror, cloning it..."

        mkdir -p $NEW_GCC_TOOLCHAIN_DIR
        cd $NEW_GCC_TOOLCHAIN_DIR

        logiferr "$GIT_BIN clone --mirror $NEW_GCC_UPSTREAM_DIR"

        if [ $? -ne 0 ]; then
            errcho "Error cloning gcc upstream mirror (local)"
            return 1
        fi

        cd $NEW_GCC_LOCAL_MIRROR
        logiferr "$GIT_BIN remote set-url --push origin $TOOLCHAIN_DIR/gcc-new.git"
        if [ $? -ne 0 ]; then
            errcho "Error setting correct remote (local)"
            return 1
        fi
    fi

    cd $NEW_GCC_LOCAL_MIRROR
    logiferr "$GIT_BIN remote update"

    if [ $? -ne 0 ]; then
        errcho "Error updating gcc upstream mirror (local)"
        return 1
    fi

    return 0
}

function push_changes() {
    cd $GCC_MIRROR_DIR
    # gitolite, not git, this is important since the push has to happen on the
    # local filesystem and the repository is controlled by gitolite.
    logiferr "$GITOLITE_BIN push --all"
    logiferr "$GITOLITE_BIN push --tags"
}

function update_server_info() {
    logiferr "git --git-dir=$GCC_REPO update-server-info"
}

function update_bzr_branch() {
    cd $GCC_MIRROR_DIR
    logiferr "git bzr sync $BZR_BRANCH"
    push_changes
    update_server_info
}

function update_upstream_48_branch() {
    cd $GCC_MIRROR_DIR
    logiferr "git checkout $UPSTREAM_48_BRANCH"
    logiferr "git pull --rebase"
    logiferr "git checkout master"
}

function update_linaro_upstream_48_branch() {
    cd $GCC_MIRROR_DIR
    logiferr "git checkout $LINARO_UPSTREAM_48_BRANCH"
    logiferr "git pull --rebase"
    logiferr "git checkout master"
}

function update_linaro_upstream_49_branch() {
    cd $GCC_MIRROR_DIR
    logiferr "git checkout $LINARO_UPSTREAM_49_BRANCH"
    logiferr "git pull --rebase"
    logiferr "git checkout master"
}

function update_svn_upstream_48_branch() {
    cd $SVN_UPSTREAM_48_BRANCH
    logiferr "git svn rebase"
}

function update_svn_upstream_47_branch() {
    cd $SVN_UPSTREAM_47_BRANCH
    logiferr "git svn rebase"
}

function update_svn_upstream_49_branch() {
    cd $SVN_UPSTREAM_49_BRANCH
    logiferr "git svn rebase"
}

function update_upstream_47_branch() {
    cd $GCC_MIRROR_DIR
    logiferr "git checkout $UPSTREAM_47_BRANCH"
    logiferr "git pull --rebase"
    logiferr "git checkout master"
}

function update_gcc_repo_remote() {
    cd $GCC_MIRROR_DIR
    logiferr "git remote update"
    logiferr "git pull --all"
}

function update_newlib_mirror() {
    cd $TOOLCHAIN_DIR/newlib.git
    stubborn_do git remote update
}

function update_glibc_mirror() {
    cd $TOOLCHAIN_DIR/glibc.git
    stubborn_do git remote update
}

function pull_git_changes() {
    update_svn_upstream_47_branch
    update_svn_upstream_48_branch
    update_svn_upstream_49_branch
    update_gcc_repo_remote

    update_upstream_47_branch
    update_upstream_48_branch
    update_linaro_upstream_48_branch
    update_linaro_upstream_49_branch

    push_changes
    update_server_info
}

function update_binutils_gdb() {
    cd $BINUTILS_GDB_REPO
    stubborn_do git remote update
    logiferr "git update-server-info"
}

function update_dejagnu_mirror() {
    cd "$MIRROR_DIR/dejagnu.git"
    stubborn_do git remote update
    if [ $? == 0 ]
    then
        logiferr "$GITOLITE_BIN push"
    fi
}

function all() {
    update_bzr_branch
    pull_git_changes
    update_binutils_gdb
}

$@

all_repos="gcc.git gcc-new-deprecated-201505.git glibc.git dejagnu.git newlib.git binutils-gdb.git"
cd /srv/repositories
for repo in $all_repos ; do
    logiferr "/usr/local/bin/grok-manifest -m /var/www/git.linaro.org/manifest.js.gz -t /srv/repositories/ -v -n toolchain/$repo"
done