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. 292b74dd91SManos Pitsidianakissubprojects="keycodemapdb libvfio-user berkeley-softfloat-3 30*37fdb2f5SManos Pitsidianakis berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs 31*37fdb2f5SManos Pitsidianakis bilge-impl-0.2-rs either-1-rs itertools-0.11-rs proc-macro2-1-rs 32*37fdb2f5SManos Pitsidianakis proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs 332b74dd91SManos Pitsidianakis syn-2-rs unicode-ident-1-rs" 348fc76176SGerd Hoffmannsub_deinit="" 3547bb908dSDaniel P. Berrange 368fc76176SGerd Hoffmannfunction cleanup() { 378fc76176SGerd Hoffmann local status=$? 388fc76176SGerd Hoffmann rm -rf "$sub_tdir" 398fc76176SGerd Hoffmann if test "$sub_deinit" != ""; then 408fc76176SGerd Hoffmann git submodule deinit $sub_deinit 418fc76176SGerd Hoffmann fi 428fc76176SGerd Hoffmann exit $status 438fc76176SGerd Hoffmann} 448fc76176SGerd Hoffmanntrap "cleanup" 0 1 2 3 15 4547bb908dSDaniel P. Berrange 4684963b5bSMarc-André Lureaufunction tree_ish() { 4784963b5bSMarc-André Lureau local retval='HEAD' 4884963b5bSMarc-André Lureau if ! git diff-index --quiet --ignore-submodules=all HEAD -- &>/dev/null 4947bb908dSDaniel P. Berrange then 5084963b5bSMarc-André Lureau retval=$(git stash create) 516b560c76SFam Zheng fi 5284963b5bSMarc-André Lureau echo "$retval" 5384963b5bSMarc-André Lureau} 548fc76176SGerd Hoffmann 55474dcfc0SPaolo Bonzinifunction subproject_dir() { 56474dcfc0SPaolo Bonzini if test ! -f "subprojects/$1.wrap"; then 57474dcfc0SPaolo Bonzini error "scripts/archive-source.sh should only process wrap subprojects" 58474dcfc0SPaolo Bonzini fi 59474dcfc0SPaolo Bonzini 60474dcfc0SPaolo Bonzini # Print the directory key of the wrap file, defaulting to the 61474dcfc0SPaolo Bonzini # subproject name. The wrap file is in ini format and should 62474dcfc0SPaolo Bonzini # have a single section only. There should be only one section 63474dcfc0SPaolo Bonzini # named "[wrap-*]", which helps keeping the script simple. 64474dcfc0SPaolo Bonzini local dir 65474dcfc0SPaolo Bonzini dir=$(sed -n \ 66474dcfc0SPaolo Bonzini -e '/^\[wrap-[a-z][a-z]*\]$/,/^\[/{' \ 67474dcfc0SPaolo Bonzini -e '/^directory *= */!b' \ 68474dcfc0SPaolo Bonzini -e 's///p' \ 69474dcfc0SPaolo Bonzini -e 'q' \ 70474dcfc0SPaolo Bonzini -e '}' \ 71474dcfc0SPaolo Bonzini "subprojects/$1.wrap") 72474dcfc0SPaolo Bonzini 73474dcfc0SPaolo Bonzini echo "${dir:-$1}" 74474dcfc0SPaolo Bonzini} 75474dcfc0SPaolo Bonzini 7684963b5bSMarc-André Lureaugit archive --format tar "$(tree_ish)" > "$tar_file" 778fc76176SGerd Hoffmanntest $? -ne 0 && error "failed to archive qemu" 782019cabfSPaolo Bonzini 792019cabfSPaolo Bonzinifor sp in $subprojects; do 802019cabfSPaolo Bonzini meson subprojects download $sp 812019cabfSPaolo Bonzini test $? -ne 0 && error "failed to download subproject $sp" 82474dcfc0SPaolo Bonzini tar --append --file "$tar_file" --exclude=.git subprojects/"$(subproject_dir $sp)" 832019cabfSPaolo Bonzini test $? -ne 0 && error "failed to append subproject $sp to $tar_file" 842019cabfSPaolo Bonzinidone 856b560c76SFam Zhengexit 0 86