2
0

archive-source.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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="keycodemapdb libvfio-user berkeley-softfloat-3
  26. berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs
  27. bilge-impl-0.2-rs either-1-rs itertools-0.11-rs proc-macro2-1-rs
  28. proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs
  29. syn-2-rs unicode-ident-1-rs"
  30. sub_deinit=""
  31. function cleanup() {
  32. local status=$?
  33. rm -rf "$sub_tdir"
  34. if test "$sub_deinit" != ""; then
  35. git submodule deinit $sub_deinit
  36. fi
  37. exit $status
  38. }
  39. trap "cleanup" 0 1 2 3 15
  40. function tree_ish() {
  41. local retval='HEAD'
  42. if ! git diff-index --quiet --ignore-submodules=all HEAD -- &>/dev/null
  43. then
  44. retval=$(git stash create)
  45. fi
  46. echo "$retval"
  47. }
  48. function subproject_dir() {
  49. if test ! -f "subprojects/$1.wrap"; then
  50. error "scripts/archive-source.sh should only process wrap subprojects"
  51. fi
  52. # Print the directory key of the wrap file, defaulting to the
  53. # subproject name. The wrap file is in ini format and should
  54. # have a single section only. There should be only one section
  55. # named "[wrap-*]", which helps keeping the script simple.
  56. local dir
  57. dir=$(sed -n \
  58. -e '/^\[wrap-[a-z][a-z]*\]$/,/^\[/{' \
  59. -e '/^directory *= */!b' \
  60. -e 's///p' \
  61. -e 'q' \
  62. -e '}' \
  63. "subprojects/$1.wrap")
  64. echo "${dir:-$1}"
  65. }
  66. git archive --format tar "$(tree_ish)" > "$tar_file"
  67. test $? -ne 0 && error "failed to archive qemu"
  68. for sp in $subprojects; do
  69. meson subprojects download $sp
  70. test $? -ne 0 && error "failed to download subproject $sp"
  71. tar --append --file "$tar_file" --exclude=.git subprojects/"$(subproject_dir $sp)"
  72. test $? -ne 0 && error "failed to append subproject $sp to $tar_file"
  73. done
  74. exit 0