summaryrefslogtreecommitdiff
path: root/bin/push_nightlies.sh
blob: a737f2b9a3db301912ae1cbdc722093cfac06925 (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
#!/usr/bin/env bash

bin_dir=$(dirname "$0")
lock_file="/tmp/tinbuild-upload"
core_dir=$(pwd)

## subroutines
usage ()
{
	echo "Usage: $0 [options]"
	echo "Options:"
	echo "-a          push asynchronously"
	echo "-h          this help"
	echo "-s          staging dir for async upload (default /tmp/${B}"
	echo "-t <time>   pull time of this checkout"
	echo "-n <name>   name of this tinderbox"
	echo "-l <kbps>   bandwidth limit for upload (KBps)"
	echo "-p <dir>    location of the pdb symbol store to update and upload"
}

do_lock()
{
    m="$(uname)"
    case "$m" in
        Darwin)
            ${bin_dir?}/flock "$@"
            ;;
        *)
            flock "$@"
    esac
}


BUILDER_NAME=
PULL_TIME=
BANDWIDTH_LIMIT=20
ASYNC=0
STAGE_DIR=/tmp
SYMBOLS_DIR=
SYMSTORE="/cygdrive/c/Program Files/Debugging Tools for Windows (x64)/symstore"


while getopts aht:n:l:p: opt ; do
	case "$opt" in
        a) ASYNC=1 ;;
		h) usage; exit ;;
        s) STAGE_DIR="${OPTARG}";;
		t) PULL_TIME="${OPTARG// /_}" ;;
		n) BUILDER_NAME="${OPTARG// /_}" ;;
		l) BANDWIDTH_LIMIT="$OPTARG" ;;
		p) SYMBOLS_DIR="${OPTARG}";;
		?) usage; exit ;;
	esac
done

if [ -z "$PULL_TIME" -o -z "$BUILDER_NAME" ] ; then
	echo "missing argument. syntax $0 -t <git_pull_timestap> -n <tinderbox_name>" 1>&2
    exit 1;
else
    PULL_TIME="${PULL_TIME//:/.}"
fi

if [ ! -d "instsetoo_native" ] ; then
	echo "current working directory is not, or not a valid bootstrap git repo" 1>&2
	exit 1;
fi

CURR_HEAD=$(<".git/HEAD")
BRANCH="${CURR_HEAD#*/*/}"
tag="${BRANCH}~${PULL_TIME}"
ssh upload@gimli.documentfoundation.org "mkdir -p \"/srv/www/dev-builds.libreoffice.org/daily/${BRANCH}/${BUILDER_NAME}/${PULL_TIME}\"" || exit 1

if [ -f config_host.mk ] ; then
    INPATH=$(grep INPATH= config_host.mk | sed -e "s/.*=//")
fi

topdir="$PWD"

cd instsetoo_native/${INPATH}

if [ $? != 0 ]; then
    cd workdir
fi

if [ "$ASYNC" = "1" ] ; then
    stage="$STAGE_DIR"
else
    mkdir push 2>/dev/null
    stage="./push"
fi

echo "find packages"
for file in $(find . -name "*.dmg" -o -name '*.apk' -o -name "Lib*O*.tar.gz" -o -name "Lib*O*.exe" -o -name "Lib*O*.zip" -o -path '*/installation/*/msi/install/*.msi' | grep -v "/push/")
do
	target=$(basename $file)
	target="${tag}_${target}"
    if [ "$ASYNC" = "1" ] ; then
	    cp $file "$stage/$target"
    else
	    mv $file "$stage/$target"
    fi
done;

if [ -f ${core_dir}/build_info.txt ] ; then
    target="${tag}_build_info.txt"
    if [ "$ASYNC" = "1" ] ; then
	    cp ${core_dir}/build_info.txt  "$stage/$target"
    else
	    mv ${core_dir}/build_info.txt  "$stage/$target"
    fi
fi


# Add pdb files for binaries of the given extension (exe,dll)
# and type (Library/Executable) to the given list.
add_pdb_files()
{
    extension=$1
    type=$2
    list=$3
    for file in `find install/ -name *.${extension}`; do
        filename=`basename $file .${extension}`
        pdb=`echo workdir/*/LinkTarget/${type}/${filename}.pdb`
        if test -f "$pdb"; then
            echo `cygpath -w $pdb` >>$list
        fi
    done

}

if [ -n "$SYMBOLS_DIR" ] ; then
    pushd "$topdir" >/dev/null
    ssh upload@gimli.documentfoundation.org "mkdir -p \"/srv/www/dev-builds.libreoffice.org/daily/${BRANCH}/${BUILDER_NAME}/symbols\"" || exit 1
    echo "update symbols"
    rm -f symbols-pdb-list.txt
    mkdir -p $SYMBOLS_DIR
    add_pdb_files dll Library symbols-pdb-list.txt
    add_pdb_files exe Executable symbols-pdb-list.txt
    "${SYMSTORE}" add /f @symbols-pdb-list.txt /s `cygpath -w $SYMBOLS_DIR` /t LibreOffice /v "$PULL_TIME"
    rm symbols-pdb-list.txt

    # The maximum number of versions of symbols to keep, older revisions will be removed.
    # Unless the .dll/.exe changes, the .pdb should be shared, so with incremental tinderbox several revisions should
    # not be that space-demanding.
    KEEP_MAX_REVISIONS=5
    to_remove=`ls -1 ${SYMBOLS_DIR}/000Admin | grep -v '\.txt' | grep -v '\.deleted' | sort | head -n -${KEEP_MAX_REVISIONS}`
    for revision in $to_remove; do
        "${SYMSTORE}" del /i ${revision} /s `cygpath -w $SYMBOLS_DIR`
    done
    popd >/dev/null
fi

if [ "$ASYNC" = "1" ] ; then
(
    (
#        do_flock -x 200
        rsync --bwlimit=${BANDWIDTH_LIMIT} -avPe ssh ${stage}/${tag}_* "upload@gimli.documentfoundation.org:/srv/www/dev-builds.libreoffice.org/daily/${BRANCH}/${BUILDER_NAME}/${PULL_TIME}/" || exit 1
        if [ "$?" == "0" ] ; then
	        ssh upload@gimli.documentfoundation.org "cd \"/srv/www/dev-builds.libreoffice.org/daily/${BRANCH}/${BUILDER_NAME}/\" && { rm current; ln -s \"${PULL_TIME}\" current ; }"
        fi
        rm -fr ${stage}/${tag}_*
        if [ -n "$SYMBOLS_DIR" ] ; then
            rsync --bwlimit=${BANDWIDTH} --fuzzy --delete-after -ave ssh ${SYMBOLS_DIR}/ "upload@gimli.documentfoundation.org:/srv/www/dev-builds.libreoffice.org/daily/${BRANCH}/${BUILDER_NAME}/symbols/" || exit 1
        fi
    )# 200>${lock_file?}
) &
else
    rsync --bwlimit=${BANDWIDTH_LIMIT} -avPe ssh ${stage}/${tag}_* "upload@gimli.documentfoundation.org:/srv/www/dev-builds.libreoffice.org/daily/${BRANCH}/${BUILDER_NAME}/${PULL_TIME}/" || exit 1
    if [ "$?" == "0" ] ; then
	    ssh upload@gimli.documentfoundation.org "cd \"/srv/www/dev-builds.libreoffice.org/daily/${BRANCH}/${BUILDER_NAME}/\" && { rm current; ln -s \"${PULL_TIME}\" current ; }"
    fi
    if [ -n "$SYMBOLS_DIR" ] ; then
        rsync --bwlimit=${BANDWIDTH} --fuzzy --delete-after -ave ssh ${SYMBOLS_DIR}/ "upload@gimli.documentfoundation.org:/srv/www/dev-builds.libreoffice.org/daily/${BRANCH}/${BUILDER_NAME}/symbols/" || exit 1
    fi
fi