blob: 8c7e81853a6d1f8998ee9b402263025e4e12260e [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3"""
4BitBake "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
26import os
27import bb
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028from bb.fetch2 import FetchMethod
29from bb.fetch2 import runfetchcmd
Brad Bishopd7bf8c12018-02-25 22:55:05 -050030from bb.fetch2 import logger
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031
32class 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 Bishop1a4b7ee2018-12-16 17:11:34 -080048 ud.basecmd = d.getVar("FETCHCMD_repo") or "/usr/bin/env repo"
49
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050 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 Bishop6e60e8b2018-02-01 10:27:11 -050056 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 -050057
58 def download(self, ud, d):
59 """Fetch url"""
60
Brad Bishop6e60e8b2018-02-01 10:27:11 -050061 if os.access(os.path.join(d.getVar("DL_DIR"), ud.localfile), os.R_OK):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062 logger.debug(1, "%s already exists (or was stashed). Skipping repo init / sync.", ud.localpath)
63 return
64
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080065 repodir = d.getVar("REPODIR") or (d.getVar("DL_DIR") + "/repo")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066 gitsrcname = "%s%s" % (ud.host, ud.path.replace("/", "."))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 codir = os.path.join(repodir, gitsrcname, ud.manifest)
68
69 if ud.user:
70 username = ud.user + "@"
71 else:
72 username = ""
73
Patrick Williamsc0f7c042017-02-23 20:41:17 -060074 repodir = os.path.join(codir, "repo")
75 bb.utils.mkdirhier(repodir)
76 if not os.path.exists(os.path.join(repodir, ".repo")):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080077 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 Williamsc124f4f2015-09-15 14:41:29 -050079
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080080 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 Williamsc124f4f2015-09-15 14:41:29 -050082
83 scmdata = ud.parm.get("scmdata", "")
84 if scmdata == "keep":
85 tar_flags = ""
86 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060087 tar_flags = "--exclude='.repo' --exclude='.git'"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088
89 # Create a cache
Patrick Williamsc0f7c042017-02-23 20:41:17 -060090 runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.join(".", "*") ), d, workdir=codir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091
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