repo.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # ex:ts=4:sw=4:sts=4:et
  2. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  3. """
  4. BitBake "Fetch" repo (git) implementation
  5. """
  6. # Copyright (C) 2009 Tom Rini <trini@embeddedalley.com>
  7. #
  8. # Based on git.py which is:
  9. # Copyright (C) 2005 Richard Purdie
  10. #
  11. # SPDX-License-Identifier: GPL-2.0-only
  12. #
  13. import os
  14. import bb
  15. from bb.fetch2 import FetchMethod
  16. from bb.fetch2 import runfetchcmd
  17. from bb.fetch2 import logger
  18. class Repo(FetchMethod):
  19. """Class to fetch a module or modules from repo (git) repositories"""
  20. def supports(self, ud, d):
  21. """
  22. Check to see if a given url can be fetched with repo.
  23. """
  24. return ud.type in ["repo"]
  25. def urldata_init(self, ud, d):
  26. """
  27. We don"t care about the git rev of the manifests repository, but
  28. we do care about the manifest to use. The default is "default".
  29. We also care about the branch or tag to be used. The default is
  30. "master".
  31. """
  32. ud.basecmd = d.getVar("FETCHCMD_repo") or "/usr/bin/env repo"
  33. ud.proto = ud.parm.get('protocol', 'git')
  34. ud.branch = ud.parm.get('branch', 'master')
  35. ud.manifest = ud.parm.get('manifest', 'default.xml')
  36. if not ud.manifest.endswith('.xml'):
  37. ud.manifest += '.xml'
  38. ud.localfile = d.expand("repo_%s%s_%s_%s.tar.gz" % (ud.host, ud.path.replace("/", "."), ud.manifest, ud.branch))
  39. def download(self, ud, d):
  40. """Fetch url"""
  41. if os.access(os.path.join(d.getVar("DL_DIR"), ud.localfile), os.R_OK):
  42. logger.debug(1, "%s already exists (or was stashed). Skipping repo init / sync.", ud.localpath)
  43. return
  44. repodir = d.getVar("REPODIR") or (d.getVar("DL_DIR") + "/repo")
  45. gitsrcname = "%s%s" % (ud.host, ud.path.replace("/", "."))
  46. codir = os.path.join(repodir, gitsrcname, ud.manifest)
  47. if ud.user:
  48. username = ud.user + "@"
  49. else:
  50. username = ""
  51. repodir = os.path.join(codir, "repo")
  52. bb.utils.mkdirhier(repodir)
  53. if not os.path.exists(os.path.join(repodir, ".repo")):
  54. bb.fetch2.check_network_access(d, "%s init -m %s -b %s -u %s://%s%s%s" % (ud.basecmd, ud.manifest, ud.branch, ud.proto, username, ud.host, ud.path), ud.url)
  55. runfetchcmd("%s init -m %s -b %s -u %s://%s%s%s" % (ud.basecmd, ud.manifest, ud.branch, ud.proto, username, ud.host, ud.path), d, workdir=repodir)
  56. bb.fetch2.check_network_access(d, "%s sync %s" % (ud.basecmd, ud.url), ud.url)
  57. runfetchcmd("%s sync" % ud.basecmd, d, workdir=repodir)
  58. scmdata = ud.parm.get("scmdata", "")
  59. if scmdata == "keep":
  60. tar_flags = ""
  61. else:
  62. tar_flags = "--exclude='.repo' --exclude='.git'"
  63. # Create a cache
  64. runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.join(".", "*") ), d, workdir=codir)
  65. def supports_srcrev(self):
  66. return False
  67. def _build_revision(self, ud, d):
  68. return ud.manifest
  69. def _want_sortable_revision(self, ud, d):
  70. return False