summaryrefslogtreecommitdiff
path: root/tcwg-generate-source-cache.sh
blob: a1e3b6e93243b094f6db88ba15197a39a88558dd (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
#!/bin/bash

set -e

usage ()
{
    cat <<EOF
Usage: $0 --dir-abe ABE/SNAPSHOTS --dir-llvm LLVM/REFERENCE [--OPT true/false]
	This script generates source caches.
	"--OPT true/false" options specify what to do:
	--abe-branch <branch>		ABE branch to use; default "tested"
	--generate-abe true/false	Generate ABE snapshots; default "true"
	--generate-llvm true/false	Generate LLVM reference repos; default "true"
	--generate-misc true/false	Generate misc repo and file caches; default "true"
	--update-abe-git true/false	Update ABE git repos; default "true"
	--update-llvm-git true/false	Update LLVM git repos; default "true"
	--verbose true/false		Be verbose; default "false"
EOF
    exit 1
}

snapshots_dir=""
llvm_reference=""
abe_branch=tested
generate_abe=true
generate_llvm=true
generate_misc=true
update_abe_git=true
update_llvm_git=true
verbose=false

OPTS="`getopt -l abe-branch:,dir-abe:,dir-llvm:,generate-abe:,generate-llvm:,generate-misc:,update-abe-git:,update-llvm-git:,verbose: -- "$@"`"
while test $# -gt 0; do
    case $1 in
	--abe-branch) abe_branch="$2"; shift ;;
	--dir-abe) snapshots_dir="$2"; shift ;;
	--dir-llvm) llvm_reference="$2"; shift ;;
	--generate-abe) generate_abe="$2"; shift ;;
	--generate-llvm) generate_llvm="$2"; shift ;;
	--generate-misc) generate_misc="$2"; shift ;;
	--update-abe-git) update_abe_git="$2"; shift ;;
	--update-llvm-git) update_llvm_git="$2"; shift ;;
	--verbose) verbose="$2"; shift ;;
    esac
    shift
done

if $verbose; then
    verbose="set -x"
else
    verbose="set +x"
fi

$verbose

if [ x"$snapshots_dir" = x"" ]; then
    echo "ERROR: no --dir-abe DIR option"
    usage
fi

if [ x"$llvm_reference" = x"" ]; then
    echo "ERROR: no --dir-llvm DIR option"
    usage
fi

# Checkout GNU tools into $snapshots_dir using ABE
generate_abe_snapshots ()
{
    set -e
    $verbose

    local abe_temp="$(dirname "$0")/abe"

    rm -rf $abe_temp
    git clone --branch ${abe_branch} --depth 1 https://git-us.linaro.org/toolchain/abe $abe_temp

    cd $abe_temp
    ./configure --with-local-snapshots=$snapshots_dir

    if [ -e $HOME/.aberc ]; then
	echo "ERROR: $HOME/.aberc detected and it might override ABE's behavior"
	exit 1
    fi

    targets=(
	aarch64-linux-gnu
	aarch64-none-elf
	arm-linux-gnueabihf
	arm-none-eabi
	i686-linux-gnu
	x86_64-linux-gnu
    )

    for t in "${targets[@]}"; do
	for c in gcc5 gcc6 gcc7; do
	    ./abe.sh --target $t --extraconfigdir config/$c --retrieve all
	done
    done
}

# Checkout LLVM tools into $llvm_reference
randomise_llvm_bobblybits ()
{
    set -e
    $verbose

    # Using the llvm scripts would be over-complicated for such a simple task
    # We also don't need all repos (like clang-tools-extra, zorg or www)
    local gitroot=https://git.linaro.org/toolchain/llvm
    local repos="llvm clang compiler-rt lld libcxx libcxxabi libunwind lldb test-suite lnt openmp"
    for repo in $repos; do
	if [ -d "$llvm_reference/$repo" ]; then continue; fi
	git clone --no-checkout "$gitroot/$repo" "$llvm_reference/$repo"
    done
}

# Checkout other repos that we might need
generate_misc_files ()
{
    set -e
    $verbose

    # Distribute Foundation Model to the builders so that containers
    # running there can access Foundation Model via a bind-mount for
    # bare-metal testing.
    tar xf $HOME/public_html/infrastructure/FM000-KT-00035-r9p5-41rel0.tgz -C $snapshots_dir
    chmod -R ugo+rx $snapshots_dir/Foundation_Platformpkg

    # Clone the Linux kernel and LLVM monorepo.
    # Subsequent calls will update it.
    repos=(
	https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
	https://github.com/llvm/llvm-project.git
	https://git.linaro.org/toolchain/jenkins-scripts.git
    )
    for repo in "${repos[@]}"; do
	dir=$(basename $repo)
	dir=$snapshots_dir/$dir
	if [ ! -d $dir/.git ]; then
	    rm -rf $dir
	    git clone --no-checkout $repo $dir
	fi
    done
}

update_git_repos () {
    set -e
    $verbose

    local dir="$1"

    for repo_git in "$dir"/*/.git; do
	(
            local repo
            repo=$(dirname "$repo_git")
	    cd "$repo"
	    # Update and prune local clone
	    git remote update -p
	    find -maxdepth 1 ! -name .git ! -name . -print0 \
		| xargs -0 rm -rf
	)
    done
}

if $generate_abe; then
    mkdir -p $snapshots_dir

    # Remove *.asc files to fix cached incorrect md5sum files
    rm -f $snapshots_dir/*.asc

    update_git_repos $snapshots_dir
    generate_abe_snapshots
fi

if $generate_llvm; then
    mkdir -p $llvm_reference

    update_git_repos $llvm_reference
    randomise_llvm_bobblybits
fi

if $generate_misc; then
    generate_misc_files
fi

if $update_abe_git; then
    update_git_repos $snapshots_dir
fi

if $update_llvm_git; then
    update_git_repos $llvm_reference
fi

echo "Snapshots status:"
du -hs $snapshots_dir/*

echo "LLVM reference status:"
du -hs $llvm_reference/*