repo.py 3.6 KB

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