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=$(realpath "$1") 22sub_tdir=$(mktemp -d "${tar_file%.tar}.sub.XXXXXXXX") 23sub_file="${sub_tdir}/submodule.tar" 24 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. 29subprojects=( 30 anyhow-1-rs 31 arbitrary-int-1-rs 32 attrs-0.2-rs 33 berkeley-softfloat-3 34 berkeley-testfloat-3 35 bilge-0.2-rs 36 bilge-impl-0.2-rs 37 either-1-rs 38 foreign-0.3-rs 39 glib-sys-0.21-rs 40 itertools-0.11-rs 41 keycodemapdb 42 libc-0.2-rs 43 libvfio-user 44 proc-macro-error-1-rs 45 proc-macro-error-attr-1-rs 46 proc-macro2-1-rs 47 quote-1-rs 48 syn-2-rs 49 unicode-ident-1-rs 50) 51sub_deinit="" 52 53function cleanup() { 54 local status=$? 55 rm -rf "$sub_tdir" 56 if test "$sub_deinit" != ""; then 57 git submodule deinit $sub_deinit 58 fi 59 exit $status 60} 61trap "cleanup" 0 1 2 3 15 62 63function tree_ish() { 64 local retval='HEAD' 65 if ! git diff-index --quiet --ignore-submodules=all HEAD -- &>/dev/null 66 then 67 retval=$(git stash create) 68 fi 69 echo "$retval" 70} 71 72function subproject_dir() { 73 if test ! -f "subprojects/$1.wrap"; then 74 error "scripts/archive-source.sh should only process wrap subprojects" 75 fi 76 77 # Print the directory key of the wrap file, defaulting to the 78 # subproject name. The wrap file is in ini format and should 79 # have a single section only. There should be only one section 80 # named "[wrap-*]", which helps keeping the script simple. 81 local dir 82 dir=$(sed -n \ 83 -e '/^\[wrap-[a-z][a-z]*\]$/,/^\[/{' \ 84 -e '/^directory *= */!b' \ 85 -e 's///p' \ 86 -e 'q' \ 87 -e '}' \ 88 "subprojects/$1.wrap") 89 90 echo "${dir:-$1}" 91} 92 93git archive --format tar "$(tree_ish)" > "$tar_file" 94test $? -ne 0 && error "failed to archive qemu" 95 96meson subprojects download ${subprojects[@]} >/dev/null 97test $? -ne 0 && error "failed to download subprojects $subprojects" 98 99for sp in "${subprojects[@]}"; do 100 tar --append --file "$tar_file" --exclude=.git subprojects/"$(subproject_dir $sp)" 101 test $? -ne 0 && error "failed to append subproject $sp to $tar_file" 102done 103exit 0 104