gitsm.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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' git submodules implementation
  5. """
  6. # Copyright (C) 2013 Richard Purdie
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License version 2 as
  10. # published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. import os
  21. import bb
  22. from bb import data
  23. from bb.fetch2.git import Git
  24. from bb.fetch2 import runfetchcmd
  25. from bb.fetch2 import logger
  26. class GitSM(Git):
  27. def supports(self, ud, d):
  28. """
  29. Check to see if a given url can be fetched with git.
  30. """
  31. return ud.type in ['gitsm']
  32. def uses_submodules(self, ud, d):
  33. for name in ud.names:
  34. try:
  35. runfetchcmd("%s show %s:.gitmodules" % (ud.basecmd, ud.revisions[name]), d, quiet=True)
  36. return True
  37. except bb.fetch.FetchError:
  38. pass
  39. return False
  40. def update_submodules(self, ud, d):
  41. # We have to convert bare -> full repo, do the submodule bit, then convert back
  42. tmpclonedir = ud.clonedir + ".tmp"
  43. gitdir = tmpclonedir + os.sep + ".git"
  44. bb.utils.remove(tmpclonedir, True)
  45. os.mkdir(tmpclonedir)
  46. os.rename(ud.clonedir, gitdir)
  47. runfetchcmd("sed " + gitdir + "/config -i -e 's/bare.*=.*true/bare = false/'", d)
  48. os.chdir(tmpclonedir)
  49. runfetchcmd("git reset --hard", d)
  50. runfetchcmd("git submodule init", d)
  51. runfetchcmd("git submodule update", d)
  52. runfetchcmd("sed " + gitdir + "/config -i -e 's/bare.*=.*false/bare = true/'", d)
  53. os.rename(gitdir, ud.clonedir,)
  54. bb.utils.remove(tmpclonedir, True)
  55. def download(self, ud, d):
  56. Git.download(self, ud, d)
  57. os.chdir(ud.clonedir)
  58. submodules = self.uses_submodules(ud, d)
  59. if submodules:
  60. self.update_submodules(ud, d)
  61. def unpack(self, ud, destdir, d):
  62. Git.unpack(self, ud, destdir, d)
  63. os.chdir(ud.destdir)
  64. submodules = self.uses_submodules(ud, d)
  65. if submodules:
  66. runfetchcmd("cp -r " + ud.clonedir + "/modules " + ud.destdir + "/.git/", d)
  67. runfetchcmd("git submodule init", d)
  68. runfetchcmd("git submodule update", d)