aboutsummaryrefslogtreecommitdiff
path: root/utils/br-reproduce-build
blob: 7073d7b26ea12aaacf66402e7730fb14e8f17231 (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
#!/bin/bash

# A directory that contains an existing Git repository of
# Buildroot. The script will git clone from it instead of git cloning
# from the official repo, in order to reduce the clone time.
BASE_GIT="${BASE_GIT:-/home/test/buildroot/}"

# Location where the output directories will be created. One
# subdirectory, named after the build ID will be created for each
# build.
OUTPUT_DIR="${OUTPUT_DIR:-$(pwd)}"

if [ $# -ne 1 ] ; then
    echo "Usage: $0 buildid" ;
    echo "  buildid is the SHA1 of the build result, as found on http://autobuild.buildroot.net"
    exit 1 ;
fi

# The location where the results are stored on the server is
# of the form 'xxx/xxxyyyyyyyy', where 'xxx' are the first
# three chars of the sha1, and 'xxxyyyyyyyy' is the full sha1.
#
# We accept the user to pass either the full sha1, or the full
# sha1 prefixed with the 'xxx' part. So we just extract the sha1
# from the value passed by the user
BUILD_ID="${1#*/}"

# The build directory is only made of the full sha1, without the
# leading 'xxx/' part
BUILD_DIR="${OUTPUT_DIR}/${BUILD_ID}"

# Now, we construct the BUILD-ID as it is expected to be on the server:
# - extract the first three chars of the sha1: use some shell trickery:
# - prepend those three chars and a '/' to the full sha1
BUILD_ID_SHORT="${BUILD_ID:0:3}"
BUILD_ID="${BUILD_ID_SHORT}/${BUILD_ID}"

mkdir -p "${BUILD_DIR}"
if [ $? -ne 0 ] ; then
    echo "Cannot create output directory"
    exit 1
fi

wget -O "${BUILD_DIR}/config" "http://autobuild.buildroot.org/results/${BUILD_ID}/config"
if [ $? -ne 0 ] ; then
    echo "Cannot get configuration for build ${BUILD_ID}"
    rm -f "${BUILD_DIR}"
    exit 1
fi

wget -O "${BUILD_DIR}/gitid" "http://autobuild.buildroot.org/results/${BUILD_ID}/gitid"

cd "${BUILD_DIR}"
git clone "${BASE_GIT}" buildroot
if [ $? -ne 0 ] ; then
    echo "Cannot clone Buildroot Git repository"
    rm -rf "${BUILD_DIR}"
    exit 1
fi

cd buildroot

git remote set-url origin git://git.busybox.net/buildroot

git fetch
if [ $? -ne 0 ] ; then
    echo "Cannot fetch Buildroot official Git repository"
    rm -rf "${BUILD_DIR}"
    exit 1
fi

git checkout $(cat ../gitid)
if [ $? -ne 0 ] ; then
    echo "Cannot checkout commit " $(cat ../gitid)
    rm -rf "${BUILD_DIR}"
    exit 1
fi

# Handle cases of testing reproducibility failures.
# Run the build in different output directories if BR2_REPRODUCIBLE=y
# and run diffoscope on the generated images. Output of diffoscope is
# saved in the "output-1" directory.
# NOTE: You should have diffoscope installed in order to test
# reproducibility failures.
if grep -Fxq "BR2_REPRODUCIBLE=y" "${BUILD_DIR}/config"; then
    mkdir ../output-1 ../output-2
    cp "${BUILD_DIR}/config" ../output-1/.config
    cp "${BUILD_DIR}/config" ../output-2/.config
    make olddefconfig O=../output-1
    make olddefconfig O=../output-2
    make 2>&1 O=../output-1 | tee logfile-1 && make 2>&1 O=../output-2 | tee logfile-2
    if test $? -ne 0 ; then exit 1 ; fi
    PREFIX=$(make --no-print-directory O=../output-1 printvars VARS=TARGET_CROSS | cut -c 14- | head -c -1)
    IMAGE_1="../output-1/images/rootfs.tar"
    IMAGE_2="../output-2/images/rootfs.tar"
    diffoscope ${IMAGE_1} ${IMAGE_2} --tool-prefix-binutils ${PREFIX} --text ../output-1/diffoscope_results.txt
else
    mkdir ../output
    cp "${BUILD_DIR}/config" ../output/.config
    make olddefconfig O=../output/
    make 2>&1 O=../output | tee logfile
fi