xref: /qemu/scripts/archive-source.sh (revision f0df613b)
16b560c76SFam Zheng#!/bin/bash
26b560c76SFam Zheng#
36b560c76SFam Zheng# Author: Fam Zheng <famz@redhat.com>
46b560c76SFam Zheng#
56b560c76SFam Zheng# Archive source tree, including submodules. This is created for test code to
66b560c76SFam Zheng# export the source files, in order to be built in a different environment,
76b560c76SFam Zheng# such as in a docker instance or VM.
86b560c76SFam Zheng#
96b560c76SFam Zheng# This code is licensed under the GPL version 2 or later.  See
106b560c76SFam Zheng# the COPYING file in the top-level directory.
116b560c76SFam Zheng
126b560c76SFam Zhengerror() {
136b560c76SFam Zheng    printf %s\\n "$*" >&2
146b560c76SFam Zheng    exit 1
156b560c76SFam Zheng}
166b560c76SFam Zheng
176b560c76SFam Zhengif test $# -lt 1; then
186b560c76SFam Zheng    error "Usage: $0 <output tarball>"
196b560c76SFam Zhengfi
206b560c76SFam Zheng
21934821ebSMao Zhongyitar_file=$(realpath "$1")
228fc76176SGerd Hoffmannsub_tdir=$(mktemp -d "${tar_file%.tar}.sub.XXXXXXXX")
238fc76176SGerd Hoffmannsub_file="${sub_tdir}/submodule.tar"
246b560c76SFam Zheng
2547bb908dSDaniel P. Berrange# We want a predictable list of submodules for builds, that is
2647bb908dSDaniel P. Berrange# independent of what the developer currently has initialized
2747bb908dSDaniel P. Berrange# in their checkout, because the build environment is completely
2847bb908dSDaniel P. Berrange# different to the host OS.
29f0df613bSPaolo Bonzinisubprojects="keycodemapdb libvfio-user berkeley-softfloat-3 berkeley-testfloat-3"
308fc76176SGerd Hoffmannsub_deinit=""
3147bb908dSDaniel P. Berrange
328fc76176SGerd Hoffmannfunction cleanup() {
338fc76176SGerd Hoffmann    local status=$?
348fc76176SGerd Hoffmann    rm -rf "$sub_tdir"
358fc76176SGerd Hoffmann    if test "$sub_deinit" != ""; then
368fc76176SGerd Hoffmann        git submodule deinit $sub_deinit
378fc76176SGerd Hoffmann    fi
388fc76176SGerd Hoffmann    exit $status
398fc76176SGerd Hoffmann}
408fc76176SGerd Hoffmanntrap "cleanup" 0 1 2 3 15
4147bb908dSDaniel P. Berrange
4284963b5bSMarc-André Lureaufunction tree_ish() {
4384963b5bSMarc-André Lureau    local retval='HEAD'
4484963b5bSMarc-André Lureau    if ! git diff-index --quiet --ignore-submodules=all HEAD -- &>/dev/null
4547bb908dSDaniel P. Berrange    then
4684963b5bSMarc-André Lureau        retval=$(git stash create)
476b560c76SFam Zheng    fi
4884963b5bSMarc-André Lureau    echo "$retval"
4984963b5bSMarc-André Lureau}
508fc76176SGerd Hoffmann
5184963b5bSMarc-André Lureaugit archive --format tar "$(tree_ish)" > "$tar_file"
528fc76176SGerd Hoffmanntest $? -ne 0 && error "failed to archive qemu"
532019cabfSPaolo Bonzini
542019cabfSPaolo Bonzinifor sp in $subprojects; do
552019cabfSPaolo Bonzini    meson subprojects download $sp
562019cabfSPaolo Bonzini    test $? -ne 0 && error "failed to download subproject $sp"
572019cabfSPaolo Bonzini    tar --append --file "$tar_file" --exclude=.git subprojects/$sp
582019cabfSPaolo Bonzini    test $? -ne 0 && error "failed to append subproject $sp to $tar_file"
592019cabfSPaolo Bonzinidone
606b560c76SFam Zhengexit 0
61