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

set -e

scripts=$(dirname $0)
# shellcheck source=jenkins-helpers.sh
. $scripts/jenkins-helpers.sh

usage ()
{
    cat <<EOF
Usage: $0 --dir-abe ABE/SNAPSHOTS [--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-misc true/false	Generate misc repo and file caches; default "true"
	--update-abe-git true/false	Update ABE git repos; default "true"
	--verbose true/false		Be verbose; default "false"
EOF
    exit 1
}

snapshots_dir=""
abe_branch=tested
generate_abe=true
generate_misc=true
update_abe_git=true
verbose=false

getopt -l abe-branch:,dir-abe:,generate-abe:,generate-misc:,update-abe-git:,verbose: -Q -- "$@"
while test $# -gt 0; do
    case $1 in
	--abe-branch) abe_branch="$2"; shift ;;
	--dir-abe) snapshots_dir="$2"; shift ;;
	--generate-abe) generate_abe="$2"; shift ;;
	--generate-misc) generate_misc="$2"; shift ;;
	--update-abe-git) update_abe_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

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

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

    rm -rf $abe_temp
    run_with_timeout_and_retry 10m 3 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 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/tcwg-buildslave/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
	    run_with_timeout_and_retry 1h 3 git clone --no-checkout $repo $dir
	fi
    done
}

update_git_repos () {
    set -e
    $verbose

    local dir="$1"
    while IFS= read -r -d '' repo_git
    do
    (
      local repo
      repo=$(dirname "$repo_git")
	    cd "$repo"
	    # Update and prune local clone
	    run_with_timeout_and_retry 1h 3 git remote update -p
	    find -maxdepth 1 ! -name .git ! -name . -print0 \
		    | xargs -0 rm -rf
    )
    done < <(find "$dir" -name .git -type d -print0)
}

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_misc; then
    generate_misc_files
fi

if $update_abe_git; then
    update_git_repos $snapshots_dir
fi

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