Skip to content

Commit 2c60cb7

Browse files
committed
ci + build
1 parent f774a67 commit 2c60cb7

File tree

6 files changed

+306
-0
lines changed

6 files changed

+306
-0
lines changed

.github/workflows/build.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
on: push
2+
3+
jobs:
4+
build_qemu:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: checkout
8+
uses: actions/checkout@v3
9+
- name: check merge is success
10+
run: bash -c 'if [ -f shazam.log ]; then echo "merge failed"; cat shazam.log; exit 1; fi'
11+
- name: build_container
12+
run: ./run.sh amd64 true
13+
- name: build opt
14+
run: ./run.sh amd64 ./build.sh opt

.github/workflows/new_series.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
on:
2+
schedule:
3+
- cron: '0 * * * *'
4+
workflow_dispatch:
5+
6+
permissions: write-all
7+
8+
jobs:
9+
push_new_series:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: checkout
13+
uses: actions/checkout@v3
14+
with:
15+
# a PAT must be generated with workflow permission, else it's not
16+
# possible to push any change for those files
17+
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/triggering-a-workflow#triggering-a-workflow-from-a-workflow
18+
token: ${{ secrets.WORKFLOW_COMMIT_TOKEN }}
19+
- run: git fetch -a origin --unshallow || true
20+
- run: git config user.name "GitHub Actions Bot"
21+
- run: git config user.email "<>"
22+
- run: sudo pip install b4
23+
- run: ./push_new_series.sh
24+
25+
keepalive-job:
26+
name: Keepalive Workflow
27+
if: ${{ always() }}
28+
needs: app
29+
runs-on: ubuntu-latest
30+
permissions:
31+
contents: write
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: gautamkrishnar/keepalive-workflow@v2
35+
with:
36+
use_api: false

Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ARG arch=
2+
FROM docker.io/${arch}/debian:bookworm
3+
4+
RUN apt update && apt upgrade -y
5+
# https://wiki.qemu.org/Hosts/Linux#Building_QEMU_for_Linux
6+
RUN apt update && apt install -y \
7+
git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev ninja-build\
8+
git-email\
9+
libaio-dev libbluetooth-dev libcapstone-dev libbrlapi-dev libbz2-dev\
10+
libcap-ng-dev libcurl4-gnutls-dev libgtk-3-dev\
11+
libibverbs-dev libjpeg-dev libncurses5-dev libnuma-dev\
12+
librbd-dev librdmacm-dev\
13+
libsasl2-dev libsdl2-dev libseccomp-dev libsnappy-dev libssh-dev\
14+
libvde-dev libvdeplug-dev libvte-2.91-dev liblzo2-dev\
15+
valgrind xfslibs-dev
16+
17+
RUN apt update && apt install -y \
18+
python3-venv meson coreutils build-essential git ccache python3-tomli
19+
20+
RUN apt update && apt install -y xvfb
21+
22+
RUN apt update && apt install -y flex bison
23+
24+
RUN apt update && apt install -y libunwind-dev
25+
26+
ARG arch=
27+
ENV ARCH=${arch}

build.sh

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
x64="x86_64-linux-user,x86_64-softmmu"
6+
i386="i386-linux-user,i386-softmmu"
7+
aarch64="aarch64-linux-user,aarch64-softmmu"
8+
9+
type=
10+
if [ $# -eq 1 ]; then
11+
type=$1
12+
fi
13+
14+
mkdir -p build
15+
touch build/.build_type
16+
previous_type="$(cat build/.build_type)"
17+
18+
if [ "$type" == "" ]; then
19+
type=$previous_type
20+
fi
21+
if [ "$type" == "" ]; then
22+
type=debug
23+
fi
24+
25+
if [ "$previous_type" != "$type" ]; then
26+
echo "build type is different ($previous_type -> $type)"
27+
rm -rf build || true
28+
mkdir -p build
29+
echo "$type" > build/.build_type
30+
fi
31+
32+
echo "build: $type"
33+
34+
if [ $type == tsan ]; then
35+
echo "Build with TSAN: use export LD_LIBRARY_PATH=$(pwd)/build/glib_tsan"
36+
fi
37+
38+
pushd build
39+
if [ ! -f .configured ]; then
40+
export CC="ccache cc"
41+
export CXX="ccache cxx"
42+
configure_flags=
43+
target="--target-list=$x64,$i386,$aarch64"
44+
case $type in
45+
opt)
46+
configure_flags=""
47+
export CFLAGS="-O2 -g -fno-omit-frame-pointer"
48+
;;
49+
opt-gcov)
50+
configure_flags=""
51+
export CFLAGS="-O2 -g -fno-omit-frame-pointer --coverage"
52+
export LDFLAGS="--coverage"
53+
;;
54+
debug)
55+
configure_flags="--enable-debug -Dasan=true -Dubsan=true"
56+
;;
57+
tsan)
58+
if [ ! -d glib_tsan ]; then
59+
rm -rf glib
60+
git clone --depth=1 --branch=2.81.0 https://github.com/GNOME/glib.git
61+
pushd glib
62+
CFLAGS="-O2 -g -fsanitize=thread" meson setup \
63+
--prefix=$(pwd)/out \
64+
build -Dtests=false
65+
ninja -C build install
66+
popd
67+
mkdir -p glib_tsan
68+
rsync -av glib/out/lib/*/* glib_tsan/
69+
rm -rf glib/
70+
fi
71+
configure_flags="--enable-debug -Dtsan=true"
72+
;;
73+
all)
74+
target=
75+
;;
76+
all-clang)
77+
target=
78+
export CC="ccache clang"
79+
export CXX="ccache clang++"
80+
;;
81+
*)
82+
echo "Unknown build type $type (choices: opt, debug, tsan, all, all-clang)"
83+
exit 1
84+
;;
85+
esac
86+
../configure $target $configure_flags
87+
touch .configured
88+
fi
89+
ninja
90+
make -B -C contrib/plugins/ > /dev/null
91+
popd

push_new_series.sh

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
die()
6+
{
7+
echo 1>&2 "$@"
8+
exit 1
9+
}
10+
11+
# return URL for mailboxes for previous, current and next month. This way, we
12+
# don't miss any email, even with different timezones.
13+
mailbox_archives()
14+
{
15+
current_date=$1
16+
17+
current_month=$(date +%m --date "$current_date")
18+
current_year=$(date +%Y --date "$current_date")
19+
20+
if [ $current_month == "01" ]; then
21+
previous_month=12
22+
previous_year=$((current_year - 1))
23+
elif [ $current_month == "12" ]; then
24+
next_month=01
25+
next_year=$((current_year + 1))
26+
else
27+
previous_year=$current_year
28+
next_year=$current_year
29+
previous_month=$(printf "%02d" $((current_month - 1)))
30+
next_month=$(printf "%02d" $((current_month + 1)))
31+
fi
32+
33+
qemu_archive="https://lists.gnu.org/archive/mbox/qemu-devel/"
34+
echo $qemu_archive$previous_year-$previous_month \
35+
$qemu_archive$current_year-$current_month \
36+
$qemu_archive$next_year-$next_month
37+
}
38+
39+
# download all emails for previous, current and next month.
40+
fetch_mails()
41+
{
42+
out=$1
43+
rm -rf $out
44+
mkdir -p $out
45+
mkdir -p $out.mailbox
46+
pushd $out.mailbox
47+
archives=$(mailbox_archives "$(date)")
48+
# we can have missing current or next mailbox depending on timezone
49+
wget --no-verbose --no-clobber $archives || true
50+
popd
51+
git mailsplit -o$out $out.mailbox/*
52+
}
53+
54+
find_series()
55+
{
56+
mail_dir=$1
57+
# find all message id, for mails without a reference (i.e. first in series).
58+
grep -Lri '^References:' $mail_dir | while read m
59+
do
60+
msg_id=$(grep -i '^message-id: ' $m | head -n1 | sed -e 's/.*<//' -e 's/>$//')
61+
date=$(grep -i '^date: ' $m | head -n1 | sed -e 's/^date: //I')
62+
echo "$msg_id|$date"
63+
done
64+
}
65+
66+
pull_repositories()
67+
{
68+
git remote remove upstream || true
69+
git remote add upstream -f https://gitlab.com/qemu-project/qemu
70+
git fetch -a origin
71+
}
72+
73+
push_one_series()
74+
{
75+
s="$1"
76+
echo "-----------------------------------------------------------------"
77+
msg_id=$(echo "$s" | cut -f 1 -d '|')
78+
date=$(echo "$s" | cut -f 2 -d '|')
79+
echo "$msg_id | $date"
80+
if git rev-parse "remotes/origin/$msg_id" >& /dev/null; then
81+
return
82+
fi
83+
84+
# find git commit on master close to date of series
85+
base_git_revision=$(git log -n1 --format=format:%H --before="$date" --first-parent upstream/master)
86+
echo "push this new series, applied from $base_git_revision"
87+
git checkout "$base_git_revision" >& /dev/null
88+
git branch -D new_series >& /dev/null || true
89+
git checkout -b new_series
90+
91+
# apply CI patch
92+
git cherry-pick origin/ci
93+
94+
# apply series
95+
if ! b4 shazam --allow-unicode-control-chars $msg_id |& tee shazam.log; then
96+
git am --abort
97+
git add shazam.log
98+
git commit -m 'b4 shazam failed'
99+
fi
100+
101+
# push result
102+
git push --set-upstream origin new_series:$msg_id
103+
104+
# reset branch
105+
git checkout origin/ci
106+
git branch -D new_series
107+
}
108+
109+
pull_repositories
110+
fetch_mails mails
111+
find_series mails | while read s; do push_one_series "$s"; done

run.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
die()
6+
{
7+
echo "$@" >&2
8+
exit 1
9+
}
10+
11+
[ $# -ge 2 ] || die "usage: arch command [args...]
12+
arch: (amd64|arm64v8|i386|s390x)"
13+
arch=$1;shift
14+
15+
script_dir=$(dirname $(readlink -f $0))
16+
pushd $script_dir
17+
18+
image=qemu-$arch
19+
podman build -t $image -f - --build-arg arch=$arch < Dockerfile
20+
mkdir -p build_$arch build
21+
mkdir -p $HOME/.cache/ccache
22+
podman run -it \
23+
-e CCACHE_DIR=$HOME/.cache/ccache \
24+
-v $HOME/.cache/ccache/:$HOME/.cache/ccache/ \
25+
-v $(pwd):$(pwd) -v $(pwd)/build_$arch:$(pwd)/build -w $(pwd)\
26+
-v /:/host \
27+
$image "$@"

0 commit comments

Comments
 (0)