Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- """
- Bitbake 'Fetch' implementation for gclient/depot_tools repos
- This is specifically an implementation for downloading an endpoint project that
- has its own DEPS and is synced with unmanaged; it will probably need modification
- before it can be used with for instance chromium.
- """
- import hashlib
- import json
- import os
- import shutil
- import subprocess
- import bb
- import sys
- from bb.fetch2 import logger, subprocess_setup, UnpackError, FetchMethod, runfetchcmd
- class GClient(FetchMethod):
- """Class to sync and configure via gclient"""
- def supports(self, ud, d):
- """
- Check to see if a given url is for this fetcher
- """
- return ud.type in ['gclient']
- def try_mirrors(self, ud, d, mirrors, check=False):
- return False
- def try_premirror(self, ud, d):
- return False
- def urldata_init(self, ud, d):
- dl_dir = d.getVar('DL_DIR')
- gclientdir = d.getVar('GCLIENTDIR') or (d.getVar('bindir') + '/gclient')
- ud.basecmd = d.getVar("FETCHCMD_gclient") or 'PATH=%s:$PATH gclient' % gclientdir
- workdir = os.path.join(gclientdir, ud.host.replace('/', '.'), ud.path.replace('/', '.'))
- ud.syncdir = os.path.join(workdir, 'sync')
- ud.localfile = os.path.join(
- workdir, '%s-%s.tar.gz' % (ud.path.replace('/', '.'), ud.parm.get('revision', 'git')))
- logger.warning("URLDATA INIT: got base %s sync %s local %s" % (ud.basecmd, ud.syncdir, ud.localfile))
- def download(self, ud, d):
- logger.warning("DOWNLOADING")
- if not os.path.exists(ud.syncdir):
- bb.utils.mkdirhier(ud.syncdir)
- if 'revision' in ud.parm:
- clonebranch = '-b %s' % ud.parm['revision']
- else:
- clonebranch = ''
- logger.warning("ABOUT TO RUN CLONE")
- runfetchcmd(
- 'git clone %s %s %s --depth=1' % ('http://' + ud.host + ud.path, clonebranch, ud.parm.get('initialsubdir', '.')),
- d, workdir=ud.syncdir, log=sys.stderr)
- logger.warning("ABOUT TO RUN SYNC")
- runfetchcmd(
- '%s sync --with_branch_heads --with_tags' % (ud.basecmd), d, workdir=ud.syncdir, log=sys.stderr)
- runfetchcmd("tar -czf %s %s" % (ud.localfile, os.path.join(ud.syncdir, '*')), d, log=sys.stderr)
- shutil.rmtree(ud.syncdir)
- logger.warning("DONE DOWNLOADING PERHAPS?")
- def unpack(self, ud, destdir, d):
- logger.warning("UNPACKING")
- destdir = ud.destdir = os.path.join(destdir, ud.parm.get('destsuffix', 'gclient/'))
- if os.path.exists(destdir):
- bb.utils.prunedir(destdir)
- bb.utils.mkdirhier(destdir)
- runfetchcmd('tar xzf %s' % (ud.localfile), workdir=destdir)
- logger.warning('UNPACKED')
- def clean(self, ud, d):
- logger.warning('CLEANING')
- if os.path.exists(ud.syncdir) and os.path.isdir(ud.syncdir):
- shutil.rmtree(ud.syncdir)
- if os.path.exists(ud.localfile):
- os.unlink(ud.localfile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement