Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | """ |
| 7 | |
| 8 | # Copyright (C) 2009 Tom Rini <trini@embeddedalley.com> |
| 9 | # |
| 10 | # Based on git.py which is: |
| 11 | #Copyright (C) 2005 Richard Purdie |
| 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 | |
| 26 | import os |
| 27 | import bb |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | from bb.fetch2 import FetchMethod |
| 29 | from bb.fetch2 import runfetchcmd |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 30 | from bb.fetch2 import logger |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | |
| 32 | class Repo(FetchMethod): |
| 33 | """Class to fetch a module or modules from repo (git) repositories""" |
| 34 | def supports(self, ud, d): |
| 35 | """ |
| 36 | Check to see if a given url can be fetched with repo. |
| 37 | """ |
| 38 | return ud.type in ["repo"] |
| 39 | |
| 40 | def urldata_init(self, ud, d): |
| 41 | """ |
| 42 | We don"t care about the git rev of the manifests repository, but |
| 43 | we do care about the manifest to use. The default is "default". |
| 44 | We also care about the branch or tag to be used. The default is |
| 45 | "master". |
| 46 | """ |
| 47 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 48 | ud.basecmd = d.getVar("FETCHCMD_repo") or "/usr/bin/env repo" |
| 49 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 50 | ud.proto = ud.parm.get('protocol', 'git') |
| 51 | ud.branch = ud.parm.get('branch', 'master') |
| 52 | ud.manifest = ud.parm.get('manifest', 'default.xml') |
| 53 | if not ud.manifest.endswith('.xml'): |
| 54 | ud.manifest += '.xml' |
| 55 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 56 | ud.localfile = d.expand("repo_%s%s_%s_%s.tar.gz" % (ud.host, ud.path.replace("/", "."), ud.manifest, ud.branch)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | |
| 58 | def download(self, ud, d): |
| 59 | """Fetch url""" |
| 60 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 61 | if os.access(os.path.join(d.getVar("DL_DIR"), ud.localfile), os.R_OK): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | logger.debug(1, "%s already exists (or was stashed). Skipping repo init / sync.", ud.localpath) |
| 63 | return |
| 64 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 65 | repodir = d.getVar("REPODIR") or (d.getVar("DL_DIR") + "/repo") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 66 | gitsrcname = "%s%s" % (ud.host, ud.path.replace("/", ".")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 67 | codir = os.path.join(repodir, gitsrcname, ud.manifest) |
| 68 | |
| 69 | if ud.user: |
| 70 | username = ud.user + "@" |
| 71 | else: |
| 72 | username = "" |
| 73 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 74 | repodir = os.path.join(codir, "repo") |
| 75 | bb.utils.mkdirhier(repodir) |
| 76 | if not os.path.exists(os.path.join(repodir, ".repo")): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 77 | 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) |
| 78 | 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) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 79 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 80 | bb.fetch2.check_network_access(d, "%s sync %s" % (ud.basecmd, ud.url), ud.url) |
| 81 | runfetchcmd("%s sync" % ud.basecmd, d, workdir=repodir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 82 | |
| 83 | scmdata = ud.parm.get("scmdata", "") |
| 84 | if scmdata == "keep": |
| 85 | tar_flags = "" |
| 86 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 87 | tar_flags = "--exclude='.repo' --exclude='.git'" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 88 | |
| 89 | # Create a cache |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 90 | runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.join(".", "*") ), d, workdir=codir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 91 | |
| 92 | def supports_srcrev(self): |
| 93 | return False |
| 94 | |
| 95 | def _build_revision(self, ud, d): |
| 96 | return ud.manifest |
| 97 | |
| 98 | def _want_sortable_revision(self, ud, d): |
| 99 | return False |