gen_gradle_deps_file.sh 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. # Copyright (c) 2020, The Tor Project, Inc.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are
  6. # met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. #
  11. # * Redistributions in binary form must reproduce the above
  12. # copyright notice, this list of conditions and the following disclaimer
  13. # in the documentation and/or other materials provided with the
  14. # distribution.
  15. #
  16. # * Neither the names of the copyright owners nor the names of its
  17. # contributors may be used to endorse or promote products derived from
  18. # this software without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. # Usage:
  32. # 1) Point to a log file with all the dependency download attempts (for its
  33. # generation see: doc/how-to-create-gradle-dependencies-list.txt)
  34. # 2) Double-check that you get the same SHA-256 sums when downloaded from a
  35. # different network location. E.g. by using `torsocks` with this script after
  36. # having made a copy of `gradle-dependencies-list.txt` from 1) and comparing
  37. # the two .txt files.
  38. export LC_ALL=C
  39. log="$1"
  40. # Step 1: Extract all the download attempts out of the log file, ignore the ones
  41. # for maven-metadata.xml and module files. We don't need those.
  42. cat $log | grep "Performing HTTP" | grep -o "https://.*" | \
  43. grep -vE "\.module|maven-metadata\.xml" | sort | uniq > dl-attempts
  44. # Step 2: Fetch all the dependencies and calculate the SHA-256 sum
  45. declare -A URLs
  46. function dl_url {
  47. local url="$1"
  48. test -n "${URLs[$url]}" && return 0
  49. URLs[$url]=1
  50. wget -U "" $url
  51. test $? -eq 0 || return 1
  52. local fn=$(basename "$url")
  53. local sha256=`sha256sum $fn | cut -d ' ' -f 1`
  54. echo "$sha256 | $url" >> deps
  55. rm $fn
  56. }
  57. while read line
  58. do
  59. dl_url "$line"
  60. # If we downloaded a .pom file, also try to get corresponding .jar and
  61. # .aar files
  62. bname=$(basename "$line" .pom)
  63. dname=$(dirname "$line")
  64. if test "$line" != "$dname/$bname"
  65. then
  66. dl_url "$dname/$bname.aar"
  67. dl_url "$dname/$bname.jar"
  68. fi
  69. done < dl-attempts
  70. # Step 3: Add the header at the beginning of the final dependency file.
  71. echo "# On how to update dependencies see doc/how-to-create-gradle\
  72. -dependencies-list.txt" > gradle-dependencies-list.txt
  73. echo "# Don't forget to update var/gradle_dependencies_version when modifying \
  74. this file" >> gradle-dependencies-list.txt
  75. echo "sha256sum | url" >> gradle-dependencies-list.txt
  76. # Step 4: Keep only successfully downloaded artifacts, remove duplicates, and
  77. # sort based on download URL.
  78. grep ^[a-f0-9] deps | rev | sort -t/ -u -k1,4 | rev | \
  79. sort -k 3 >> gradle-dependencies-list.txt
  80. # Step 5: Clean up
  81. rm dl-attempts
  82. rm deps
  83. exit 0