blob: fa4cb8149b794c0cff0623b816a986f7318402ca [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001"""
2BitBake "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 Bishopc342db32019-05-15 21:57:59 -04009# Copyright (C) 2005 Richard Purdie
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010#
Brad Bishopc342db32019-05-15 21:57:59 -040011# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012#
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013
14import os
15import bb
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016from bb.fetch2 import FetchMethod
17from bb.fetch2 import runfetchcmd
Brad Bishopd7bf8c12018-02-25 22:55:05 -050018from bb.fetch2 import logger
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019
20class 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 Bishop1a4b7ee2018-12-16 17:11:34 -080036 ud.basecmd = d.getVar("FETCHCMD_repo") or "/usr/bin/env repo"
37
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038 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 Bishop6e60e8b2018-02-01 10:27:11 -050044 ud.localfile = d.expand("repo_%s%s_%s_%s.tar.gz" % (ud.host, ud.path.replace("/", "."), ud.manifest, ud.branch))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045
46 def download(self, ud, d):
47 """Fetch url"""
48
Brad Bishop6e60e8b2018-02-01 10:27:11 -050049 if os.access(os.path.join(d.getVar("DL_DIR"), ud.localfile), os.R_OK):
Andrew Geisslerd1e89492021-02-12 15:35:20 -060050 logger.debug("%s already exists (or was stashed). Skipping repo init / sync.", ud.localpath)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051 return
52
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080053 repodir = d.getVar("REPODIR") or (d.getVar("DL_DIR") + "/repo")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054 gitsrcname = "%s%s" % (ud.host, ud.path.replace("/", "."))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055 codir = os.path.join(repodir, gitsrcname, ud.manifest)
56
57 if ud.user:
58 username = ud.user + "@"
59 else:
60 username = ""
61
Patrick Williamsc0f7c042017-02-23 20:41:17 -060062 repodir = os.path.join(codir, "repo")
63 bb.utils.mkdirhier(repodir)
64 if not os.path.exists(os.path.join(repodir, ".repo")):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080065 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 Williamsc124f4f2015-09-15 14:41:29 -050067
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080068 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 Williamsc124f4f2015-09-15 14:41:29 -050070
71 scmdata = ud.parm.get("scmdata", "")
72 if scmdata == "keep":
73 tar_flags = ""
74 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060075 tar_flags = "--exclude='.repo' --exclude='.git'"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076
77 # Create a cache
Patrick Williamsc0f7c042017-02-23 20:41:17 -060078 runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.join(".", "*") ), d, workdir=codir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050079
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