2
0

archive-source.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. error() {
  12. printf %s\\n "$*" >&2
  13. exit 1
  14. }
  15. if test $# -lt 1; then
  16. error "Usage: $0 <output tarball>"
  17. fi
  18. tar_file=$(realpath "$1")
  19. sub_tdir=$(mktemp -d "${tar_file%.tar}.sub.XXXXXXXX")
  20. sub_file="${sub_tdir}/submodule.tar"
  21. # We want a predictable list of submodules for builds, that is
  22. # independent of what the developer currently has initialized
  23. # in their checkout, because the build environment is completely
  24. # different to the host OS.
  25. subprojects="dtc keycodemapdb libvfio-user berkeley-softfloat-3 berkeley-testfloat-3"
  26. sub_deinit=""
  27. function cleanup() {
  28. local status=$?
  29. rm -rf "$sub_tdir"
  30. if test "$sub_deinit" != ""; then
  31. git submodule deinit $sub_deinit
  32. fi
  33. exit $status
  34. }
  35. trap "cleanup" 0 1 2 3 15
  36. function tree_ish() {
  37. local retval='HEAD'
  38. if ! git diff-index --quiet --ignore-submodules=all HEAD -- &>/dev/null
  39. then
  40. retval=$(git stash create)
  41. fi
  42. echo "$retval"
  43. }
  44. git archive --format tar "$(tree_ish)" > "$tar_file"
  45. test $? -ne 0 && error "failed to archive qemu"
  46. for sp in $subprojects; do
  47. meson subprojects download $sp
  48. test $? -ne 0 && error "failed to download subproject $sp"
  49. tar --append --file "$tar_file" --exclude=.git subprojects/$sp
  50. test $? -ne 0 && error "failed to append subproject $sp to $tar_file"
  51. done
  52. exit 0