archive-source.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 tests/fp/berkeley-softfloat-3 tests/fp/berkeley-testfloat-3"
  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. for sm in $submodules; do
  36. if test -d "$sm/.git"
  37. then
  38. git clone --shared "$sm" "$vroot_dir/$sm"
  39. test $? -ne 0 && error "failed to clone submodule $sm"
  40. fi
  41. done
  42. cd "$vroot_dir"
  43. test $? -ne 0 && error "failed to change into '$vroot_dir'"
  44. git checkout $HEAD
  45. test $? -ne 0 && error "failed to checkout $HEAD revision"
  46. for sm in $submodules; do
  47. git submodule update --init $sm
  48. test $? -ne 0 && error "failed to init submodule $sm"
  49. done
  50. if test -n "$submodules"; then
  51. {
  52. git ls-files || error "git ls-files failed"
  53. for sm in $submodules; do
  54. (cd $sm; git ls-files) | sed "s:^:$sm/:"
  55. if test "${PIPESTATUS[*]}" != "0 0"; then
  56. error "git ls-files in submodule $sm failed"
  57. fi
  58. done
  59. } | grep -x -v $(for sm in $submodules; do echo "-e $sm"; done) > "$list_file"
  60. else
  61. git ls-files > "$list_file"
  62. fi
  63. if test $? -ne 0; then
  64. error "failed to generate list file"
  65. fi
  66. tar -cf "$tar_file" -T "$list_file" || error "failed to create tar file"
  67. exit 0