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