]> git.proxmox.com Git - mirror_qemu.git/blame - scripts/archive-source.sh
meson: use subproject for internal libfdt
[mirror_qemu.git] / scripts / archive-source.sh
CommitLineData
6b560c76
FZ
1#!/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
934821eb 21tar_file=$(realpath "$1")
8fc76176
GH
22sub_tdir=$(mktemp -d "${tar_file%.tar}.sub.XXXXXXXX")
23sub_file="${sub_tdir}/submodule.tar"
6b560c76 24
47bb908d
DB
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.
58e48b2e 29submodules="subprojects/dtc ui/keycodemapdb"
0a01d76f 30submodules="$submodules tests/fp/berkeley-softfloat-3 tests/fp/berkeley-testfloat-3"
8fc76176 31sub_deinit=""
47bb908d 32
8fc76176
GH
33function cleanup() {
34 local status=$?
35 rm -rf "$sub_tdir"
36 if test "$sub_deinit" != ""; then
37 git submodule deinit $sub_deinit
38 fi
39 exit $status
40}
41trap "cleanup" 0 1 2 3 15
47bb908d 42
84963b5b
MAL
43function tree_ish() {
44 local retval='HEAD'
45 if ! git diff-index --quiet --ignore-submodules=all HEAD -- &>/dev/null
46 then
47 retval=$(git stash create)
48 fi
49 echo "$retval"
50}
6b560c76 51
84963b5b 52git archive --format tar "$(tree_ish)" > "$tar_file"
8fc76176 53test $? -ne 0 && error "failed to archive qemu"
47bb908d 54for sm in $submodules; do
8fc76176
GH
55 status="$(git submodule status "$sm")"
56 smhash="${status#[ +-]}"
57 smhash="${smhash%% *}"
58 case "$status" in
59 -*)
60 sub_deinit="$sub_deinit $sm"
61 git submodule update --init "$sm"
62 test $? -ne 0 && error "failed to update submodule $sm"
63 ;;
64 +*)
65 echo "WARNING: submodule $sm is out of sync"
66 ;;
67 esac
84963b5b 68 (cd $sm; git archive --format tar --prefix "$sm/" $(tree_ish)) > "$sub_file"
8fc76176
GH
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"
47bb908d 72done
6b560c76 73exit 0