3 # Author: Fam Zheng <famz@redhat.com>
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.
9 # This code is licensed under the GPL version 2 or later. See
10 # the COPYING file in the top-level directory.
17 if test $# -lt 1; then
18 error
"Usage: $0 <output tarball>"
21 tar_file
=$
(realpath
"$1")
22 sub_tdir
=$
(mktemp
-d "${tar_file%.tar}.sub.XXXXXXXX")
23 sub_file
="${sub_tdir}/submodule.tar"
25 # 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.
29 submodules
="dtc slirp meson ui/keycodemapdb"
30 submodules
="$submodules tests/fp/berkeley-softfloat-3 tests/fp/berkeley-testfloat-3"
36 if test "$sub_deinit" != ""; then
37 git submodule deinit
$sub_deinit
41 trap "cleanup" 0 1 2 3 15
45 if ! git diff-index
--quiet --ignore-submodules=all HEAD
-- &>/dev
/null
47 retval
=$
(git stash create
)
52 git archive
--format tar "$(tree_ish)" > "$tar_file"
53 test $?
-ne 0 && error
"failed to archive qemu"
54 for sm
in $submodules; do
55 status
="$(git submodule status "$sm")"
56 smhash
="${status#[ +-]}"
57 smhash
="${smhash%% *}"
60 sub_deinit
="$sub_deinit $sm"
61 git submodule update
--init "$sm"
62 test $?
-ne 0 && error
"failed to update submodule $sm"
65 echo "WARNING: submodule $sm is out of sync"
68 (cd $sm; git archive
--format tar --prefix "$sm/" $
(tree_ish
)) > "$sub_file"
69 test $?
-ne 0 && error
"failed to archive submodule $sm ($smhash)"
70 tar --concatenate --file "$tar_file" "$sub_file"
71 test $?
-ne 0 && error
"failed append submodule $sm to $tar_file"