Fam Zheng | 6b560c7 | 2017-09-05 10:11:52 +0800 | [diff] [blame] | 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 | |
| 12 | error() { |
| 13 | printf %s\\n "$*" >&2 |
| 14 | exit 1 |
| 15 | } |
| 16 | |
| 17 | if test $# -lt 1; then |
| 18 | error "Usage: $0 <output tarball>" |
| 19 | fi |
| 20 | |
Mao Zhongyi | 934821e | 2018-10-15 17:17:34 +0800 | [diff] [blame] | 21 | tar_file=$(realpath "$1") |
Gerd Hoffmann | 8fc7617 | 2019-05-20 14:47:03 +0200 | [diff] [blame] | 22 | sub_tdir=$(mktemp -d "${tar_file%.tar}.sub.XXXXXXXX") |
| 23 | sub_file="${sub_tdir}/submodule.tar" |
Fam Zheng | 6b560c7 | 2017-09-05 10:11:52 +0800 | [diff] [blame] | 24 | |
Daniel P. Berrange | 47bb908 | 2017-09-29 11:11:57 +0100 | [diff] [blame] | 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. |
Manos Pitsidianakis | 2b74dd9 | 2024-10-03 16:28:50 +0300 | [diff] [blame] | 29 | subprojects="keycodemapdb libvfio-user berkeley-softfloat-3 |
Paolo Bonzini | d0f0cd5 | 2024-10-10 16:11:28 +0200 | [diff] [blame^] | 30 | berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs |
| 31 | bilge-impl-0.2-rs either-1-rs itertools-0.11-rs proc-macro2-1-rs |
| 32 | proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs |
Manos Pitsidianakis | 2b74dd9 | 2024-10-03 16:28:50 +0300 | [diff] [blame] | 33 | syn-2-rs unicode-ident-1-rs" |
Gerd Hoffmann | 8fc7617 | 2019-05-20 14:47:03 +0200 | [diff] [blame] | 34 | sub_deinit="" |
Daniel P. Berrange | 47bb908 | 2017-09-29 11:11:57 +0100 | [diff] [blame] | 35 | |
Gerd Hoffmann | 8fc7617 | 2019-05-20 14:47:03 +0200 | [diff] [blame] | 36 | function cleanup() { |
| 37 | local status=$? |
| 38 | rm -rf "$sub_tdir" |
| 39 | if test "$sub_deinit" != ""; then |
| 40 | git submodule deinit $sub_deinit |
| 41 | fi |
| 42 | exit $status |
| 43 | } |
| 44 | trap "cleanup" 0 1 2 3 15 |
Daniel P. Berrange | 47bb908 | 2017-09-29 11:11:57 +0100 | [diff] [blame] | 45 | |
Marc-André Lureau | 84963b5 | 2019-07-09 00:02:49 +0400 | [diff] [blame] | 46 | function tree_ish() { |
| 47 | local retval='HEAD' |
| 48 | if ! git diff-index --quiet --ignore-submodules=all HEAD -- &>/dev/null |
| 49 | then |
| 50 | retval=$(git stash create) |
| 51 | fi |
| 52 | echo "$retval" |
| 53 | } |
Gerd Hoffmann | 8fc7617 | 2019-05-20 14:47:03 +0200 | [diff] [blame] | 54 | |
Paolo Bonzini | 474dcfc | 2024-10-10 16:26:35 +0200 | [diff] [blame] | 55 | function subproject_dir() { |
| 56 | if test ! -f "subprojects/$1.wrap"; then |
| 57 | error "scripts/archive-source.sh should only process wrap subprojects" |
| 58 | fi |
| 59 | |
| 60 | # Print the directory key of the wrap file, defaulting to the |
| 61 | # subproject name. The wrap file is in ini format and should |
| 62 | # have a single section only. There should be only one section |
| 63 | # named "[wrap-*]", which helps keeping the script simple. |
| 64 | local dir |
| 65 | dir=$(sed -n \ |
| 66 | -e '/^\[wrap-[a-z][a-z]*\]$/,/^\[/{' \ |
| 67 | -e '/^directory *= */!b' \ |
| 68 | -e 's///p' \ |
| 69 | -e 'q' \ |
| 70 | -e '}' \ |
| 71 | "subprojects/$1.wrap") |
| 72 | |
| 73 | echo "${dir:-$1}" |
| 74 | } |
| 75 | |
Marc-André Lureau | 84963b5 | 2019-07-09 00:02:49 +0400 | [diff] [blame] | 76 | git archive --format tar "$(tree_ish)" > "$tar_file" |
Gerd Hoffmann | 8fc7617 | 2019-05-20 14:47:03 +0200 | [diff] [blame] | 77 | test $? -ne 0 && error "failed to archive qemu" |
Paolo Bonzini | 2019cab | 2023-05-18 16:50:00 +0200 | [diff] [blame] | 78 | |
| 79 | for sp in $subprojects; do |
| 80 | meson subprojects download $sp |
| 81 | test $? -ne 0 && error "failed to download subproject $sp" |
Paolo Bonzini | 474dcfc | 2024-10-10 16:26:35 +0200 | [diff] [blame] | 82 | tar --append --file "$tar_file" --exclude=.git subprojects/"$(subproject_dir $sp)" |
Paolo Bonzini | 2019cab | 2023-05-18 16:50:00 +0200 | [diff] [blame] | 83 | test $? -ne 0 && error "failed to append subproject $sp to $tar_file" |
| 84 | done |
Fam Zheng | 6b560c7 | 2017-09-05 10:11:52 +0800 | [diff] [blame] | 85 | exit 0 |