blob: c22d9b5578eb9b0177b9bc28851ad04eefb59f4f [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
48 ud.proto = ud.parm.get('protocol', 'git')
49 ud.branch = ud.parm.get('branch', 'master')
50 ud.manifest = ud.parm.get('manifest', 'default.xml')
51 if not ud.manifest.endswith('.xml'):
52 ud.manifest += '.xml'
53
Brad Bishop6e60e8b2018-02-01 10:27:11 -050054 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 -050055
56 def download(self, ud, d):
57 """Fetch url"""
58
Brad Bishop6e60e8b2018-02-01 10:27:11 -050059 if os.access(os.path.join(d.getVar("DL_DIR"), ud.localfile), os.R_OK):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 logger.debug(1, "%s already exists (or was stashed). Skipping repo init / sync.", ud.localpath)
61 return
62
63 gitsrcname = "%s%s" % (ud.host, ud.path.replace("/", "."))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050064 repodir = d.getVar("REPODIR") or os.path.join(d.getVar("DL_DIR"), "repo")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065 codir = os.path.join(repodir, gitsrcname, ud.manifest)
66
67 if ud.user:
68 username = ud.user + "@"
69 else:
70 username = ""
71
Patrick Williamsc0f7c042017-02-23 20:41:17 -060072 repodir = os.path.join(codir, "repo")
73 bb.utils.mkdirhier(repodir)
74 if not os.path.exists(os.path.join(repodir, ".repo")):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075 bb.fetch2.check_network_access(d, "repo init -m %s -b %s -u %s://%s%s%s" % (ud.manifest, ud.branch, ud.proto, username, ud.host, ud.path), ud.url)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060076 runfetchcmd("repo init -m %s -b %s -u %s://%s%s%s" % (ud.manifest, ud.branch, ud.proto, username, ud.host, ud.path), d, workdir=repodir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077
78 bb.fetch2.check_network_access(d, "repo sync %s" % ud.url, ud.url)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060079 runfetchcmd("repo sync", d, workdir=repodir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080
81 scmdata = ud.parm.get("scmdata", "")
82 if scmdata == "keep":
83 tar_flags = ""
84 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060085 tar_flags = "--exclude='.repo' --exclude='.git'"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086
87 # Create a cache
Patrick Williamsc0f7c042017-02-23 20:41:17 -060088 runfetchcmd("tar %s -czf %s %s" % (tar_flags, ud.localpath, os.path.join(".", "*") ), d, workdir=codir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089
90 def supports_srcrev(self):
91 return False
92
93 def _build_revision(self, ud, d):
94 return ud.manifest
95
96 def _want_sortable_revision(self, ud, d):
97 return False