Guest User

Untitled

a guest
May 25th, 2025
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. repopulate_cache() {
  2. # populate the cache with what is needed for do_compile
  3. ${GO} clean -modcache
  4. go_do_compile
  5. }
  6.  
  7. update_modules_srcuri() {
  8. dldir="${GOMODCACHE}/cache/download/"
  9. find $dldir -name "*.zip" | sort > ${B}/.go-modules
  10. modsfile="${THISDIR}/${BPN}-go-mods.inc"
  11.  
  12. echo "# Autogenerated with 'bitbake -c update_modules ${PN}'\n" > $modsfile
  13. echo 'SRC_URI += "\' >> $modsfile
  14. while read -r zip; do
  15. sha256="$(sha256sum $zip | awk '{ print $1; }')"
  16. zip=$(realpath --relative-to=$dldir $zip)
  17. url=$(echo $zip | awk -F '/@v/' '{print $1}')
  18. url=$(echo $url | sed -e 's/\![a-z]/\U&/g' -e 's/!//g')
  19. version=$(echo $zip | awk -F '/@v/' '{print $2}')
  20. version="${version%.zip}"
  21. echo " gomod://$url;version=$version;sha256sum=$sha256 \\" >> $modsfile
  22. done < ${B}/.go-modules
  23. echo '"' >> $modsfile
  24. }
  25.  
  26. update_license_files() {
  27. licdir="${GOMODCACHE}"
  28. find $licdir -name LICENSE | sort > ${B}/.go-mod-licenses
  29.  
  30. licgen="${THISDIR}/${BPN}-licenses.inc"
  31. echo "# Autogenerated with 'bitbake -c update_modules ${PN}'\n" > $licgen
  32. echo 'LIC_FILES_CHKSUM += " \' >> $licgen
  33. while read -r licfile; do
  34. echo $licfile
  35. relpath="$(realpath --relative-to=$licdir $licfile)"
  36. md5=$(md5sum $licfile | awk '{ print $1; }')
  37.  
  38. # these are two lines to prevent bitbake expanding the variable, the must be a better way
  39. echo -n " file://$" >> $licgen
  40. echo "{GOMODCACHE}/$relpath;md5=$md5 \\" >> $licgen
  41.  
  42. license="$(sed -En "s/^$md5,([^,]+),?/\\1/p" ${THISDIR}/${BPN}-license-md5.csv)"
  43. if [ "$license" = "" ]; then
  44. bbwarn "Unknown license: $licfile"
  45. fi
  46.  
  47. if echo "$license" | grep ' '; then
  48. license="($license)"
  49. fi
  50.  
  51. if [ "$usedlic" = "" ]; then
  52. usedlic="$license"
  53. else
  54. usedlic="$usedlic\n$license"
  55. fi
  56.  
  57. done < ${B}/.go-mod-licenses
  58. echo '"' >> $licgen
  59.  
  60. usedlic="$(echo $usedlic | sort -u | awk '{printf " & %s", $0}')"
  61. echo >> $licgen
  62. echo "LICENSE += \"$usedlic\"" >> $licgen
  63. }
  64.  
  65. RECIPE_UPGRADE_EXTRA_TASKS += "do_update_modules"
  66.  
  67. addtask do_update_modules after do_configure
  68. do_update_modules[nostamp] = "1"
  69. do_update_modules[network] = "1"
  70. do_update_modules[dirs] = "${GOTMPDIR} ${B}/src/${GO_WORKDIR}"
  71.  
  72. do_update_modules() {
  73. repopulate_cache
  74. update_modules_srcuri
  75. update_license_files
  76. }
Advertisement
Add Comment
Please, Sign In to add comment