blob: 65af8063e4bddc89ea4bdf05716ebc9ed108e7fb [file] [log] [blame]
Fam Zheng6b560c72017-09-05 10:11:52 +08001#!/bin/bash
2#
3# Author: Fam Zheng <famz@redhat.com>
4#
5# Archive source tree, including submodules. This is created for test code to
6# export the source files, in order to be built in a different environment,
7# such as in a docker instance or VM.
8#
9# This code is licensed under the GPL version 2 or later. See
10# the COPYING file in the top-level directory.
11
12error() {
13 printf %s\\n "$*" >&2
14 exit 1
15}
16
17if test $# -lt 1; then
18 error "Usage: $0 <output tarball>"
19fi
20
Mao Zhongyi934821e2018-10-15 17:17:34 +080021tar_file=$(realpath "$1")
Gerd Hoffmann8fc76172019-05-20 14:47:03 +020022sub_tdir=$(mktemp -d "${tar_file%.tar}.sub.XXXXXXXX")
23sub_file="${sub_tdir}/submodule.tar"
Fam Zheng6b560c72017-09-05 10:11:52 +080024
Daniel P. Berrange47bb9082017-09-29 11:11:57 +010025# We want a predictable list of submodules for builds, that is
26# independent of what the developer currently has initialized
27# in their checkout, because the build environment is completely
28# different to the host OS.
Paolo Bonzinif0df6132023-09-26 12:31:40 +020029subprojects="keycodemapdb libvfio-user berkeley-softfloat-3 berkeley-testfloat-3"
Gerd Hoffmann8fc76172019-05-20 14:47:03 +020030sub_deinit=""
Daniel P. Berrange47bb9082017-09-29 11:11:57 +010031
Gerd Hoffmann8fc76172019-05-20 14:47:03 +020032function cleanup() {
33 local status=$?
34 rm -rf "$sub_tdir"
35 if test "$sub_deinit" != ""; then
36 git submodule deinit $sub_deinit
37 fi
38 exit $status
39}
40trap "cleanup" 0 1 2 3 15
Daniel P. Berrange47bb9082017-09-29 11:11:57 +010041
Marc-André Lureau84963b52019-07-09 00:02:49 +040042function tree_ish() {
43 local retval='HEAD'
44 if ! git diff-index --quiet --ignore-submodules=all HEAD -- &>/dev/null
45 then
46 retval=$(git stash create)
47 fi
48 echo "$retval"
49}
Gerd Hoffmann8fc76172019-05-20 14:47:03 +020050
Marc-André Lureau84963b52019-07-09 00:02:49 +040051git archive --format tar "$(tree_ish)" > "$tar_file"
Gerd Hoffmann8fc76172019-05-20 14:47:03 +020052test $? -ne 0 && error "failed to archive qemu"
Paolo Bonzini2019cab2023-05-18 16:50:00 +020053
54for sp in $subprojects; do
55 meson subprojects download $sp
56 test $? -ne 0 && error "failed to download subproject $sp"
57 tar --append --file "$tar_file" --exclude=.git subprojects/$sp
58 test $? -ne 0 && error "failed to append subproject $sp to $tar_file"
59done
Fam Zheng6b560c72017-09-05 10:11:52 +080060exit 0