xref: /openbmc/qemu/scripts/archive-source.sh (revision 8b812533)
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
21tar_file="$1"
22list_file="$1.list"
23submodules=$(git submodule foreach --recursive --quiet 'echo $name')
24
25if test $? -ne 0; then
26    error "git submodule command failed"
27fi
28
29trap "status=$?; rm -f \"$list_file\"; exit \$status" 0 1 2 3 15
30
31if test -n "$submodules"; then
32    {
33        git ls-files || error "git ls-files failed"
34        for sm in $submodules; do
35            (cd $sm; git ls-files) | sed "s:^:$sm/:"
36            if test "${PIPESTATUS[*]}" != "0 0"; then
37                error "git ls-files in submodule $sm failed"
38            fi
39        done
40    } | grep -x -v $(for sm in $submodules; do echo "-e $sm"; done) > "$list_file"
41else
42    git ls-files > "$list_file"
43fi
44
45if test $? -ne 0; then
46    error "failed to generate list file"
47fi
48
49tar -cf "$tar_file" -T "$list_file" || error "failed to create tar file"
50
51exit 0
52