gen-tarball 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env bash
  2. # Call gclient and generate a flutter-engine source tarball if one does not
  3. # already exist.
  4. set -eu
  5. DL_DIR=
  6. DOT_GCLIENT=
  7. JOBS=
  8. SCRATCH_DIR=
  9. TARBALL_DL_PATH=
  10. VERSION=
  11. TARBALL_NAME=
  12. term_bold="$(tput smso 2>/dev/null || true)"
  13. term_reset="$(tput rmso 2>/dev/null || true)"
  14. # Print status messages in the same style Buildroot prints.
  15. message() {
  16. printf "%s>>> flutter-engine %s %s%s\n" "${term_bold}" "${VERSION}" "${1}" "${term_reset}"
  17. }
  18. parse_opts() {
  19. local o O opts
  20. o='d:j:s:t:v:'
  21. O='dot-gclient:,jobs:,scratch-dir:,tarball-dl-path:,version:'
  22. opts="$(getopt -o "${o}" -l "${O}" -- "${@}")"
  23. eval set -- "${opts}"
  24. while [ ${#} -gt 0 ]; do
  25. case "${1}" in
  26. (-d|--dot-gclient) DOT_GCLIENT="${2}"; shift 2;;
  27. (-j|--jobs) JOBS="${2}"; shift 2;;
  28. (-s|--scratch-dir) SCRATCH_DIR="${2}"; shift 2;;
  29. (-t|--tarball-dl-path) DL_DIR=$(dirname "${2}"); TARBALL_DL_PATH="${2}"; shift 2;;
  30. (-v|--version) VERSION="${2}"; TARBALL_NAME=flutter-"${VERSION}".tar.gz; shift 2;;
  31. (--) shift; break;;
  32. esac
  33. done
  34. }
  35. prepare() {
  36. rm -rf "${SCRATCH_DIR}"
  37. mkdir -p "${SCRATCH_DIR}"
  38. pushd "${SCRATCH_DIR}" >/dev/null
  39. }
  40. copy_dot_gclient() {
  41. sed "s%!FLUTTER_VERSION!%${VERSION}%g" "${DOT_GCLIENT}" >.gclient
  42. }
  43. run_gclient() {
  44. message "Downloading"
  45. gclient.py \
  46. sync \
  47. --delete_unversioned_trees \
  48. --no-history \
  49. --reset \
  50. --shallow \
  51. -j"${JOBS}"
  52. }
  53. gen_tarball() {
  54. message "Generating tarball"
  55. mkdir -p "${DL_DIR}"
  56. # There are two issues with the flutter-engine buildsystem:
  57. # - it expects empty directories created by gclient.py to be present; that
  58. # means we can't use the mk_tar_gz helper method from support/download/helpers,
  59. # because it does not include empty directories;
  60. # - it insists on having a full git repositoy, with .git et al., which means
  61. # we can't generate a reproducible archive anyway.
  62. # So we just create a plain tarball.
  63. ${TAR} -C "${SCRATCH_DIR}"/src -czf "${TARBALL_NAME}" .
  64. mv "${TARBALL_NAME}" "${TARBALL_DL_PATH}"
  65. }
  66. cleanup() {
  67. popd >/dev/null
  68. rm -rf "${SCRATCH_DIR}"
  69. }
  70. main() {
  71. parse_opts "${@}"
  72. if [[ ! -e "${TARBALL_DL_PATH}" ]]; then
  73. prepare
  74. copy_dot_gclient
  75. run_gclient
  76. gen_tarball
  77. cleanup
  78. fi
  79. }
  80. main "${@}"