archive-source.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. list_file="${tar_file}.list"
  20. vroot_dir="${tar_file}.vroot"
  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. submodules="dtc ui/keycodemapdb"
  26. trap "status=$?; rm -rf \"$list_file\" \"$vroot_dir\"; exit \$status" 0 1 2 3 15
  27. if git diff-index --quiet HEAD -- &>/dev/null
  28. then
  29. HEAD=HEAD
  30. else
  31. HEAD=`git stash create`
  32. fi
  33. git clone --shared . "$vroot_dir"
  34. test $? -ne 0 && error "failed to clone into '$vroot_dir'"
  35. cd "$vroot_dir"
  36. test $? -ne 0 && error "failed to change into '$vroot_dir'"
  37. git checkout $HEAD
  38. test $? -ne 0 && error "failed to checkout $HEAD revision"
  39. for sm in $submodules; do
  40. git submodule update --init $sm
  41. test $? -ne 0 && error "failed to init submodule $sm"
  42. done
  43. if test -n "$submodules"; then
  44. {
  45. git ls-files || error "git ls-files failed"
  46. for sm in $submodules; do
  47. (cd $sm; git ls-files) | sed "s:^:$sm/:"
  48. if test "${PIPESTATUS[*]}" != "0 0"; then
  49. error "git ls-files in submodule $sm failed"
  50. fi
  51. done
  52. } | grep -x -v $(for sm in $submodules; do echo "-e $sm"; done) > "$list_file"
  53. else
  54. git ls-files > "$list_file"
  55. fi
  56. if test $? -ne 0; then
  57. error "failed to generate list file"
  58. fi
  59. tar -cf "$tar_file" -T "$list_file" || error "failed to create tar file"
  60. exit 0