repo.py 2.9 KB

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