Advertisement
Guest User

fetcher

a guest
Aug 25th, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. """
  4. Bitbake 'Fetch' implementation for gclient/depot_tools repos
  5.  
  6. This is specifically an implementation for downloading an endpoint project that
  7. has its own DEPS and is synced with unmanaged; it will probably need modification
  8. before it can be used with for instance chromium.
  9. """
  10. import hashlib
  11. import json
  12. import os
  13. import shutil
  14. import subprocess
  15. import bb
  16. import sys
  17. from bb.fetch2 import logger, subprocess_setup, UnpackError, FetchMethod, runfetchcmd
  18.  
  19. class GClient(FetchMethod):
  20.  
  21. """Class to sync and configure via gclient"""
  22.  
  23. def supports(self, ud, d):
  24. """
  25. Check to see if a given url is for this fetcher
  26. """
  27. return ud.type in ['gclient']
  28.  
  29. def try_mirrors(self, ud, d, mirrors, check=False):
  30. return False
  31.  
  32. def try_premirror(self, ud, d):
  33. return False
  34.  
  35. def urldata_init(self, ud, d):
  36. dl_dir = d.getVar('DL_DIR')
  37. gclientdir = d.getVar('GCLIENTDIR') or (d.getVar('bindir') + '/gclient')
  38. ud.basecmd = d.getVar("FETCHCMD_gclient") or 'PATH=%s:$PATH gclient' % gclientdir
  39. workdir = os.path.join(gclientdir, ud.host.replace('/', '.'), ud.path.replace('/', '.'))
  40. ud.syncdir = os.path.join(workdir, 'sync')
  41. ud.localfile = os.path.join(
  42. workdir, '%s-%s.tar.gz' % (ud.path.replace('/', '.'), ud.parm.get('revision', 'git')))
  43. logger.warning("URLDATA INIT: got base %s sync %s local %s" % (ud.basecmd, ud.syncdir, ud.localfile))
  44.  
  45. def download(self, ud, d):
  46. logger.warning("DOWNLOADING")
  47. if not os.path.exists(ud.syncdir):
  48. bb.utils.mkdirhier(ud.syncdir)
  49. if 'revision' in ud.parm:
  50. clonebranch = '-b %s' % ud.parm['revision']
  51. else:
  52. clonebranch = ''
  53. logger.warning("ABOUT TO RUN CLONE")
  54. runfetchcmd(
  55. 'git clone %s %s %s --depth=1' % ('http://' + ud.host + ud.path, clonebranch, ud.parm.get('initialsubdir', '.')),
  56. d, workdir=ud.syncdir, log=sys.stderr)
  57. logger.warning("ABOUT TO RUN SYNC")
  58. runfetchcmd(
  59. '%s sync --with_branch_heads --with_tags' % (ud.basecmd), d, workdir=ud.syncdir, log=sys.stderr)
  60. runfetchcmd("tar -czf %s %s" % (ud.localfile, os.path.join(ud.syncdir, '*')), d, log=sys.stderr)
  61. shutil.rmtree(ud.syncdir)
  62. logger.warning("DONE DOWNLOADING PERHAPS?")
  63.  
  64. def unpack(self, ud, destdir, d):
  65. logger.warning("UNPACKING")
  66. destdir = ud.destdir = os.path.join(destdir, ud.parm.get('destsuffix', 'gclient/'))
  67. if os.path.exists(destdir):
  68. bb.utils.prunedir(destdir)
  69. bb.utils.mkdirhier(destdir)
  70. runfetchcmd('tar xzf %s' % (ud.localfile), workdir=destdir)
  71. logger.warning('UNPACKED')
  72.  
  73. def clean(self, ud, d):
  74. logger.warning('CLEANING')
  75. if os.path.exists(ud.syncdir) and os.path.isdir(ud.syncdir):
  76. shutil.rmtree(ud.syncdir)
  77. if os.path.exists(ud.localfile):
  78. os.unlink(ud.localfile)
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement