Mike Frysinger | f601376 | 2019-06-13 02:30:51 -0400 | [diff] [blame] | 1 | # -*- coding:utf-8 -*- |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2008 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Sarah Owens | cecd1d8 | 2012-11-01 22:59:27 -0700 | [diff] [blame] | 17 | from __future__ import print_function |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 18 | import itertools |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 19 | import os |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 20 | import re |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 21 | import sys |
David Pursehouse | 59bbb58 | 2013-05-17 10:49:33 +0900 | [diff] [blame] | 22 | import xml.dom.minidom |
| 23 | |
| 24 | from pyversion import is_python3 |
| 25 | if is_python3(): |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 26 | import urllib.parse |
David Pursehouse | 59bbb58 | 2013-05-17 10:49:33 +0900 | [diff] [blame] | 27 | else: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 28 | import imp |
| 29 | import urlparse |
| 30 | urllib = imp.new_module('urllib') |
Chirayu Desai | db2ad9d | 2013-06-11 13:42:25 +0530 | [diff] [blame] | 31 | urllib.parse = urlparse |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 32 | |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 33 | import gitc_utils |
David Pursehouse | e15c65a | 2012-08-22 10:46:11 +0900 | [diff] [blame] | 34 | from git_config import GitConfig |
David Pursehouse | e00aa6b | 2012-09-11 14:33:51 +0900 | [diff] [blame] | 35 | from git_refs import R_HEADS, HEAD |
Renaud Paquay | d5cec5e | 2016-11-01 11:24:03 -0700 | [diff] [blame] | 36 | import platform_utils |
David Pursehouse | e00aa6b | 2012-09-11 14:33:51 +0900 | [diff] [blame] | 37 | from project import RemoteSpec, Project, MetaProject |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 38 | from error import (ManifestParseError, ManifestInvalidPathError, |
| 39 | ManifestInvalidRevisionError) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 40 | |
| 41 | MANIFEST_FILE_NAME = 'manifest.xml' |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 42 | LOCAL_MANIFEST_NAME = 'local_manifest.xml' |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 43 | LOCAL_MANIFESTS_DIR_NAME = 'local_manifests' |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 44 | |
Anthony King | cb07ba7 | 2015-03-28 23:26:04 +0000 | [diff] [blame] | 45 | # urljoin gets confused if the scheme is not known. |
Joe Kilner | 6e31079 | 2016-10-27 15:53:53 -0700 | [diff] [blame] | 46 | urllib.parse.uses_relative.extend([ |
| 47 | 'ssh', |
| 48 | 'git', |
| 49 | 'persistent-https', |
| 50 | 'sso', |
| 51 | 'rpc']) |
| 52 | urllib.parse.uses_netloc.extend([ |
| 53 | 'ssh', |
| 54 | 'git', |
| 55 | 'persistent-https', |
| 56 | 'sso', |
| 57 | 'rpc']) |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 58 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 59 | class _Default(object): |
| 60 | """Project defaults within the manifest.""" |
| 61 | |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 62 | revisionExpr = None |
Conley Owens | b6a16e6 | 2013-09-25 15:06:09 -0700 | [diff] [blame] | 63 | destBranchExpr = None |
Nasser Grainawi | da40341 | 2018-05-04 12:53:29 -0600 | [diff] [blame] | 64 | upstreamExpr = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 65 | remote = None |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 66 | sync_j = 1 |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 67 | sync_c = False |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 68 | sync_s = False |
YOUNG HO CHA | a32c92c | 2018-02-14 16:57:31 +0900 | [diff] [blame] | 69 | sync_tags = True |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 70 | |
Julien Campergue | 7487992 | 2013-10-09 14:38:46 +0200 | [diff] [blame] | 71 | def __eq__(self, other): |
| 72 | return self.__dict__ == other.__dict__ |
| 73 | |
| 74 | def __ne__(self, other): |
| 75 | return self.__dict__ != other.__dict__ |
| 76 | |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 77 | class _XmlRemote(object): |
| 78 | def __init__(self, |
| 79 | name, |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 80 | alias=None, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 81 | fetch=None, |
Steve Rae | d648045 | 2016-08-10 15:00:00 -0700 | [diff] [blame] | 82 | pushUrl=None, |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 83 | manifestUrl=None, |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 84 | review=None, |
Jonathan Nieder | 9371979 | 2015-03-17 11:29:58 -0700 | [diff] [blame] | 85 | revision=None): |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 86 | self.name = name |
| 87 | self.fetchUrl = fetch |
Steve Rae | d648045 | 2016-08-10 15:00:00 -0700 | [diff] [blame] | 88 | self.pushUrl = pushUrl |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 89 | self.manifestUrl = manifestUrl |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 90 | self.remoteAlias = alias |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 91 | self.reviewUrl = review |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 92 | self.revision = revision |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 93 | self.resolvedFetchUrl = self._resolveFetchUrl() |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 94 | |
David Pursehouse | 717ece9 | 2012-11-13 08:49:16 +0900 | [diff] [blame] | 95 | def __eq__(self, other): |
| 96 | return self.__dict__ == other.__dict__ |
| 97 | |
| 98 | def __ne__(self, other): |
| 99 | return self.__dict__ != other.__dict__ |
| 100 | |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 101 | def _resolveFetchUrl(self): |
| 102 | url = self.fetchUrl.rstrip('/') |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 103 | manifestUrl = self.manifestUrl.rstrip('/') |
Conley Owens | 2d0f508 | 2014-01-31 15:03:51 -0800 | [diff] [blame] | 104 | # urljoin will gets confused over quite a few things. The ones we care |
| 105 | # about here are: |
| 106 | # * no scheme in the base url, like <hostname:port> |
Anthony King | cb07ba7 | 2015-03-28 23:26:04 +0000 | [diff] [blame] | 107 | # We handle no scheme by replacing it with an obscure protocol, gopher |
| 108 | # and then replacing it with the original when we are done. |
| 109 | |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 110 | if manifestUrl.find(':') != manifestUrl.find('/') - 1: |
Conley Owens | 4ccad75 | 2015-04-29 10:45:37 -0700 | [diff] [blame] | 111 | url = urllib.parse.urljoin('gopher://' + manifestUrl, url) |
| 112 | url = re.sub(r'^gopher://', '', url) |
Anthony King | cb07ba7 | 2015-03-28 23:26:04 +0000 | [diff] [blame] | 113 | else: |
| 114 | url = urllib.parse.urljoin(manifestUrl, url) |
Shawn Pearce | a9f11b3 | 2013-01-02 15:40:48 -0800 | [diff] [blame] | 115 | return url |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 116 | |
| 117 | def ToRemoteSpec(self, projectName): |
David Riley | e0684ad | 2017-04-05 00:02:59 -0700 | [diff] [blame] | 118 | fetchUrl = self.resolvedFetchUrl.rstrip('/') |
| 119 | url = fetchUrl + '/' + projectName |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 120 | remoteName = self.name |
Conley Owens | 1e7ab2a | 2013-10-08 17:26:57 -0700 | [diff] [blame] | 121 | if self.remoteAlias: |
David Pursehouse | 37128b6 | 2013-10-15 10:48:40 +0900 | [diff] [blame] | 122 | remoteName = self.remoteAlias |
Dan Willemsen | 96c2d65 | 2016-04-06 16:03:54 -0700 | [diff] [blame] | 123 | return RemoteSpec(remoteName, |
| 124 | url=url, |
Steve Rae | d648045 | 2016-08-10 15:00:00 -0700 | [diff] [blame] | 125 | pushUrl=self.pushUrl, |
Dan Willemsen | 96c2d65 | 2016-04-06 16:03:54 -0700 | [diff] [blame] | 126 | review=self.reviewUrl, |
David Riley | e0684ad | 2017-04-05 00:02:59 -0700 | [diff] [blame] | 127 | orig_name=self.name, |
| 128 | fetchUrl=self.fetchUrl) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 129 | |
Shawn O. Pearce | c8a300f | 2009-05-18 13:19:57 -0700 | [diff] [blame] | 130 | class XmlManifest(object): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 131 | """manages the repo configuration file""" |
| 132 | |
| 133 | def __init__(self, repodir): |
| 134 | self.repodir = os.path.abspath(repodir) |
| 135 | self.topdir = os.path.dirname(self.repodir) |
| 136 | self.manifestFile = os.path.join(self.repodir, MANIFEST_FILE_NAME) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 137 | self.globalConfig = GitConfig.ForUser() |
David Pursehouse | 4eb285c | 2013-02-14 16:28:44 +0900 | [diff] [blame] | 138 | self.localManifestWarning = False |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 139 | self.isGitcClient = False |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 140 | self._load_local_manifests = True |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 141 | |
| 142 | self.repoProject = MetaProject(self, 'repo', |
| 143 | gitdir = os.path.join(repodir, 'repo/.git'), |
| 144 | worktree = os.path.join(repodir, 'repo')) |
| 145 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 146 | self.manifestProject = MetaProject(self, 'manifests', |
Shawn O. Pearce | f5c25a6 | 2008-11-04 08:11:53 -0800 | [diff] [blame] | 147 | gitdir = os.path.join(repodir, 'manifests.git'), |
| 148 | worktree = os.path.join(repodir, 'manifests')) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 149 | |
| 150 | self._Unload() |
| 151 | |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 152 | def Override(self, name, load_local_manifests=True): |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 153 | """Use a different manifest, just for the current instantiation. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 154 | """ |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 155 | path = None |
| 156 | |
| 157 | # Look for a manifest by path in the filesystem (including the cwd). |
| 158 | if not load_local_manifests: |
| 159 | local_path = os.path.abspath(name) |
| 160 | if os.path.isfile(local_path): |
| 161 | path = local_path |
| 162 | |
| 163 | # Look for manifests by name from the manifests repo. |
| 164 | if path is None: |
| 165 | path = os.path.join(self.manifestProject.worktree, name) |
| 166 | if not os.path.isfile(path): |
| 167 | raise ManifestParseError('manifest %s not found' % name) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 168 | |
| 169 | old = self.manifestFile |
| 170 | try: |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 171 | self._load_local_manifests = load_local_manifests |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 172 | self.manifestFile = path |
| 173 | self._Unload() |
| 174 | self._Load() |
| 175 | finally: |
| 176 | self.manifestFile = old |
| 177 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 178 | def Link(self, name): |
| 179 | """Update the repo metadata to use a different manifest. |
| 180 | """ |
| 181 | self.Override(name) |
| 182 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 183 | try: |
Sebastian Frias | 223bf96 | 2012-11-21 19:09:25 +0100 | [diff] [blame] | 184 | if os.path.lexists(self.manifestFile): |
Renaud Paquay | 010fed7 | 2016-11-11 14:25:29 -0800 | [diff] [blame] | 185 | platform_utils.remove(self.manifestFile) |
Renaud Paquay | d5cec5e | 2016-11-01 11:24:03 -0700 | [diff] [blame] | 186 | platform_utils.symlink(os.path.join('manifests', name), self.manifestFile) |
Sebastian Frias | 223bf96 | 2012-11-21 19:09:25 +0100 | [diff] [blame] | 187 | except OSError as e: |
| 188 | raise ManifestParseError('cannot link manifest %s: %s' % (name, str(e))) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 189 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 190 | def _RemoteToXml(self, r, doc, root): |
| 191 | e = doc.createElement('remote') |
| 192 | root.appendChild(e) |
| 193 | e.setAttribute('name', r.name) |
| 194 | e.setAttribute('fetch', r.fetchUrl) |
Steve Rae | d648045 | 2016-08-10 15:00:00 -0700 | [diff] [blame] | 195 | if r.pushUrl is not None: |
| 196 | e.setAttribute('pushurl', r.pushUrl) |
Conley Owens | 1e7ab2a | 2013-10-08 17:26:57 -0700 | [diff] [blame] | 197 | if r.remoteAlias is not None: |
| 198 | e.setAttribute('alias', r.remoteAlias) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 199 | if r.reviewUrl is not None: |
| 200 | e.setAttribute('review', r.reviewUrl) |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 201 | if r.revision is not None: |
| 202 | e.setAttribute('revision', r.revision) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 203 | |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 204 | def _ParseGroups(self, groups): |
| 205 | return [x for x in re.split(r'[,\s]+', groups) if x] |
| 206 | |
Dan Willemsen | 5ea32d1 | 2015-09-08 13:27:20 -0700 | [diff] [blame] | 207 | def Save(self, fd, peg_rev=False, peg_rev_upstream=True, groups=None): |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 208 | """Write the current manifest out to the given file descriptor. |
| 209 | """ |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 210 | mp = self.manifestProject |
| 211 | |
Dan Willemsen | 5ea32d1 | 2015-09-08 13:27:20 -0700 | [diff] [blame] | 212 | if groups is None: |
| 213 | groups = mp.config.GetString('manifest.groups') |
Matt Gumbel | 0c635bb | 2012-12-21 10:14:53 -0800 | [diff] [blame] | 214 | if groups: |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 215 | groups = self._ParseGroups(groups) |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 216 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 217 | doc = xml.dom.minidom.Document() |
| 218 | root = doc.createElement('manifest') |
| 219 | doc.appendChild(root) |
| 220 | |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 221 | # Save out the notice. There's a little bit of work here to give it the |
| 222 | # right whitespace, which assumes that the notice is automatically indented |
| 223 | # by 4 by minidom. |
| 224 | if self.notice: |
| 225 | notice_element = root.appendChild(doc.createElement('notice')) |
| 226 | notice_lines = self.notice.splitlines() |
| 227 | indented_notice = ('\n'.join(" "*4 + line for line in notice_lines))[4:] |
| 228 | notice_element.appendChild(doc.createTextNode(indented_notice)) |
| 229 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 230 | d = self.default |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 231 | |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 232 | for r in sorted(self.remotes): |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 233 | self._RemoteToXml(self.remotes[r], doc, root) |
| 234 | if self.remotes: |
| 235 | root.appendChild(doc.createTextNode('')) |
| 236 | |
| 237 | have_default = False |
| 238 | e = doc.createElement('default') |
| 239 | if d.remote: |
| 240 | have_default = True |
| 241 | e.setAttribute('remote', d.remote.name) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 242 | if d.revisionExpr: |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 243 | have_default = True |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 244 | e.setAttribute('revision', d.revisionExpr) |
Simon Ruggier | 7e59de2 | 2015-07-24 12:50:06 +0200 | [diff] [blame] | 245 | if d.destBranchExpr: |
| 246 | have_default = True |
| 247 | e.setAttribute('dest-branch', d.destBranchExpr) |
Nasser Grainawi | da40341 | 2018-05-04 12:53:29 -0600 | [diff] [blame] | 248 | if d.upstreamExpr: |
| 249 | have_default = True |
| 250 | e.setAttribute('upstream', d.upstreamExpr) |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 251 | if d.sync_j > 1: |
| 252 | have_default = True |
| 253 | e.setAttribute('sync-j', '%d' % d.sync_j) |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 254 | if d.sync_c: |
| 255 | have_default = True |
| 256 | e.setAttribute('sync-c', 'true') |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 257 | if d.sync_s: |
| 258 | have_default = True |
| 259 | e.setAttribute('sync-s', 'true') |
YOUNG HO CHA | a32c92c | 2018-02-14 16:57:31 +0900 | [diff] [blame] | 260 | if not d.sync_tags: |
| 261 | have_default = True |
| 262 | e.setAttribute('sync-tags', 'false') |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 263 | if have_default: |
| 264 | root.appendChild(e) |
| 265 | root.appendChild(doc.createTextNode('')) |
| 266 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 267 | if self._manifest_server: |
| 268 | e = doc.createElement('manifest-server') |
| 269 | e.setAttribute('url', self._manifest_server) |
| 270 | root.appendChild(e) |
| 271 | root.appendChild(doc.createTextNode('')) |
| 272 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 273 | def output_projects(parent, parent_node, projects): |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 274 | for project_name in projects: |
| 275 | for project in self._projects[project_name]: |
| 276 | output_project(parent, parent_node, project) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 277 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 278 | def output_project(parent, parent_node, p): |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 279 | if not p.MatchesGroups(groups): |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 280 | return |
| 281 | |
| 282 | name = p.name |
| 283 | relpath = p.relpath |
| 284 | if parent: |
| 285 | name = self._UnjoinName(parent.name, name) |
| 286 | relpath = self._UnjoinRelpath(parent.relpath, relpath) |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 287 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 288 | e = doc.createElement('project') |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 289 | parent_node.appendChild(e) |
| 290 | e.setAttribute('name', name) |
| 291 | if relpath != name: |
| 292 | e.setAttribute('path', relpath) |
Conley Owens | a17d7af | 2013-10-16 14:38:09 -0700 | [diff] [blame] | 293 | remoteName = None |
| 294 | if d.remote: |
Dan Willemsen | 96c2d65 | 2016-04-06 16:03:54 -0700 | [diff] [blame] | 295 | remoteName = d.remote.name |
| 296 | if not d.remote or p.remote.orig_name != remoteName: |
| 297 | remoteName = p.remote.orig_name |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 298 | e.setAttribute('remote', remoteName) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 299 | if peg_rev: |
| 300 | if self.IsMirror: |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 301 | value = p.bare_git.rev_parse(p.revisionExpr + '^0') |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 302 | else: |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 303 | value = p.work_git.rev_parse(HEAD + '^0') |
| 304 | e.setAttribute('revision', value) |
Conley Owens | 551dfec | 2015-07-10 14:54:54 -0700 | [diff] [blame] | 305 | if peg_rev_upstream: |
| 306 | if p.upstream: |
| 307 | e.setAttribute('upstream', p.upstream) |
| 308 | elif value != p.revisionExpr: |
| 309 | # Only save the origin if the origin is not a sha1, and the default |
| 310 | # isn't our value |
| 311 | e.setAttribute('upstream', p.revisionExpr) |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 312 | else: |
Dan Willemsen | 96c2d65 | 2016-04-06 16:03:54 -0700 | [diff] [blame] | 313 | revision = self.remotes[p.remote.orig_name].revision or d.revisionExpr |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 314 | if not revision or revision != p.revisionExpr: |
| 315 | e.setAttribute('revision', p.revisionExpr) |
Nasser Grainawi | da40341 | 2018-05-04 12:53:29 -0600 | [diff] [blame] | 316 | if (p.upstream and (p.upstream != p.revisionExpr or |
| 317 | p.upstream != d.upstreamExpr)): |
Mani Chandel | 7a91d51 | 2014-07-24 16:27:08 +0530 | [diff] [blame] | 318 | e.setAttribute('upstream', p.upstream) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 319 | |
Simon Ruggier | 7e59de2 | 2015-07-24 12:50:06 +0200 | [diff] [blame] | 320 | if p.dest_branch and p.dest_branch != d.destBranchExpr: |
| 321 | e.setAttribute('dest-branch', p.dest_branch) |
| 322 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 323 | for c in p.copyfiles: |
| 324 | ce = doc.createElement('copyfile') |
| 325 | ce.setAttribute('src', c.src) |
| 326 | ce.setAttribute('dest', c.dest) |
| 327 | e.appendChild(ce) |
| 328 | |
Jeff Hamilton | e0df232 | 2014-04-21 17:10:59 -0500 | [diff] [blame] | 329 | for l in p.linkfiles: |
| 330 | le = doc.createElement('linkfile') |
| 331 | le.setAttribute('src', l.src) |
| 332 | le.setAttribute('dest', l.dest) |
| 333 | e.appendChild(le) |
| 334 | |
Conley Owens | bb1b5f5 | 2012-08-13 13:11:18 -0700 | [diff] [blame] | 335 | default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath] |
Dmitry Fink | 17f85ea | 2012-08-06 14:52:29 -0700 | [diff] [blame] | 336 | egroups = [g for g in p.groups if g not in default_groups] |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 337 | if egroups: |
| 338 | e.setAttribute('groups', ','.join(egroups)) |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 339 | |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 340 | for a in p.annotations: |
| 341 | if a.keep == "true": |
| 342 | ae = doc.createElement('annotation') |
| 343 | ae.setAttribute('name', a.name) |
| 344 | ae.setAttribute('value', a.value) |
| 345 | e.appendChild(ae) |
| 346 | |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 347 | if p.sync_c: |
| 348 | e.setAttribute('sync-c', 'true') |
| 349 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 350 | if p.sync_s: |
| 351 | e.setAttribute('sync-s', 'true') |
| 352 | |
YOUNG HO CHA | a32c92c | 2018-02-14 16:57:31 +0900 | [diff] [blame] | 353 | if not p.sync_tags: |
| 354 | e.setAttribute('sync-tags', 'false') |
| 355 | |
Dan Willemsen | 8840922 | 2015-08-17 15:29:10 -0700 | [diff] [blame] | 356 | if p.clone_depth: |
| 357 | e.setAttribute('clone-depth', str(p.clone_depth)) |
| 358 | |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 359 | self._output_manifest_project_extras(p, e) |
| 360 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 361 | if p.subprojects: |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 362 | subprojects = set(subp.name for subp in p.subprojects) |
| 363 | output_projects(p, e, list(sorted(subprojects))) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 364 | |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 365 | projects = set(p.name for p in self._paths.values() if not p.parent) |
| 366 | output_projects(None, root, list(sorted(projects))) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 367 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 368 | if self._repo_hooks_project: |
| 369 | root.appendChild(doc.createTextNode('')) |
| 370 | e = doc.createElement('repo-hooks') |
| 371 | e.setAttribute('in-project', self._repo_hooks_project.name) |
| 372 | e.setAttribute('enabled-list', |
| 373 | ' '.join(self._repo_hooks_project.enabled_repo_hooks)) |
| 374 | root.appendChild(e) |
| 375 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 376 | doc.writexml(fd, '', ' ', '\n', 'UTF-8') |
| 377 | |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 378 | def _output_manifest_project_extras(self, p, e): |
| 379 | """Manifests can modify e if they support extra project attributes.""" |
| 380 | pass |
| 381 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 382 | @property |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 383 | def paths(self): |
| 384 | self._Load() |
| 385 | return self._paths |
| 386 | |
| 387 | @property |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 388 | def projects(self): |
| 389 | self._Load() |
Anthony King | d58bfe5 | 2014-05-05 23:30:49 +0100 | [diff] [blame] | 390 | return list(self._paths.values()) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 391 | |
| 392 | @property |
| 393 | def remotes(self): |
| 394 | self._Load() |
| 395 | return self._remotes |
| 396 | |
| 397 | @property |
| 398 | def default(self): |
| 399 | self._Load() |
| 400 | return self._default |
| 401 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 402 | @property |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 403 | def repo_hooks_project(self): |
| 404 | self._Load() |
| 405 | return self._repo_hooks_project |
| 406 | |
| 407 | @property |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 408 | def notice(self): |
| 409 | self._Load() |
| 410 | return self._notice |
| 411 | |
| 412 | @property |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 413 | def manifest_server(self): |
| 414 | self._Load() |
Shawn O. Pearce | 34fb20f | 2011-11-30 13:41:02 -0800 | [diff] [blame] | 415 | return self._manifest_server |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 416 | |
| 417 | @property |
Xin Li | 745be2e | 2019-06-03 11:24:30 -0700 | [diff] [blame] | 418 | def CloneFilter(self): |
| 419 | if self.manifestProject.config.GetBoolean('repo.partialclone'): |
| 420 | return self.manifestProject.config.GetString('repo.clonefilter') |
| 421 | return None |
| 422 | |
| 423 | @property |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 424 | def IsMirror(self): |
| 425 | return self.manifestProject.config.GetBoolean('repo.mirror') |
| 426 | |
Julien Campergue | 335f5ef | 2013-10-16 11:02:35 +0200 | [diff] [blame] | 427 | @property |
| 428 | def IsArchive(self): |
| 429 | return self.manifestProject.config.GetBoolean('repo.archive') |
| 430 | |
Martin Kelly | e4e94d2 | 2017-03-21 16:05:12 -0700 | [diff] [blame] | 431 | @property |
| 432 | def HasSubmodules(self): |
| 433 | return self.manifestProject.config.GetBoolean('repo.submodules') |
| 434 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 435 | def _Unload(self): |
| 436 | self._loaded = False |
| 437 | self._projects = {} |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 438 | self._paths = {} |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 439 | self._remotes = {} |
| 440 | self._default = None |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 441 | self._repo_hooks_project = None |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 442 | self._notice = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 443 | self.branch = None |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 444 | self._manifest_server = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 445 | |
| 446 | def _Load(self): |
| 447 | if not self._loaded: |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 448 | m = self.manifestProject |
| 449 | b = m.GetBranch(m.CurrentBranch).merge |
Shawn O. Pearce | 21c5c34 | 2009-06-25 16:47:30 -0700 | [diff] [blame] | 450 | if b is not None and b.startswith(R_HEADS): |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 451 | b = b[len(R_HEADS):] |
| 452 | self.branch = b |
| 453 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 454 | nodes = [] |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 455 | nodes.append(self._ParseManifestXml(self.manifestFile, |
| 456 | self.manifestProject.worktree)) |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 457 | |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 458 | if self._load_local_manifests: |
| 459 | local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME) |
| 460 | if os.path.exists(local): |
| 461 | if not self.localManifestWarning: |
| 462 | self.localManifestWarning = True |
| 463 | print('warning: %s is deprecated; put local manifests ' |
| 464 | 'in `%s` instead' % (LOCAL_MANIFEST_NAME, |
| 465 | os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME)), |
| 466 | file=sys.stderr) |
| 467 | nodes.append(self._ParseManifestXml(local, self.repodir)) |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 468 | |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 469 | local_dir = os.path.abspath(os.path.join(self.repodir, |
| 470 | LOCAL_MANIFESTS_DIR_NAME)) |
| 471 | try: |
| 472 | for local_file in sorted(platform_utils.listdir(local_dir)): |
| 473 | if local_file.endswith('.xml'): |
| 474 | local = os.path.join(local_dir, local_file) |
| 475 | nodes.append(self._ParseManifestXml(local, self.repodir)) |
| 476 | except OSError: |
| 477 | pass |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 478 | |
Joe Onorato | 26e2475 | 2013-01-11 12:35:53 -0800 | [diff] [blame] | 479 | try: |
| 480 | self._ParseManifest(nodes) |
| 481 | except ManifestParseError as e: |
| 482 | # There was a problem parsing, unload ourselves in case they catch |
| 483 | # this error and try again later, we will show the correct error |
| 484 | self._Unload() |
| 485 | raise e |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 486 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 487 | if self.IsMirror: |
| 488 | self._AddMetaProjectMirror(self.repoProject) |
| 489 | self._AddMetaProjectMirror(self.manifestProject) |
| 490 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 491 | self._loaded = True |
| 492 | |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 493 | def _ParseManifestXml(self, path, include_root): |
David Pursehouse | f7fc8a9 | 2012-11-13 04:00:28 +0900 | [diff] [blame] | 494 | try: |
| 495 | root = xml.dom.minidom.parse(path) |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 496 | except (OSError, xml.parsers.expat.ExpatError) as e: |
David Pursehouse | f7fc8a9 | 2012-11-13 04:00:28 +0900 | [diff] [blame] | 497 | raise ManifestParseError("error parsing manifest %s: %s" % (path, e)) |
| 498 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 499 | if not root or not root.childNodes: |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 500 | raise ManifestParseError("no root node in %s" % (path,)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 501 | |
Jooncheol Park | 34acdd2 | 2012-08-27 02:25:59 +0900 | [diff] [blame] | 502 | for manifest in root.childNodes: |
| 503 | if manifest.nodeName == 'manifest': |
| 504 | break |
| 505 | else: |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 506 | raise ManifestParseError("no <manifest> in %s" % (path,)) |
| 507 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 508 | nodes = [] |
David Pursehouse | 65b0ba5 | 2018-06-24 16:21:51 +0900 | [diff] [blame] | 509 | for node in manifest.childNodes: |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 510 | if node.nodeName == 'include': |
| 511 | name = self._reqatt(node, 'name') |
| 512 | fp = os.path.join(include_root, name) |
| 513 | if not os.path.isfile(fp): |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 514 | raise ManifestParseError("include %s doesn't exist or isn't a file" |
| 515 | % (name,)) |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 516 | try: |
| 517 | nodes.extend(self._ParseManifestXml(fp, include_root)) |
| 518 | # should isolate this to the exact exception, but that's |
| 519 | # tricky. actual parsing implementation may vary. |
| 520 | except (KeyboardInterrupt, RuntimeError, SystemExit): |
| 521 | raise |
| 522 | except Exception as e: |
| 523 | raise ManifestParseError( |
Mike Frysinger | ec558df | 2019-07-05 01:38:05 -0400 | [diff] [blame] | 524 | "failed parsing included manifest %s: %s" % (name, e)) |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 525 | else: |
| 526 | nodes.append(node) |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 527 | return nodes |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 528 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 529 | def _ParseManifest(self, node_list): |
| 530 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 531 | if node.nodeName == 'remote': |
| 532 | remote = self._ParseRemote(node) |
David Pursehouse | 717ece9 | 2012-11-13 08:49:16 +0900 | [diff] [blame] | 533 | if remote: |
| 534 | if remote.name in self._remotes: |
| 535 | if remote != self._remotes[remote.name]: |
| 536 | raise ManifestParseError( |
| 537 | 'remote %s already exists with different attributes' % |
| 538 | (remote.name)) |
| 539 | else: |
| 540 | self._remotes[remote.name] = remote |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 541 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 542 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 543 | if node.nodeName == 'default': |
Julien Campergue | 7487992 | 2013-10-09 14:38:46 +0200 | [diff] [blame] | 544 | new_default = self._ParseDefault(node) |
| 545 | if self._default is None: |
| 546 | self._default = new_default |
| 547 | elif new_default != self._default: |
David Pursehouse | 37128b6 | 2013-10-15 10:48:40 +0900 | [diff] [blame] | 548 | raise ManifestParseError('duplicate default in %s' % |
| 549 | (self.manifestFile)) |
Julien Campergue | 7487992 | 2013-10-09 14:38:46 +0200 | [diff] [blame] | 550 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 551 | if self._default is None: |
| 552 | self._default = _Default() |
| 553 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 554 | for node in itertools.chain(*node_list): |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 555 | if node.nodeName == 'notice': |
| 556 | if self._notice is not None: |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 557 | raise ManifestParseError( |
| 558 | 'duplicate notice in %s' % |
| 559 | (self.manifestFile)) |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 560 | self._notice = self._ParseNotice(node) |
| 561 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 562 | for node in itertools.chain(*node_list): |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 563 | if node.nodeName == 'manifest-server': |
| 564 | url = self._reqatt(node, 'url') |
| 565 | if self._manifest_server is not None: |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 566 | raise ManifestParseError( |
| 567 | 'duplicate manifest-server in %s' % |
| 568 | (self.manifestFile)) |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 569 | self._manifest_server = url |
| 570 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 571 | def recursively_add_projects(project): |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 572 | projects = self._projects.setdefault(project.name, []) |
| 573 | if project.relpath is None: |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 574 | raise ManifestParseError( |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 575 | 'missing path for %s in %s' % |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 576 | (project.name, self.manifestFile)) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 577 | if project.relpath in self._paths: |
| 578 | raise ManifestParseError( |
| 579 | 'duplicate path %s in %s' % |
| 580 | (project.relpath, self.manifestFile)) |
| 581 | self._paths[project.relpath] = project |
| 582 | projects.append(project) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 583 | for subproject in project.subprojects: |
| 584 | recursively_add_projects(subproject) |
| 585 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 586 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 587 | if node.nodeName == 'project': |
| 588 | project = self._ParseProject(node) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 589 | recursively_add_projects(project) |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 590 | if node.nodeName == 'extend-project': |
| 591 | name = self._reqatt(node, 'name') |
| 592 | |
| 593 | if name not in self._projects: |
| 594 | raise ManifestParseError('extend-project element specifies non-existent ' |
| 595 | 'project: %s' % name) |
| 596 | |
| 597 | path = node.getAttribute('path') |
| 598 | groups = node.getAttribute('groups') |
| 599 | if groups: |
| 600 | groups = self._ParseGroups(groups) |
Luis Hector Chavez | 7d52585 | 2018-03-15 09:54:08 -0700 | [diff] [blame] | 601 | revision = node.getAttribute('revision') |
Kyunam Jo | bd0aae9 | 2020-02-04 11:38:53 +0900 | [diff] [blame] | 602 | remote = node.getAttribute('remote') |
| 603 | if remote: |
| 604 | remote = self._get_remote(node) |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 605 | |
| 606 | for p in self._projects[name]: |
| 607 | if path and p.relpath != path: |
| 608 | continue |
| 609 | if groups: |
| 610 | p.groups.extend(groups) |
Luis Hector Chavez | 7d52585 | 2018-03-15 09:54:08 -0700 | [diff] [blame] | 611 | if revision: |
| 612 | p.revisionExpr = revision |
Kyunam Jo | bd0aae9 | 2020-02-04 11:38:53 +0900 | [diff] [blame] | 613 | if remote: |
| 614 | p.remote = remote.ToRemoteSpec(name) |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 615 | if node.nodeName == 'repo-hooks': |
| 616 | # Get the name of the project and the (space-separated) list of enabled. |
| 617 | repo_hooks_project = self._reqatt(node, 'in-project') |
| 618 | enabled_repo_hooks = self._reqatt(node, 'enabled-list').split() |
| 619 | |
| 620 | # Only one project can be the hooks project |
| 621 | if self._repo_hooks_project is not None: |
| 622 | raise ManifestParseError( |
| 623 | 'duplicate repo-hooks in %s' % |
| 624 | (self.manifestFile)) |
| 625 | |
| 626 | # Store a reference to the Project. |
| 627 | try: |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 628 | repo_hooks_projects = self._projects[repo_hooks_project] |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 629 | except KeyError: |
| 630 | raise ManifestParseError( |
| 631 | 'project %s not found for repo-hooks' % |
| 632 | (repo_hooks_project)) |
| 633 | |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 634 | if len(repo_hooks_projects) != 1: |
| 635 | raise ManifestParseError( |
| 636 | 'internal error parsing repo-hooks in %s' % |
| 637 | (self.manifestFile)) |
| 638 | self._repo_hooks_project = repo_hooks_projects[0] |
| 639 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 640 | # Store the enabled hooks in the Project object. |
| 641 | self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 642 | if node.nodeName == 'remove-project': |
| 643 | name = self._reqatt(node, 'name') |
David James | b8433df | 2014-01-30 10:11:17 -0800 | [diff] [blame] | 644 | |
| 645 | if name not in self._projects: |
David Pursehouse | f910748 | 2012-11-16 19:12:32 +0900 | [diff] [blame] | 646 | raise ManifestParseError('remove-project element specifies non-existent ' |
| 647 | 'project: %s' % name) |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 648 | |
David James | b8433df | 2014-01-30 10:11:17 -0800 | [diff] [blame] | 649 | for p in self._projects[name]: |
| 650 | del self._paths[p.relpath] |
| 651 | del self._projects[name] |
| 652 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 653 | # If the manifest removes the hooks project, treat it as if it deleted |
| 654 | # the repo-hooks element too. |
| 655 | if self._repo_hooks_project and (self._repo_hooks_project.name == name): |
| 656 | self._repo_hooks_project = None |
| 657 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 658 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 659 | def _AddMetaProjectMirror(self, m): |
| 660 | name = None |
| 661 | m_url = m.GetRemote(m.remote.name).url |
| 662 | if m_url.endswith('/.git'): |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 663 | raise ManifestParseError('refusing to mirror %s' % m_url) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 664 | |
| 665 | if self._default and self._default.remote: |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 666 | url = self._default.remote.resolvedFetchUrl |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 667 | if not url.endswith('/'): |
| 668 | url += '/' |
| 669 | if m_url.startswith(url): |
| 670 | remote = self._default.remote |
| 671 | name = m_url[len(url):] |
| 672 | |
| 673 | if name is None: |
| 674 | s = m_url.rindex('/') + 1 |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 675 | manifestUrl = self.manifestProject.config.GetString('remote.origin.url') |
Shawn O. Pearce | f35b2d9 | 2012-08-02 11:46:22 -0700 | [diff] [blame] | 676 | remote = _XmlRemote('origin', fetch=m_url[:s], manifestUrl=manifestUrl) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 677 | name = m_url[s:] |
| 678 | |
| 679 | if name.endswith('.git'): |
| 680 | name = name[:-4] |
| 681 | |
| 682 | if name not in self._projects: |
| 683 | m.PreSync() |
| 684 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 685 | project = Project(manifest = self, |
| 686 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 687 | remote = remote.ToRemoteSpec(name), |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 688 | gitdir = gitdir, |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 689 | objdir = gitdir, |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 690 | worktree = None, |
Kwanhong Lee | ccd218c | 2014-02-17 13:07:32 +0900 | [diff] [blame] | 691 | relpath = name or None, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 692 | revisionExpr = m.revisionExpr, |
| 693 | revisionId = None) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 694 | self._projects[project.name] = [project] |
Kwanhong Lee | ccd218c | 2014-02-17 13:07:32 +0900 | [diff] [blame] | 695 | self._paths[project.relpath] = project |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 696 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 697 | def _ParseRemote(self, node): |
| 698 | """ |
| 699 | reads a <remote> element from the manifest file |
| 700 | """ |
| 701 | name = self._reqatt(node, 'name') |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 702 | alias = node.getAttribute('alias') |
| 703 | if alias == '': |
| 704 | alias = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 705 | fetch = self._reqatt(node, 'fetch') |
Steve Rae | d648045 | 2016-08-10 15:00:00 -0700 | [diff] [blame] | 706 | pushUrl = node.getAttribute('pushurl') |
| 707 | if pushUrl == '': |
| 708 | pushUrl = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 709 | review = node.getAttribute('review') |
Shawn O. Pearce | ae6e094 | 2008-11-06 10:25:35 -0800 | [diff] [blame] | 710 | if review == '': |
| 711 | review = None |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 712 | revision = node.getAttribute('revision') |
| 713 | if revision == '': |
| 714 | revision = None |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 715 | manifestUrl = self.manifestProject.config.GetString('remote.origin.url') |
Steve Rae | d648045 | 2016-08-10 15:00:00 -0700 | [diff] [blame] | 716 | return _XmlRemote(name, alias, fetch, pushUrl, manifestUrl, review, revision) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 717 | |
| 718 | def _ParseDefault(self, node): |
| 719 | """ |
| 720 | reads a <default> element from the manifest file |
| 721 | """ |
| 722 | d = _Default() |
| 723 | d.remote = self._get_remote(node) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 724 | d.revisionExpr = node.getAttribute('revision') |
| 725 | if d.revisionExpr == '': |
| 726 | d.revisionExpr = None |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 727 | |
Bryan Jacobs | f609f91 | 2013-05-06 13:36:24 -0400 | [diff] [blame] | 728 | d.destBranchExpr = node.getAttribute('dest-branch') or None |
Nasser Grainawi | da40341 | 2018-05-04 12:53:29 -0600 | [diff] [blame] | 729 | d.upstreamExpr = node.getAttribute('upstream') or None |
Bryan Jacobs | f609f91 | 2013-05-06 13:36:24 -0400 | [diff] [blame] | 730 | |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 731 | sync_j = node.getAttribute('sync-j') |
| 732 | if sync_j == '' or sync_j is None: |
| 733 | d.sync_j = 1 |
| 734 | else: |
| 735 | d.sync_j = int(sync_j) |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 736 | |
| 737 | sync_c = node.getAttribute('sync-c') |
| 738 | if not sync_c: |
| 739 | d.sync_c = False |
| 740 | else: |
| 741 | d.sync_c = sync_c.lower() in ("yes", "true", "1") |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 742 | |
| 743 | sync_s = node.getAttribute('sync-s') |
| 744 | if not sync_s: |
| 745 | d.sync_s = False |
| 746 | else: |
| 747 | d.sync_s = sync_s.lower() in ("yes", "true", "1") |
YOUNG HO CHA | a32c92c | 2018-02-14 16:57:31 +0900 | [diff] [blame] | 748 | |
| 749 | sync_tags = node.getAttribute('sync-tags') |
| 750 | if not sync_tags: |
| 751 | d.sync_tags = True |
| 752 | else: |
| 753 | d.sync_tags = sync_tags.lower() in ("yes", "true", "1") |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 754 | return d |
| 755 | |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 756 | def _ParseNotice(self, node): |
| 757 | """ |
| 758 | reads a <notice> element from the manifest file |
| 759 | |
| 760 | The <notice> element is distinct from other tags in the XML in that the |
| 761 | data is conveyed between the start and end tag (it's not an empty-element |
| 762 | tag). |
| 763 | |
| 764 | The white space (carriage returns, indentation) for the notice element is |
| 765 | relevant and is parsed in a way that is based on how python docstrings work. |
| 766 | In fact, the code is remarkably similar to here: |
| 767 | http://www.python.org/dev/peps/pep-0257/ |
| 768 | """ |
| 769 | # Get the data out of the node... |
| 770 | notice = node.childNodes[0].data |
| 771 | |
| 772 | # Figure out minimum indentation, skipping the first line (the same line |
| 773 | # as the <notice> tag)... |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 774 | minIndent = sys.maxsize |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 775 | lines = notice.splitlines() |
| 776 | for line in lines[1:]: |
| 777 | lstrippedLine = line.lstrip() |
| 778 | if lstrippedLine: |
| 779 | indent = len(line) - len(lstrippedLine) |
| 780 | minIndent = min(indent, minIndent) |
| 781 | |
| 782 | # Strip leading / trailing blank lines and also indentation. |
| 783 | cleanLines = [lines[0].strip()] |
| 784 | for line in lines[1:]: |
| 785 | cleanLines.append(line[minIndent:].rstrip()) |
| 786 | |
| 787 | # Clear completely blank lines from front and back... |
| 788 | while cleanLines and not cleanLines[0]: |
| 789 | del cleanLines[0] |
| 790 | while cleanLines and not cleanLines[-1]: |
| 791 | del cleanLines[-1] |
| 792 | |
| 793 | return '\n'.join(cleanLines) |
| 794 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 795 | def _JoinName(self, parent_name, name): |
| 796 | return os.path.join(parent_name, name) |
| 797 | |
| 798 | def _UnjoinName(self, parent_name, name): |
| 799 | return os.path.relpath(name, parent_name) |
| 800 | |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 801 | def _ParseProject(self, node, parent = None, **extra_proj_attrs): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 802 | """ |
| 803 | reads a <project> element from the manifest file |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 804 | """ |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 805 | name = self._reqatt(node, 'name') |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 806 | if parent: |
| 807 | name = self._JoinName(parent.name, name) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 808 | |
| 809 | remote = self._get_remote(node) |
| 810 | if remote is None: |
| 811 | remote = self._default.remote |
| 812 | if remote is None: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 813 | raise ManifestParseError("no remote for project %s within %s" % |
| 814 | (name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 815 | |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 816 | revisionExpr = node.getAttribute('revision') or remote.revision |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 817 | if not revisionExpr: |
| 818 | revisionExpr = self._default.revisionExpr |
| 819 | if not revisionExpr: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 820 | raise ManifestParseError("no revision for project %s within %s" % |
| 821 | (name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 822 | |
| 823 | path = node.getAttribute('path') |
| 824 | if not path: |
| 825 | path = name |
| 826 | if path.startswith('/'): |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 827 | raise ManifestParseError("project %s path cannot be absolute in %s" % |
| 828 | (name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 829 | |
Mike Pontillo | d315382 | 2012-02-28 11:53:24 -0800 | [diff] [blame] | 830 | rebase = node.getAttribute('rebase') |
| 831 | if not rebase: |
| 832 | rebase = True |
| 833 | else: |
| 834 | rebase = rebase.lower() in ("yes", "true", "1") |
| 835 | |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 836 | sync_c = node.getAttribute('sync-c') |
| 837 | if not sync_c: |
| 838 | sync_c = False |
| 839 | else: |
| 840 | sync_c = sync_c.lower() in ("yes", "true", "1") |
| 841 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 842 | sync_s = node.getAttribute('sync-s') |
| 843 | if not sync_s: |
| 844 | sync_s = self._default.sync_s |
| 845 | else: |
| 846 | sync_s = sync_s.lower() in ("yes", "true", "1") |
| 847 | |
YOUNG HO CHA | a32c92c | 2018-02-14 16:57:31 +0900 | [diff] [blame] | 848 | sync_tags = node.getAttribute('sync-tags') |
| 849 | if not sync_tags: |
| 850 | sync_tags = self._default.sync_tags |
| 851 | else: |
| 852 | sync_tags = sync_tags.lower() in ("yes", "true", "1") |
| 853 | |
David Pursehouse | ede7f12 | 2012-11-27 22:25:30 +0900 | [diff] [blame] | 854 | clone_depth = node.getAttribute('clone-depth') |
| 855 | if clone_depth: |
| 856 | try: |
| 857 | clone_depth = int(clone_depth) |
| 858 | if clone_depth <= 0: |
| 859 | raise ValueError() |
| 860 | except ValueError: |
| 861 | raise ManifestParseError('invalid clone-depth %s in %s' % |
| 862 | (clone_depth, self.manifestFile)) |
| 863 | |
Bryan Jacobs | f609f91 | 2013-05-06 13:36:24 -0400 | [diff] [blame] | 864 | dest_branch = node.getAttribute('dest-branch') or self._default.destBranchExpr |
| 865 | |
Nasser Grainawi | da40341 | 2018-05-04 12:53:29 -0600 | [diff] [blame] | 866 | upstream = node.getAttribute('upstream') or self._default.upstreamExpr |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 867 | |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 868 | groups = '' |
| 869 | if node.hasAttribute('groups'): |
| 870 | groups = node.getAttribute('groups') |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 871 | groups = self._ParseGroups(groups) |
Brian Harring | 7da1314 | 2012-06-15 02:24:20 -0700 | [diff] [blame] | 872 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 873 | if parent is None: |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 874 | relpath, worktree, gitdir, objdir = self.GetProjectPaths(name, path) |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 875 | else: |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 876 | relpath, worktree, gitdir, objdir = \ |
| 877 | self.GetSubprojectPaths(parent, name, path) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 878 | |
| 879 | default_groups = ['all', 'name:%s' % name, 'path:%s' % relpath] |
| 880 | groups.extend(set(default_groups).difference(groups)) |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 881 | |
Scott Fan | db83b1b | 2013-02-28 09:34:14 +0800 | [diff] [blame] | 882 | if self.IsMirror and node.hasAttribute('force-path'): |
| 883 | if node.getAttribute('force-path').lower() in ("yes", "true", "1"): |
| 884 | gitdir = os.path.join(self.topdir, '%s.git' % path) |
| 885 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 886 | project = Project(manifest = self, |
| 887 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 888 | remote = remote.ToRemoteSpec(name), |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 889 | gitdir = gitdir, |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 890 | objdir = objdir, |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 891 | worktree = worktree, |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 892 | relpath = relpath, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 893 | revisionExpr = revisionExpr, |
Mike Pontillo | d315382 | 2012-02-28 11:53:24 -0800 | [diff] [blame] | 894 | revisionId = None, |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 895 | rebase = rebase, |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 896 | groups = groups, |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 897 | sync_c = sync_c, |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 898 | sync_s = sync_s, |
YOUNG HO CHA | a32c92c | 2018-02-14 16:57:31 +0900 | [diff] [blame] | 899 | sync_tags = sync_tags, |
David Pursehouse | ede7f12 | 2012-11-27 22:25:30 +0900 | [diff] [blame] | 900 | clone_depth = clone_depth, |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 901 | upstream = upstream, |
Bryan Jacobs | f609f91 | 2013-05-06 13:36:24 -0400 | [diff] [blame] | 902 | parent = parent, |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 903 | dest_branch = dest_branch, |
| 904 | **extra_proj_attrs) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 905 | |
| 906 | for n in node.childNodes: |
Shawn O. Pearce | 242b526 | 2009-05-19 13:00:29 -0700 | [diff] [blame] | 907 | if n.nodeName == 'copyfile': |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 908 | self._ParseCopyFile(project, n) |
Jeff Hamilton | e0df232 | 2014-04-21 17:10:59 -0500 | [diff] [blame] | 909 | if n.nodeName == 'linkfile': |
| 910 | self._ParseLinkFile(project, n) |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 911 | if n.nodeName == 'annotation': |
| 912 | self._ParseAnnotation(project, n) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 913 | if n.nodeName == 'project': |
| 914 | project.subprojects.append(self._ParseProject(n, parent = project)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 915 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 916 | return project |
| 917 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 918 | def GetProjectPaths(self, name, path): |
| 919 | relpath = path |
| 920 | if self.IsMirror: |
| 921 | worktree = None |
| 922 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 923 | objdir = gitdir |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 924 | else: |
| 925 | worktree = os.path.join(self.topdir, path).replace('\\', '/') |
| 926 | gitdir = os.path.join(self.repodir, 'projects', '%s.git' % path) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 927 | objdir = os.path.join(self.repodir, 'project-objects', '%s.git' % name) |
| 928 | return relpath, worktree, gitdir, objdir |
| 929 | |
| 930 | def GetProjectsWithName(self, name): |
| 931 | return self._projects.get(name, []) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 932 | |
| 933 | def GetSubprojectName(self, parent, submodule_path): |
| 934 | return os.path.join(parent.name, submodule_path) |
| 935 | |
| 936 | def _JoinRelpath(self, parent_relpath, relpath): |
| 937 | return os.path.join(parent_relpath, relpath) |
| 938 | |
| 939 | def _UnjoinRelpath(self, parent_relpath, relpath): |
| 940 | return os.path.relpath(relpath, parent_relpath) |
| 941 | |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 942 | def GetSubprojectPaths(self, parent, name, path): |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 943 | relpath = self._JoinRelpath(parent.relpath, path) |
| 944 | gitdir = os.path.join(parent.gitdir, 'subprojects', '%s.git' % path) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 945 | objdir = os.path.join(parent.gitdir, 'subproject-objects', '%s.git' % name) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 946 | if self.IsMirror: |
| 947 | worktree = None |
| 948 | else: |
| 949 | worktree = os.path.join(parent.worktree, path).replace('\\', '/') |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 950 | return relpath, worktree, gitdir, objdir |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 951 | |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 952 | @staticmethod |
| 953 | def _CheckLocalPath(path, symlink=False): |
| 954 | """Verify |path| is reasonable for use in <copyfile> & <linkfile>.""" |
| 955 | if '~' in path: |
| 956 | return '~ not allowed (due to 8.3 filenames on Windows filesystems)' |
| 957 | |
| 958 | # Some filesystems (like Apple's HFS+) try to normalize Unicode codepoints |
| 959 | # which means there are alternative names for ".git". Reject paths with |
| 960 | # these in it as there shouldn't be any reasonable need for them here. |
| 961 | # The set of codepoints here was cribbed from jgit's implementation: |
| 962 | # https://eclipse.googlesource.com/jgit/jgit/+/9110037e3e9461ff4dac22fee84ef3694ed57648/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java#884 |
| 963 | BAD_CODEPOINTS = { |
| 964 | u'\u200C', # ZERO WIDTH NON-JOINER |
| 965 | u'\u200D', # ZERO WIDTH JOINER |
| 966 | u'\u200E', # LEFT-TO-RIGHT MARK |
| 967 | u'\u200F', # RIGHT-TO-LEFT MARK |
| 968 | u'\u202A', # LEFT-TO-RIGHT EMBEDDING |
| 969 | u'\u202B', # RIGHT-TO-LEFT EMBEDDING |
| 970 | u'\u202C', # POP DIRECTIONAL FORMATTING |
| 971 | u'\u202D', # LEFT-TO-RIGHT OVERRIDE |
| 972 | u'\u202E', # RIGHT-TO-LEFT OVERRIDE |
| 973 | u'\u206A', # INHIBIT SYMMETRIC SWAPPING |
| 974 | u'\u206B', # ACTIVATE SYMMETRIC SWAPPING |
| 975 | u'\u206C', # INHIBIT ARABIC FORM SHAPING |
| 976 | u'\u206D', # ACTIVATE ARABIC FORM SHAPING |
| 977 | u'\u206E', # NATIONAL DIGIT SHAPES |
| 978 | u'\u206F', # NOMINAL DIGIT SHAPES |
| 979 | u'\uFEFF', # ZERO WIDTH NO-BREAK SPACE |
| 980 | } |
| 981 | if BAD_CODEPOINTS & set(path): |
| 982 | # This message is more expansive than reality, but should be fine. |
| 983 | return 'Unicode combining characters not allowed' |
| 984 | |
| 985 | # Assume paths might be used on case-insensitive filesystems. |
| 986 | path = path.lower() |
| 987 | |
Mike Frysinger | ae62541 | 2020-02-10 17:10:03 -0500 | [diff] [blame] | 988 | # Some people use src="." to create stable links to projects. Lets allow |
| 989 | # that but reject all other uses of "." to keep things simple. |
| 990 | parts = path.split(os.path.sep) |
| 991 | if parts != ['.']: |
| 992 | for part in set(parts): |
| 993 | if part in {'.', '..', '.git'} or part.startswith('.repo'): |
| 994 | return 'bad component: %s' % (part,) |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 995 | |
| 996 | if not symlink and path.endswith(os.path.sep): |
| 997 | return 'dirs not allowed' |
| 998 | |
| 999 | norm = os.path.normpath(path) |
| 1000 | if norm == '..' or norm.startswith('../') or norm.startswith(os.path.sep): |
| 1001 | return 'path cannot be outside' |
| 1002 | |
| 1003 | @classmethod |
| 1004 | def _ValidateFilePaths(cls, element, src, dest): |
| 1005 | """Verify |src| & |dest| are reasonable for <copyfile> & <linkfile>. |
| 1006 | |
| 1007 | We verify the path independent of any filesystem state as we won't have a |
| 1008 | checkout available to compare to. i.e. This is for parsing validation |
| 1009 | purposes only. |
| 1010 | |
| 1011 | We'll do full/live sanity checking before we do the actual filesystem |
| 1012 | modifications in _CopyFile/_LinkFile/etc... |
| 1013 | """ |
| 1014 | # |dest| is the file we write to or symlink we create. |
| 1015 | # It is relative to the top of the repo client checkout. |
| 1016 | msg = cls._CheckLocalPath(dest) |
| 1017 | if msg: |
| 1018 | raise ManifestInvalidPathError( |
| 1019 | '<%s> invalid "dest": %s: %s' % (element, dest, msg)) |
| 1020 | |
| 1021 | # |src| is the file we read from or path we point to for symlinks. |
| 1022 | # It is relative to the top of the git project checkout. |
| 1023 | msg = cls._CheckLocalPath(src, symlink=element == 'linkfile') |
| 1024 | if msg: |
| 1025 | raise ManifestInvalidPathError( |
| 1026 | '<%s> invalid "src": %s: %s' % (element, src, msg)) |
| 1027 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1028 | def _ParseCopyFile(self, project, node): |
| 1029 | src = self._reqatt(node, 'src') |
| 1030 | dest = self._reqatt(node, 'dest') |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 1031 | if not self.IsMirror: |
| 1032 | # src is project relative; |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1033 | # dest is relative to the top of the tree. |
| 1034 | # We only validate paths if we actually plan to process them. |
| 1035 | self._ValidateFilePaths('copyfile', src, dest) |
Mike Frysinger | e6a202f | 2019-08-02 15:57:57 -0400 | [diff] [blame] | 1036 | project.AddCopyFile(src, dest, self.topdir) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1037 | |
Jeff Hamilton | e0df232 | 2014-04-21 17:10:59 -0500 | [diff] [blame] | 1038 | def _ParseLinkFile(self, project, node): |
| 1039 | src = self._reqatt(node, 'src') |
| 1040 | dest = self._reqatt(node, 'dest') |
| 1041 | if not self.IsMirror: |
| 1042 | # src is project relative; |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1043 | # dest is relative to the top of the tree. |
| 1044 | # We only validate paths if we actually plan to process them. |
| 1045 | self._ValidateFilePaths('linkfile', src, dest) |
Mike Frysinger | e6a202f | 2019-08-02 15:57:57 -0400 | [diff] [blame] | 1046 | project.AddLinkFile(src, dest, self.topdir) |
Jeff Hamilton | e0df232 | 2014-04-21 17:10:59 -0500 | [diff] [blame] | 1047 | |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 1048 | def _ParseAnnotation(self, project, node): |
| 1049 | name = self._reqatt(node, 'name') |
| 1050 | value = self._reqatt(node, 'value') |
| 1051 | try: |
| 1052 | keep = self._reqatt(node, 'keep').lower() |
| 1053 | except ManifestParseError: |
| 1054 | keep = "true" |
| 1055 | if keep != "true" and keep != "false": |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 1056 | raise ManifestParseError('optional "keep" attribute must be ' |
| 1057 | '"true" or "false"') |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 1058 | project.AddAnnotation(name, value, keep) |
| 1059 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1060 | def _get_remote(self, node): |
| 1061 | name = node.getAttribute('remote') |
| 1062 | if not name: |
| 1063 | return None |
| 1064 | |
| 1065 | v = self._remotes.get(name) |
| 1066 | if not v: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 1067 | raise ManifestParseError("remote %s not defined in %s" % |
| 1068 | (name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1069 | return v |
| 1070 | |
| 1071 | def _reqatt(self, node, attname): |
| 1072 | """ |
| 1073 | reads a required attribute from the node. |
| 1074 | """ |
| 1075 | v = node.getAttribute(attname) |
| 1076 | if not v: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 1077 | raise ManifestParseError("no %s in <%s> within %s" % |
| 1078 | (attname, node.nodeName, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1079 | return v |
Julien Campergue | dd65422 | 2014-01-09 16:21:37 +0100 | [diff] [blame] | 1080 | |
| 1081 | def projectsDiff(self, manifest): |
| 1082 | """return the projects differences between two manifests. |
| 1083 | |
| 1084 | The diff will be from self to given manifest. |
| 1085 | |
| 1086 | """ |
| 1087 | fromProjects = self.paths |
| 1088 | toProjects = manifest.paths |
| 1089 | |
Anthony King | 7446c59 | 2014-05-06 09:19:39 +0100 | [diff] [blame] | 1090 | fromKeys = sorted(fromProjects.keys()) |
| 1091 | toKeys = sorted(toProjects.keys()) |
Julien Campergue | dd65422 | 2014-01-09 16:21:37 +0100 | [diff] [blame] | 1092 | |
| 1093 | diff = {'added': [], 'removed': [], 'changed': [], 'unreachable': []} |
| 1094 | |
| 1095 | for proj in fromKeys: |
| 1096 | if not proj in toKeys: |
| 1097 | diff['removed'].append(fromProjects[proj]) |
| 1098 | else: |
| 1099 | fromProj = fromProjects[proj] |
| 1100 | toProj = toProjects[proj] |
| 1101 | try: |
| 1102 | fromRevId = fromProj.GetCommitRevisionId() |
| 1103 | toRevId = toProj.GetCommitRevisionId() |
| 1104 | except ManifestInvalidRevisionError: |
| 1105 | diff['unreachable'].append((fromProj, toProj)) |
| 1106 | else: |
| 1107 | if fromRevId != toRevId: |
| 1108 | diff['changed'].append((fromProj, toProj)) |
| 1109 | toKeys.remove(proj) |
| 1110 | |
| 1111 | for proj in toKeys: |
| 1112 | diff['added'].append(toProjects[proj]) |
| 1113 | |
| 1114 | return diff |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 1115 | |
| 1116 | |
| 1117 | class GitcManifest(XmlManifest): |
| 1118 | |
| 1119 | def __init__(self, repodir, gitc_client_name): |
| 1120 | """Initialize the GitcManifest object.""" |
| 1121 | super(GitcManifest, self).__init__(repodir) |
| 1122 | self.isGitcClient = True |
| 1123 | self.gitc_client_name = gitc_client_name |
Simran Basi | 8ce5041 | 2015-08-28 14:25:44 -0700 | [diff] [blame] | 1124 | self.gitc_client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(), |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 1125 | gitc_client_name) |
| 1126 | self.manifestFile = os.path.join(self.gitc_client_dir, '.manifest') |
| 1127 | |
| 1128 | def _ParseProject(self, node, parent = None): |
| 1129 | """Override _ParseProject and add support for GITC specific attributes.""" |
| 1130 | return super(GitcManifest, self)._ParseProject( |
| 1131 | node, parent=parent, old_revision=node.getAttribute('old-revision')) |
| 1132 | |
| 1133 | def _output_manifest_project_extras(self, p, e): |
| 1134 | """Output GITC Specific Project attributes""" |
| 1135 | if p.old_revision: |
Stefan Beller | 6685106 | 2016-06-17 16:40:08 -0700 | [diff] [blame] | 1136 | e.setAttribute('old-revision', str(p.old_revision)) |