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