repo.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License version 2 as
  15. # published by the Free Software Foundation.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. # You should have received a copy of the GNU General Public License along
  23. # with this program; if not, write to the Free Software Foundation, Inc.,
  24. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  25. import os
  26. import bb
  27. from bb.fetch2 import FetchMethod
  28. from bb.fetch2 import runfetchcmd
  29. from bb.fetch2 import logger
  30. class Repo(FetchMethod):
  31. """Class to fetch a module or modules from repo (git) repositories"""
  32. def supports(self, ud, d):
  33. """
  34. Check to see if a given url can be fetched with repo.
  35. """
  36. return ud.type in ["repo"]
  37. def urldata_init(self, ud, d):
  38. """
  39. We don"t care about the git rev of the manifests repository, but
  40. we do care about the manifest to use. The default is "default".
  41. We also care about the branch or tag to be used. The default is
  42. "master".
  43. """
  44. ud.basecmd = d.getVar("FETCHCMD_repo") or "/usr/bin/env repo"
  45. ud.proto = ud.parm.get('protocol', 'git')
  46. ud.branch = ud.parm.get('branch', 'master')
  47. ud.manifest = ud.parm.get('manifest', 'default.xml')
  48. if not ud.manifest.endswith('.xml'):
  49. ud.manifest += '.xml'
  50. ud.localfile = d.expand("repo_%s%s_%s_%s.tar.gz" % (ud.host, ud.path.replace("/", "."), ud.manifest, ud.branch))
  51. def download(self, ud, d):
  52. """Fetch url"""
  53. if os.access(os.path.join(d.getVar("DL_DIR"), ud.localfile), os.R_OK):
  54. logger.debug(1, "%s already exists (or was stashed). Skipping repo init / sync.", ud.localpath)
  55. return
  56. repodir = d.getVar("REPODIR") or (d.getVar("DL_DIR") + "/repo")
  57. gitsrcname = "%s%s" % (ud.host, ud.path.replace("/", "."))
  58. codir = os.path.join(repodir, gitsrcname, ud.manifest)
  59. if ud.user:
  60. username = ud.user + "@"
  61. else:
  62. username = ""
  63. repodir = os.path.join(codir, "repo")
  64. bb.utils.mkdirhier(repodir)
  65. if not os.path.exists(os.path.join(repodir, ".repo")):
  66. 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)
  67. 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)
  68. bb.fetch2.check_network_access(d, "%s sync %s" % (ud.basecmd, ud.url), ud.url)
  69. runfetchcmd("%s sync" % ud.basecmd, d, workdir=repodir)
  70. scmdata = ud.parm.get("scmdata", "")
  71. if scmdata == "keep":
  72. tar_flags = ""
  73. else:
  74. tar_flags = "--exclude='.repo' --exclude='.git'"
  75. # Create a cache
  76. runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.join(".", "*") ), d, workdir=codir)
  77. def supports_srcrev(self):
  78. return False
  79. def _build_revision(self, ud, d):
  80. return ud.manifest
  81. def _want_sortable_revision(self, ud, d):
  82. return False