The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # Copyright (C) 2008 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Raman Tenneti | 993af5e | 2021-05-12 12:00:31 -0700 | [diff] [blame] | 15 | import collections |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 16 | import itertools |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 17 | import os |
Raman Tenneti | 080877e | 2021-03-09 15:19:06 -0800 | [diff] [blame] | 18 | import platform |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 19 | import re |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 20 | import sys |
David Pursehouse | 59bbb58 | 2013-05-17 10:49:33 +0900 | [diff] [blame] | 21 | import xml.dom.minidom |
Mike Frysinger | acf63b2 | 2019-06-13 02:24:21 -0400 | [diff] [blame] | 22 | import urllib.parse |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 23 | |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 24 | import gitc_utils |
Miguel Gaio | 1f20776 | 2020-07-17 14:09:13 +0200 | [diff] [blame] | 25 | from git_config import GitConfig, IsId |
David Pursehouse | e00aa6b | 2012-09-11 14:33:51 +0900 | [diff] [blame] | 26 | from git_refs import R_HEADS, HEAD |
Renaud Paquay | d5cec5e | 2016-11-01 11:24:03 -0700 | [diff] [blame] | 27 | import platform_utils |
LaMont Jones | 9b72cf2 | 2022-03-29 21:54:22 +0000 | [diff] [blame] | 28 | from project import (Annotation, RemoteSpec, Project, RepoProject, |
| 29 | ManifestProject) |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 30 | from error import (ManifestParseError, ManifestInvalidPathError, |
| 31 | ManifestInvalidRevisionError) |
Raman Tenneti | 993af5e | 2021-05-12 12:00:31 -0700 | [diff] [blame] | 32 | from wrapper import Wrapper |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 33 | |
| 34 | MANIFEST_FILE_NAME = 'manifest.xml' |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 35 | LOCAL_MANIFEST_NAME = 'local_manifest.xml' |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 36 | LOCAL_MANIFESTS_DIR_NAME = 'local_manifests' |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 37 | SUBMANIFEST_DIR = 'submanifests' |
| 38 | # Limit submanifests to an arbitrary depth for loop detection. |
| 39 | MAX_SUBMANIFEST_DEPTH = 8 |
LaMont Jones | b308db1 | 2022-02-25 17:05:21 +0000 | [diff] [blame] | 40 | # Add all projects from sub manifest into a group. |
| 41 | SUBMANIFEST_GROUP_PREFIX = 'submanifest:' |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 42 | |
Raman Tenneti | 78f4dd3 | 2021-06-07 13:27:37 -0700 | [diff] [blame] | 43 | # Add all projects from local manifest into a group. |
| 44 | LOCAL_MANIFEST_GROUP_PREFIX = 'local:' |
| 45 | |
Raman Tenneti | 993af5e | 2021-05-12 12:00:31 -0700 | [diff] [blame] | 46 | # ContactInfo has the self-registered bug url, supplied by the manifest authors. |
| 47 | ContactInfo = collections.namedtuple('ContactInfo', 'bugurl') |
| 48 | |
Anthony King | cb07ba7 | 2015-03-28 23:26:04 +0000 | [diff] [blame] | 49 | # urljoin gets confused if the scheme is not known. |
Joe Kilner | 6e31079 | 2016-10-27 15:53:53 -0700 | [diff] [blame] | 50 | urllib.parse.uses_relative.extend([ |
| 51 | 'ssh', |
| 52 | 'git', |
| 53 | 'persistent-https', |
| 54 | 'sso', |
| 55 | 'rpc']) |
| 56 | urllib.parse.uses_netloc.extend([ |
| 57 | 'ssh', |
| 58 | 'git', |
| 59 | 'persistent-https', |
| 60 | 'sso', |
| 61 | 'rpc']) |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 62 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 63 | |
Mike Frysinger | bb8ee7f | 2020-02-22 05:30:12 -0500 | [diff] [blame] | 64 | def XmlBool(node, attr, default=None): |
| 65 | """Determine boolean value of |node|'s |attr|. |
| 66 | |
| 67 | Invalid values will issue a non-fatal warning. |
| 68 | |
| 69 | Args: |
| 70 | node: XML node whose attributes we access. |
| 71 | attr: The attribute to access. |
| 72 | default: If the attribute is not set (value is empty), then use this. |
| 73 | |
| 74 | Returns: |
| 75 | True if the attribute is a valid string representing true. |
| 76 | False if the attribute is a valid string representing false. |
| 77 | |default| otherwise. |
| 78 | """ |
| 79 | value = node.getAttribute(attr) |
| 80 | s = value.lower() |
| 81 | if s == '': |
| 82 | return default |
| 83 | elif s in {'yes', 'true', '1'}: |
| 84 | return True |
| 85 | elif s in {'no', 'false', '0'}: |
| 86 | return False |
| 87 | else: |
| 88 | print('warning: manifest: %s="%s": ignoring invalid XML boolean' % |
| 89 | (attr, value), file=sys.stderr) |
| 90 | return default |
| 91 | |
| 92 | |
| 93 | def XmlInt(node, attr, default=None): |
| 94 | """Determine integer value of |node|'s |attr|. |
| 95 | |
| 96 | Args: |
| 97 | node: XML node whose attributes we access. |
| 98 | attr: The attribute to access. |
| 99 | default: If the attribute is not set (value is empty), then use this. |
| 100 | |
| 101 | Returns: |
| 102 | The number if the attribute is a valid number. |
| 103 | |
| 104 | Raises: |
| 105 | ManifestParseError: The number is invalid. |
| 106 | """ |
| 107 | value = node.getAttribute(attr) |
| 108 | if not value: |
| 109 | return default |
| 110 | |
| 111 | try: |
| 112 | return int(value) |
| 113 | except ValueError: |
| 114 | raise ManifestParseError('manifest: invalid %s="%s" integer' % |
| 115 | (attr, value)) |
| 116 | |
| 117 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 118 | class _Default(object): |
| 119 | """Project defaults within the manifest.""" |
| 120 | |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 121 | revisionExpr = None |
Conley Owens | b6a16e6 | 2013-09-25 15:06:09 -0700 | [diff] [blame] | 122 | destBranchExpr = None |
Nasser Grainawi | da40341 | 2018-05-04 12:53:29 -0600 | [diff] [blame] | 123 | upstreamExpr = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 124 | remote = None |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 125 | sync_j = 1 |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 126 | sync_c = False |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 127 | sync_s = False |
YOUNG HO CHA | a32c92c | 2018-02-14 16:57:31 +0900 | [diff] [blame] | 128 | sync_tags = True |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 129 | |
Julien Campergue | 7487992 | 2013-10-09 14:38:46 +0200 | [diff] [blame] | 130 | def __eq__(self, other): |
Jack Neus | 5ba2120 | 2021-06-09 15:21:25 +0000 | [diff] [blame] | 131 | if not isinstance(other, _Default): |
| 132 | return False |
Julien Campergue | 7487992 | 2013-10-09 14:38:46 +0200 | [diff] [blame] | 133 | return self.__dict__ == other.__dict__ |
| 134 | |
| 135 | def __ne__(self, other): |
Jack Neus | 5ba2120 | 2021-06-09 15:21:25 +0000 | [diff] [blame] | 136 | if not isinstance(other, _Default): |
| 137 | return True |
Julien Campergue | 7487992 | 2013-10-09 14:38:46 +0200 | [diff] [blame] | 138 | return self.__dict__ != other.__dict__ |
| 139 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 140 | |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 141 | class _XmlRemote(object): |
| 142 | def __init__(self, |
| 143 | name, |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 144 | alias=None, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 145 | fetch=None, |
Steve Rae | d648045 | 2016-08-10 15:00:00 -0700 | [diff] [blame] | 146 | pushUrl=None, |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 147 | manifestUrl=None, |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 148 | review=None, |
Jonathan Nieder | 9371979 | 2015-03-17 11:29:58 -0700 | [diff] [blame] | 149 | revision=None): |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 150 | self.name = name |
| 151 | self.fetchUrl = fetch |
Steve Rae | d648045 | 2016-08-10 15:00:00 -0700 | [diff] [blame] | 152 | self.pushUrl = pushUrl |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 153 | self.manifestUrl = manifestUrl |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 154 | self.remoteAlias = alias |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 155 | self.reviewUrl = review |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 156 | self.revision = revision |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 157 | self.resolvedFetchUrl = self._resolveFetchUrl() |
Jack Neus | 6ea0cae | 2021-07-20 20:52:33 +0000 | [diff] [blame] | 158 | self.annotations = [] |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 159 | |
David Pursehouse | 717ece9 | 2012-11-13 08:49:16 +0900 | [diff] [blame] | 160 | def __eq__(self, other): |
Jack Neus | 5ba2120 | 2021-06-09 15:21:25 +0000 | [diff] [blame] | 161 | if not isinstance(other, _XmlRemote): |
| 162 | return False |
Jack Neus | 6ea0cae | 2021-07-20 20:52:33 +0000 | [diff] [blame] | 163 | return (sorted(self.annotations) == sorted(other.annotations) and |
| 164 | self.name == other.name and self.fetchUrl == other.fetchUrl and |
| 165 | self.pushUrl == other.pushUrl and self.remoteAlias == other.remoteAlias |
| 166 | and self.reviewUrl == other.reviewUrl and self.revision == other.revision) |
David Pursehouse | 717ece9 | 2012-11-13 08:49:16 +0900 | [diff] [blame] | 167 | |
| 168 | def __ne__(self, other): |
Jack Neus | 6ea0cae | 2021-07-20 20:52:33 +0000 | [diff] [blame] | 169 | return not self.__eq__(other) |
David Pursehouse | 717ece9 | 2012-11-13 08:49:16 +0900 | [diff] [blame] | 170 | |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 171 | def _resolveFetchUrl(self): |
Jack Neus | 5ba2120 | 2021-06-09 15:21:25 +0000 | [diff] [blame] | 172 | if self.fetchUrl is None: |
| 173 | return '' |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 174 | url = self.fetchUrl.rstrip('/') |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 175 | manifestUrl = self.manifestUrl.rstrip('/') |
Conley Owens | 2d0f508 | 2014-01-31 15:03:51 -0800 | [diff] [blame] | 176 | # urljoin will gets confused over quite a few things. The ones we care |
| 177 | # about here are: |
| 178 | # * no scheme in the base url, like <hostname:port> |
Anthony King | cb07ba7 | 2015-03-28 23:26:04 +0000 | [diff] [blame] | 179 | # We handle no scheme by replacing it with an obscure protocol, gopher |
| 180 | # and then replacing it with the original when we are done. |
| 181 | |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 182 | if manifestUrl.find(':') != manifestUrl.find('/') - 1: |
Conley Owens | 4ccad75 | 2015-04-29 10:45:37 -0700 | [diff] [blame] | 183 | url = urllib.parse.urljoin('gopher://' + manifestUrl, url) |
| 184 | url = re.sub(r'^gopher://', '', url) |
Anthony King | cb07ba7 | 2015-03-28 23:26:04 +0000 | [diff] [blame] | 185 | else: |
| 186 | url = urllib.parse.urljoin(manifestUrl, url) |
Shawn Pearce | a9f11b3 | 2013-01-02 15:40:48 -0800 | [diff] [blame] | 187 | return url |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 188 | |
| 189 | def ToRemoteSpec(self, projectName): |
David Riley | e0684ad | 2017-04-05 00:02:59 -0700 | [diff] [blame] | 190 | fetchUrl = self.resolvedFetchUrl.rstrip('/') |
| 191 | url = fetchUrl + '/' + projectName |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 192 | remoteName = self.name |
Conley Owens | 1e7ab2a | 2013-10-08 17:26:57 -0700 | [diff] [blame] | 193 | if self.remoteAlias: |
David Pursehouse | 37128b6 | 2013-10-15 10:48:40 +0900 | [diff] [blame] | 194 | remoteName = self.remoteAlias |
Dan Willemsen | 96c2d65 | 2016-04-06 16:03:54 -0700 | [diff] [blame] | 195 | return RemoteSpec(remoteName, |
| 196 | url=url, |
Steve Rae | d648045 | 2016-08-10 15:00:00 -0700 | [diff] [blame] | 197 | pushUrl=self.pushUrl, |
Dan Willemsen | 96c2d65 | 2016-04-06 16:03:54 -0700 | [diff] [blame] | 198 | review=self.reviewUrl, |
David Riley | e0684ad | 2017-04-05 00:02:59 -0700 | [diff] [blame] | 199 | orig_name=self.name, |
| 200 | fetchUrl=self.fetchUrl) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 201 | |
Jack Neus | 6ea0cae | 2021-07-20 20:52:33 +0000 | [diff] [blame] | 202 | def AddAnnotation(self, name, value, keep): |
| 203 | self.annotations.append(Annotation(name, value, keep)) |
| 204 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 205 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 206 | class _XmlSubmanifest: |
| 207 | """Manage the <submanifest> element specified in the manifest. |
| 208 | |
| 209 | Attributes: |
| 210 | name: a string, the name for this submanifest. |
| 211 | remote: a string, the remote.name for this submanifest. |
| 212 | project: a string, the name of the manifest project. |
| 213 | revision: a string, the commitish. |
| 214 | manifestName: a string, the submanifest file name. |
| 215 | groups: a list of strings, the groups to add to all projects in the submanifest. |
| 216 | path: a string, the relative path for the submanifest checkout. |
| 217 | annotations: (derived) a list of annotations. |
| 218 | present: (derived) a boolean, whether the submanifest's manifest file is present. |
| 219 | """ |
| 220 | def __init__(self, |
| 221 | name, |
| 222 | remote=None, |
| 223 | project=None, |
| 224 | revision=None, |
| 225 | manifestName=None, |
| 226 | groups=None, |
| 227 | path=None, |
| 228 | parent=None): |
| 229 | self.name = name |
| 230 | self.remote = remote |
| 231 | self.project = project |
| 232 | self.revision = revision |
| 233 | self.manifestName = manifestName |
| 234 | self.groups = groups |
| 235 | self.path = path |
| 236 | self.annotations = [] |
| 237 | outer_client = parent._outer_client or parent |
| 238 | if self.remote and not self.project: |
| 239 | raise ManifestParseError( |
| 240 | f'Submanifest {name}: must specify project when remote is given.') |
LaMont Jones | 5d3291d | 2022-03-23 19:03:02 +0000 | [diff] [blame] | 241 | # Construct the absolute path to the manifest file using the parent's |
| 242 | # method, so that we can correctly create our repo_client. |
| 243 | manifestFile = parent.SubmanifestInfoDir( |
| 244 | os.path.join(parent.path_prefix, self.relpath), |
| 245 | os.path.join('manifests', manifestName or 'default.xml')) |
LaMont Jones | 55ee304 | 2022-04-06 17:10:21 +0000 | [diff] [blame^] | 246 | linkFile = parent.SubmanifestInfoDir( |
| 247 | os.path.join(parent.path_prefix, self.relpath), MANIFEST_FILE_NAME) |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 248 | rc = self.repo_client = RepoClient( |
LaMont Jones | 55ee304 | 2022-04-06 17:10:21 +0000 | [diff] [blame^] | 249 | parent.repodir, linkFile, parent_groups=','.join(groups) or '', |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 250 | submanifest_path=self.relpath, outer_client=outer_client) |
| 251 | |
LaMont Jones | 55ee304 | 2022-04-06 17:10:21 +0000 | [diff] [blame^] | 252 | self.present = os.path.exists(manifestFile) |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 253 | |
| 254 | def __eq__(self, other): |
| 255 | if not isinstance(other, _XmlSubmanifest): |
| 256 | return False |
| 257 | return ( |
| 258 | self.name == other.name and |
| 259 | self.remote == other.remote and |
| 260 | self.project == other.project and |
| 261 | self.revision == other.revision and |
| 262 | self.manifestName == other.manifestName and |
| 263 | self.groups == other.groups and |
| 264 | self.path == other.path and |
| 265 | sorted(self.annotations) == sorted(other.annotations)) |
| 266 | |
| 267 | def __ne__(self, other): |
| 268 | return not self.__eq__(other) |
| 269 | |
| 270 | def ToSubmanifestSpec(self, root): |
| 271 | """Return a SubmanifestSpec object, populating attributes""" |
| 272 | mp = root.manifestProject |
| 273 | remote = root.remotes[self.remote or root.default.remote.name] |
| 274 | # If a project was given, generate the url from the remote and project. |
| 275 | # If not, use this manifestProject's url. |
| 276 | if self.project: |
| 277 | manifestUrl = remote.ToRemoteSpec(self.project).url |
| 278 | else: |
| 279 | manifestUrl = mp.GetRemote(mp.remote.name).url |
| 280 | manifestName = self.manifestName or 'default.xml' |
| 281 | revision = self.revision or self.name |
| 282 | path = self.path or revision.split('/')[-1] |
| 283 | groups = self.groups or [] |
| 284 | |
| 285 | return SubmanifestSpec(self.name, manifestUrl, manifestName, revision, path, |
| 286 | groups) |
| 287 | |
| 288 | @property |
| 289 | def relpath(self): |
| 290 | """The path of this submanifest relative to the parent manifest.""" |
| 291 | revision = self.revision or self.name |
| 292 | return self.path or revision.split('/')[-1] |
| 293 | |
| 294 | def GetGroupsStr(self): |
| 295 | """Returns the `groups` given for this submanifest.""" |
| 296 | if self.groups: |
| 297 | return ','.join(self.groups) |
| 298 | return '' |
| 299 | |
| 300 | def AddAnnotation(self, name, value, keep): |
| 301 | """Add annotations to the submanifest.""" |
| 302 | self.annotations.append(Annotation(name, value, keep)) |
| 303 | |
| 304 | |
| 305 | class SubmanifestSpec: |
| 306 | """The submanifest element, with all fields expanded.""" |
| 307 | |
| 308 | def __init__(self, |
| 309 | name, |
| 310 | manifestUrl, |
| 311 | manifestName, |
| 312 | revision, |
| 313 | path, |
| 314 | groups): |
| 315 | self.name = name |
| 316 | self.manifestUrl = manifestUrl |
| 317 | self.manifestName = manifestName |
| 318 | self.revision = revision |
| 319 | self.path = path |
| 320 | self.groups = groups or [] |
| 321 | |
| 322 | |
Shawn O. Pearce | c8a300f | 2009-05-18 13:19:57 -0700 | [diff] [blame] | 323 | class XmlManifest(object): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 324 | """manages the repo configuration file""" |
| 325 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 326 | def __init__(self, repodir, manifest_file, local_manifests=None, |
| 327 | outer_client=None, parent_groups='', submanifest_path=''): |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 328 | """Initialize. |
| 329 | |
| 330 | Args: |
| 331 | repodir: Path to the .repo/ dir for holding all internal checkout state. |
| 332 | It must be in the top directory of the repo client checkout. |
| 333 | manifest_file: Full path to the manifest file to parse. This will usually |
| 334 | be |repodir|/|MANIFEST_FILE_NAME|. |
| 335 | local_manifests: Full path to the directory of local override manifests. |
| 336 | This will usually be |repodir|/|LOCAL_MANIFESTS_DIR_NAME|. |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 337 | outer_client: RepoClient of the outertree. |
| 338 | parent_groups: a string, the groups to apply to this projects. |
| 339 | submanifest_path: The submanifest root relative to the repo root. |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 340 | """ |
| 341 | # TODO(vapier): Move this out of this class. |
| 342 | self.globalConfig = GitConfig.ForUser() |
| 343 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 344 | self.repodir = os.path.abspath(repodir) |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 345 | self._CheckLocalPath(submanifest_path) |
| 346 | self.topdir = os.path.join(os.path.dirname(self.repodir), submanifest_path) |
LaMont Jones | 5d3291d | 2022-03-23 19:03:02 +0000 | [diff] [blame] | 347 | if manifest_file != os.path.abspath(manifest_file): |
| 348 | raise ManifestParseError('manifest_file must be abspath') |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 349 | self.manifestFile = manifest_file |
| 350 | self.local_manifests = local_manifests |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 351 | self._load_local_manifests = True |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 352 | self.parent_groups = parent_groups |
| 353 | |
| 354 | if outer_client and self.isGitcClient: |
| 355 | raise ManifestParseError('Multi-manifest is incompatible with `gitc-init`') |
| 356 | |
| 357 | if submanifest_path and not outer_client: |
| 358 | # If passing a submanifest_path, there must be an outer_client. |
| 359 | raise ManifestParseError(f'Bad call to {self.__class__.__name__}') |
| 360 | |
| 361 | # If self._outer_client is None, this is not a checkout that supports |
| 362 | # multi-tree. |
| 363 | self._outer_client = outer_client or self |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 364 | |
LaMont Jones | 9b72cf2 | 2022-03-29 21:54:22 +0000 | [diff] [blame] | 365 | self.repoProject = RepoProject(self, 'repo', |
David Pursehouse | abdf750 | 2020-02-12 14:58:39 +0900 | [diff] [blame] | 366 | gitdir=os.path.join(repodir, 'repo/.git'), |
| 367 | worktree=os.path.join(repodir, 'repo')) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 368 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 369 | mp = self.SubmanifestProject(self.path_prefix) |
Mike Frysinger | 979d5bd | 2020-02-09 02:28:34 -0500 | [diff] [blame] | 370 | self.manifestProject = mp |
| 371 | |
| 372 | # This is a bit hacky, but we're in a chicken & egg situation: all the |
| 373 | # normal repo settings live in the manifestProject which we just setup |
| 374 | # above, so we couldn't easily query before that. We assume Project() |
| 375 | # init doesn't care if this changes afterwards. |
LaMont Jones | d82be3e | 2022-04-05 19:30:46 +0000 | [diff] [blame] | 376 | if os.path.exists(mp.gitdir) and mp.use_worktree: |
Mike Frysinger | 979d5bd | 2020-02-09 02:28:34 -0500 | [diff] [blame] | 377 | mp.use_git_worktrees = True |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 378 | |
| 379 | self._Unload() |
| 380 | |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 381 | def Override(self, name, load_local_manifests=True): |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 382 | """Use a different manifest, just for the current instantiation. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 383 | """ |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 384 | path = None |
| 385 | |
| 386 | # Look for a manifest by path in the filesystem (including the cwd). |
| 387 | if not load_local_manifests: |
| 388 | local_path = os.path.abspath(name) |
| 389 | if os.path.isfile(local_path): |
| 390 | path = local_path |
| 391 | |
| 392 | # Look for manifests by name from the manifests repo. |
| 393 | if path is None: |
| 394 | path = os.path.join(self.manifestProject.worktree, name) |
| 395 | if not os.path.isfile(path): |
| 396 | raise ManifestParseError('manifest %s not found' % name) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 397 | |
| 398 | old = self.manifestFile |
| 399 | try: |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 400 | self._load_local_manifests = load_local_manifests |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 401 | self.manifestFile = path |
| 402 | self._Unload() |
| 403 | self._Load() |
| 404 | finally: |
| 405 | self.manifestFile = old |
| 406 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 407 | def Link(self, name): |
| 408 | """Update the repo metadata to use a different manifest. |
| 409 | """ |
| 410 | self.Override(name) |
| 411 | |
Mike Frysinger | a269b1c | 2020-02-21 00:49:41 -0500 | [diff] [blame] | 412 | # Old versions of repo would generate symlinks we need to clean up. |
Mike Frysinger | 9d96f58 | 2021-09-28 11:27:24 -0400 | [diff] [blame] | 413 | platform_utils.remove(self.manifestFile, missing_ok=True) |
Mike Frysinger | a269b1c | 2020-02-21 00:49:41 -0500 | [diff] [blame] | 414 | # This file is interpreted as if it existed inside the manifest repo. |
| 415 | # That allows us to use <include> with the relative file name. |
| 416 | with open(self.manifestFile, 'w') as fp: |
| 417 | fp.write("""<?xml version="1.0" encoding="UTF-8"?> |
| 418 | <!-- |
| 419 | DO NOT EDIT THIS FILE! It is generated by repo and changes will be discarded. |
| 420 | If you want to use a different manifest, use `repo init -m <file>` instead. |
| 421 | |
| 422 | If you want to customize your checkout by overriding manifest settings, use |
| 423 | the local_manifests/ directory instead. |
| 424 | |
| 425 | For more information on repo manifests, check out: |
| 426 | https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md |
| 427 | --> |
| 428 | <manifest> |
| 429 | <include name="%s" /> |
| 430 | </manifest> |
| 431 | """ % (name,)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 432 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 433 | def _RemoteToXml(self, r, doc, root): |
| 434 | e = doc.createElement('remote') |
| 435 | root.appendChild(e) |
| 436 | e.setAttribute('name', r.name) |
| 437 | e.setAttribute('fetch', r.fetchUrl) |
Steve Rae | d648045 | 2016-08-10 15:00:00 -0700 | [diff] [blame] | 438 | if r.pushUrl is not None: |
| 439 | e.setAttribute('pushurl', r.pushUrl) |
Conley Owens | 1e7ab2a | 2013-10-08 17:26:57 -0700 | [diff] [blame] | 440 | if r.remoteAlias is not None: |
| 441 | e.setAttribute('alias', r.remoteAlias) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 442 | if r.reviewUrl is not None: |
| 443 | e.setAttribute('review', r.reviewUrl) |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 444 | if r.revision is not None: |
| 445 | e.setAttribute('revision', r.revision) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 446 | |
Jack Neus | 6ea0cae | 2021-07-20 20:52:33 +0000 | [diff] [blame] | 447 | for a in r.annotations: |
| 448 | if a.keep == 'true': |
| 449 | ae = doc.createElement('annotation') |
| 450 | ae.setAttribute('name', a.name) |
| 451 | ae.setAttribute('value', a.value) |
| 452 | e.appendChild(ae) |
| 453 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 454 | def _SubmanifestToXml(self, r, doc, root): |
| 455 | """Generate XML <submanifest/> node.""" |
| 456 | e = doc.createElement('submanifest') |
| 457 | root.appendChild(e) |
| 458 | e.setAttribute('name', r.name) |
| 459 | if r.remote is not None: |
| 460 | e.setAttribute('remote', r.remote) |
| 461 | if r.project is not None: |
| 462 | e.setAttribute('project', r.project) |
| 463 | if r.manifestName is not None: |
| 464 | e.setAttribute('manifest-name', r.manifestName) |
| 465 | if r.revision is not None: |
| 466 | e.setAttribute('revision', r.revision) |
| 467 | if r.path is not None: |
| 468 | e.setAttribute('path', r.path) |
| 469 | if r.groups: |
| 470 | e.setAttribute('groups', r.GetGroupsStr()) |
| 471 | |
| 472 | for a in r.annotations: |
| 473 | if a.keep == 'true': |
| 474 | ae = doc.createElement('annotation') |
| 475 | ae.setAttribute('name', a.name) |
| 476 | ae.setAttribute('value', a.value) |
| 477 | e.appendChild(ae) |
| 478 | |
Mike Frysinger | 51e39d5 | 2020-12-04 05:32:06 -0500 | [diff] [blame] | 479 | def _ParseList(self, field): |
| 480 | """Parse fields that contain flattened lists. |
| 481 | |
| 482 | These are whitespace & comma separated. Empty elements will be discarded. |
| 483 | """ |
| 484 | return [x for x in re.split(r'[,\s]+', field) if x] |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 485 | |
Mike Frysinger | 23411d3 | 2020-09-02 04:31:10 -0400 | [diff] [blame] | 486 | def ToXml(self, peg_rev=False, peg_rev_upstream=True, peg_rev_dest_branch=True, groups=None): |
| 487 | """Return the current manifest XML.""" |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 488 | mp = self.manifestProject |
| 489 | |
Dan Willemsen | 5ea32d1 | 2015-09-08 13:27:20 -0700 | [diff] [blame] | 490 | if groups is None: |
LaMont Jones | d82be3e | 2022-04-05 19:30:46 +0000 | [diff] [blame] | 491 | groups = mp.manifest_groups |
Matt Gumbel | 0c635bb | 2012-12-21 10:14:53 -0800 | [diff] [blame] | 492 | if groups: |
Mike Frysinger | 51e39d5 | 2020-12-04 05:32:06 -0500 | [diff] [blame] | 493 | groups = self._ParseList(groups) |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 494 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 495 | doc = xml.dom.minidom.Document() |
| 496 | root = doc.createElement('manifest') |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 497 | if self.is_submanifest: |
| 498 | root.setAttribute('path', self.path_prefix) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 499 | doc.appendChild(root) |
| 500 | |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 501 | # Save out the notice. There's a little bit of work here to give it the |
| 502 | # right whitespace, which assumes that the notice is automatically indented |
| 503 | # by 4 by minidom. |
| 504 | if self.notice: |
| 505 | notice_element = root.appendChild(doc.createElement('notice')) |
| 506 | notice_lines = self.notice.splitlines() |
David Pursehouse | 54a4e60 | 2020-02-12 14:31:05 +0900 | [diff] [blame] | 507 | indented_notice = ('\n'.join(" " * 4 + line for line in notice_lines))[4:] |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 508 | notice_element.appendChild(doc.createTextNode(indented_notice)) |
| 509 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 510 | d = self.default |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 511 | |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 512 | for r in sorted(self.remotes): |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 513 | self._RemoteToXml(self.remotes[r], doc, root) |
| 514 | if self.remotes: |
| 515 | root.appendChild(doc.createTextNode('')) |
| 516 | |
| 517 | have_default = False |
| 518 | e = doc.createElement('default') |
| 519 | if d.remote: |
| 520 | have_default = True |
| 521 | e.setAttribute('remote', d.remote.name) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 522 | if d.revisionExpr: |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 523 | have_default = True |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 524 | e.setAttribute('revision', d.revisionExpr) |
Simon Ruggier | 7e59de2 | 2015-07-24 12:50:06 +0200 | [diff] [blame] | 525 | if d.destBranchExpr: |
| 526 | have_default = True |
| 527 | e.setAttribute('dest-branch', d.destBranchExpr) |
Nasser Grainawi | da40341 | 2018-05-04 12:53:29 -0600 | [diff] [blame] | 528 | if d.upstreamExpr: |
| 529 | have_default = True |
| 530 | e.setAttribute('upstream', d.upstreamExpr) |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 531 | if d.sync_j > 1: |
| 532 | have_default = True |
| 533 | e.setAttribute('sync-j', '%d' % d.sync_j) |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 534 | if d.sync_c: |
| 535 | have_default = True |
| 536 | e.setAttribute('sync-c', 'true') |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 537 | if d.sync_s: |
| 538 | have_default = True |
| 539 | e.setAttribute('sync-s', 'true') |
YOUNG HO CHA | a32c92c | 2018-02-14 16:57:31 +0900 | [diff] [blame] | 540 | if not d.sync_tags: |
| 541 | have_default = True |
| 542 | e.setAttribute('sync-tags', 'false') |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 543 | if have_default: |
| 544 | root.appendChild(e) |
| 545 | root.appendChild(doc.createTextNode('')) |
| 546 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 547 | if self._manifest_server: |
| 548 | e = doc.createElement('manifest-server') |
| 549 | e.setAttribute('url', self._manifest_server) |
| 550 | root.appendChild(e) |
| 551 | root.appendChild(doc.createTextNode('')) |
| 552 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 553 | for r in sorted(self.submanifests): |
| 554 | self._SubmanifestToXml(self.submanifests[r], doc, root) |
| 555 | if self.submanifests: |
| 556 | root.appendChild(doc.createTextNode('')) |
| 557 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 558 | def output_projects(parent, parent_node, projects): |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 559 | for project_name in projects: |
| 560 | for project in self._projects[project_name]: |
| 561 | output_project(parent, parent_node, project) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 562 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 563 | def output_project(parent, parent_node, p): |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 564 | if not p.MatchesGroups(groups): |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 565 | return |
| 566 | |
| 567 | name = p.name |
| 568 | relpath = p.relpath |
| 569 | if parent: |
| 570 | name = self._UnjoinName(parent.name, name) |
| 571 | relpath = self._UnjoinRelpath(parent.relpath, relpath) |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 572 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 573 | e = doc.createElement('project') |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 574 | parent_node.appendChild(e) |
| 575 | e.setAttribute('name', name) |
| 576 | if relpath != name: |
| 577 | e.setAttribute('path', relpath) |
Conley Owens | a17d7af | 2013-10-16 14:38:09 -0700 | [diff] [blame] | 578 | remoteName = None |
| 579 | if d.remote: |
Dan Willemsen | 96c2d65 | 2016-04-06 16:03:54 -0700 | [diff] [blame] | 580 | remoteName = d.remote.name |
| 581 | if not d.remote or p.remote.orig_name != remoteName: |
| 582 | remoteName = p.remote.orig_name |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 583 | e.setAttribute('remote', remoteName) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 584 | if peg_rev: |
| 585 | if self.IsMirror: |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 586 | value = p.bare_git.rev_parse(p.revisionExpr + '^0') |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 587 | else: |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 588 | value = p.work_git.rev_parse(HEAD + '^0') |
| 589 | e.setAttribute('revision', value) |
Conley Owens | 551dfec | 2015-07-10 14:54:54 -0700 | [diff] [blame] | 590 | if peg_rev_upstream: |
| 591 | if p.upstream: |
| 592 | e.setAttribute('upstream', p.upstream) |
| 593 | elif value != p.revisionExpr: |
| 594 | # Only save the origin if the origin is not a sha1, and the default |
| 595 | # isn't our value |
| 596 | e.setAttribute('upstream', p.revisionExpr) |
Sean McAllister | af908cb | 2020-04-20 08:41:58 -0600 | [diff] [blame] | 597 | |
| 598 | if peg_rev_dest_branch: |
| 599 | if p.dest_branch: |
| 600 | e.setAttribute('dest-branch', p.dest_branch) |
| 601 | elif value != p.revisionExpr: |
| 602 | e.setAttribute('dest-branch', p.revisionExpr) |
| 603 | |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 604 | else: |
Dan Willemsen | 96c2d65 | 2016-04-06 16:03:54 -0700 | [diff] [blame] | 605 | revision = self.remotes[p.remote.orig_name].revision or d.revisionExpr |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 606 | if not revision or revision != p.revisionExpr: |
| 607 | e.setAttribute('revision', p.revisionExpr) |
Raman Tenneti | b5c5a5e | 2021-02-06 09:44:15 -0800 | [diff] [blame] | 608 | elif p.revisionId: |
| 609 | e.setAttribute('revision', p.revisionId) |
Nasser Grainawi | da40341 | 2018-05-04 12:53:29 -0600 | [diff] [blame] | 610 | if (p.upstream and (p.upstream != p.revisionExpr or |
| 611 | p.upstream != d.upstreamExpr)): |
Mani Chandel | 7a91d51 | 2014-07-24 16:27:08 +0530 | [diff] [blame] | 612 | e.setAttribute('upstream', p.upstream) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 613 | |
Simon Ruggier | 7e59de2 | 2015-07-24 12:50:06 +0200 | [diff] [blame] | 614 | if p.dest_branch and p.dest_branch != d.destBranchExpr: |
| 615 | e.setAttribute('dest-branch', p.dest_branch) |
| 616 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 617 | for c in p.copyfiles: |
| 618 | ce = doc.createElement('copyfile') |
| 619 | ce.setAttribute('src', c.src) |
| 620 | ce.setAttribute('dest', c.dest) |
| 621 | e.appendChild(ce) |
| 622 | |
Jeff Hamilton | e0df232 | 2014-04-21 17:10:59 -0500 | [diff] [blame] | 623 | for l in p.linkfiles: |
| 624 | le = doc.createElement('linkfile') |
| 625 | le.setAttribute('src', l.src) |
| 626 | le.setAttribute('dest', l.dest) |
| 627 | e.appendChild(le) |
| 628 | |
Conley Owens | bb1b5f5 | 2012-08-13 13:11:18 -0700 | [diff] [blame] | 629 | default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath] |
Dmitry Fink | 17f85ea | 2012-08-06 14:52:29 -0700 | [diff] [blame] | 630 | 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] | 631 | if egroups: |
| 632 | e.setAttribute('groups', ','.join(egroups)) |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 633 | |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 634 | for a in p.annotations: |
| 635 | if a.keep == "true": |
| 636 | ae = doc.createElement('annotation') |
| 637 | ae.setAttribute('name', a.name) |
| 638 | ae.setAttribute('value', a.value) |
| 639 | e.appendChild(ae) |
| 640 | |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 641 | if p.sync_c: |
| 642 | e.setAttribute('sync-c', 'true') |
| 643 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 644 | if p.sync_s: |
| 645 | e.setAttribute('sync-s', 'true') |
| 646 | |
YOUNG HO CHA | a32c92c | 2018-02-14 16:57:31 +0900 | [diff] [blame] | 647 | if not p.sync_tags: |
| 648 | e.setAttribute('sync-tags', 'false') |
| 649 | |
Dan Willemsen | 8840922 | 2015-08-17 15:29:10 -0700 | [diff] [blame] | 650 | if p.clone_depth: |
| 651 | e.setAttribute('clone-depth', str(p.clone_depth)) |
| 652 | |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 653 | self._output_manifest_project_extras(p, e) |
| 654 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 655 | if p.subprojects: |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 656 | subprojects = set(subp.name for subp in p.subprojects) |
| 657 | output_projects(p, e, list(sorted(subprojects))) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 658 | |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 659 | projects = set(p.name for p in self._paths.values() if not p.parent) |
| 660 | output_projects(None, root, list(sorted(projects))) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 661 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 662 | if self._repo_hooks_project: |
| 663 | root.appendChild(doc.createTextNode('')) |
| 664 | e = doc.createElement('repo-hooks') |
| 665 | e.setAttribute('in-project', self._repo_hooks_project.name) |
| 666 | e.setAttribute('enabled-list', |
| 667 | ' '.join(self._repo_hooks_project.enabled_repo_hooks)) |
| 668 | root.appendChild(e) |
| 669 | |
Raman Tenneti | 1bb4fb2 | 2021-01-07 16:50:45 -0800 | [diff] [blame] | 670 | if self._superproject: |
| 671 | root.appendChild(doc.createTextNode('')) |
| 672 | e = doc.createElement('superproject') |
| 673 | e.setAttribute('name', self._superproject['name']) |
| 674 | remoteName = None |
| 675 | if d.remote: |
| 676 | remoteName = d.remote.name |
| 677 | remote = self._superproject.get('remote') |
| 678 | if not d.remote or remote.orig_name != remoteName: |
| 679 | remoteName = remote.orig_name |
| 680 | e.setAttribute('remote', remoteName) |
Xin Li | e0b16a2 | 2021-09-26 23:20:32 -0700 | [diff] [blame] | 681 | revision = remote.revision or d.revisionExpr |
| 682 | if not revision or revision != self._superproject['revision']: |
| 683 | e.setAttribute('revision', self._superproject['revision']) |
Raman Tenneti | 1bb4fb2 | 2021-01-07 16:50:45 -0800 | [diff] [blame] | 684 | root.appendChild(e) |
| 685 | |
Raman Tenneti | 993af5e | 2021-05-12 12:00:31 -0700 | [diff] [blame] | 686 | if self._contactinfo.bugurl != Wrapper().BUG_URL: |
Raman Tenneti | 1c3f57e | 2021-05-04 12:32:13 -0700 | [diff] [blame] | 687 | root.appendChild(doc.createTextNode('')) |
| 688 | e = doc.createElement('contactinfo') |
Raman Tenneti | 993af5e | 2021-05-12 12:00:31 -0700 | [diff] [blame] | 689 | e.setAttribute('bugurl', self._contactinfo.bugurl) |
Raman Tenneti | 1c3f57e | 2021-05-04 12:32:13 -0700 | [diff] [blame] | 690 | root.appendChild(e) |
| 691 | |
Mike Frysinger | 23411d3 | 2020-09-02 04:31:10 -0400 | [diff] [blame] | 692 | return doc |
| 693 | |
| 694 | def ToDict(self, **kwargs): |
| 695 | """Return the current manifest as a dictionary.""" |
| 696 | # Elements that may only appear once. |
| 697 | SINGLE_ELEMENTS = { |
| 698 | 'notice', |
| 699 | 'default', |
| 700 | 'manifest-server', |
| 701 | 'repo-hooks', |
Raman Tenneti | 1bb4fb2 | 2021-01-07 16:50:45 -0800 | [diff] [blame] | 702 | 'superproject', |
Raman Tenneti | 1c3f57e | 2021-05-04 12:32:13 -0700 | [diff] [blame] | 703 | 'contactinfo', |
Mike Frysinger | 23411d3 | 2020-09-02 04:31:10 -0400 | [diff] [blame] | 704 | } |
| 705 | # Elements that may be repeated. |
| 706 | MULTI_ELEMENTS = { |
| 707 | 'remote', |
| 708 | 'remove-project', |
| 709 | 'project', |
| 710 | 'extend-project', |
| 711 | 'include', |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 712 | 'submanifest', |
Mike Frysinger | 23411d3 | 2020-09-02 04:31:10 -0400 | [diff] [blame] | 713 | # These are children of 'project' nodes. |
| 714 | 'annotation', |
| 715 | 'project', |
| 716 | 'copyfile', |
| 717 | 'linkfile', |
| 718 | } |
| 719 | |
| 720 | doc = self.ToXml(**kwargs) |
| 721 | ret = {} |
| 722 | |
| 723 | def append_children(ret, node): |
| 724 | for child in node.childNodes: |
| 725 | if child.nodeType == xml.dom.Node.ELEMENT_NODE: |
| 726 | attrs = child.attributes |
| 727 | element = dict((attrs.item(i).localName, attrs.item(i).value) |
| 728 | for i in range(attrs.length)) |
| 729 | if child.nodeName in SINGLE_ELEMENTS: |
| 730 | ret[child.nodeName] = element |
| 731 | elif child.nodeName in MULTI_ELEMENTS: |
| 732 | ret.setdefault(child.nodeName, []).append(element) |
| 733 | else: |
| 734 | raise ManifestParseError('Unhandled element "%s"' % (child.nodeName,)) |
| 735 | |
| 736 | append_children(element, child) |
| 737 | |
| 738 | append_children(ret, doc.firstChild) |
| 739 | |
| 740 | return ret |
| 741 | |
| 742 | def Save(self, fd, **kwargs): |
| 743 | """Write the current manifest out to the given file descriptor.""" |
| 744 | doc = self.ToXml(**kwargs) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 745 | doc.writexml(fd, '', ' ', '\n', 'UTF-8') |
| 746 | |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 747 | def _output_manifest_project_extras(self, p, e): |
| 748 | """Manifests can modify e if they support extra project attributes.""" |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 749 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 750 | @property |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 751 | def is_multimanifest(self): |
| 752 | """Whether this is a multimanifest checkout""" |
| 753 | return bool(self.outer_client.submanifests) |
| 754 | |
| 755 | @property |
| 756 | def is_submanifest(self): |
| 757 | """Whether this manifest is a submanifest""" |
| 758 | return self._outer_client and self._outer_client != self |
| 759 | |
| 760 | @property |
| 761 | def outer_client(self): |
| 762 | """The instance of the outermost manifest client""" |
| 763 | self._Load() |
| 764 | return self._outer_client |
| 765 | |
| 766 | @property |
| 767 | def all_manifests(self): |
| 768 | """Generator yielding all (sub)manifests.""" |
| 769 | self._Load() |
| 770 | outer = self._outer_client |
| 771 | yield outer |
| 772 | for tree in outer.all_children: |
| 773 | yield tree |
| 774 | |
| 775 | @property |
| 776 | def all_children(self): |
| 777 | """Generator yielding all child submanifests.""" |
| 778 | self._Load() |
| 779 | for child in self._submanifests.values(): |
| 780 | if child.repo_client: |
| 781 | yield child.repo_client |
| 782 | for tree in child.repo_client.all_children: |
| 783 | yield tree |
| 784 | |
| 785 | @property |
| 786 | def path_prefix(self): |
| 787 | """The path of this submanifest, relative to the outermost manifest.""" |
| 788 | if not self._outer_client or self == self._outer_client: |
| 789 | return '' |
| 790 | return os.path.relpath(self.topdir, self._outer_client.topdir) |
| 791 | |
| 792 | @property |
| 793 | def all_paths(self): |
| 794 | """All project paths for all (sub)manifests. See `paths`.""" |
| 795 | ret = {} |
| 796 | for tree in self.all_manifests: |
| 797 | prefix = tree.path_prefix |
| 798 | ret.update({os.path.join(prefix, k): v for k, v in tree.paths.items()}) |
| 799 | return ret |
| 800 | |
| 801 | @property |
| 802 | def all_projects(self): |
| 803 | """All projects for all (sub)manifests. See `projects`.""" |
| 804 | return list(itertools.chain.from_iterable(x._paths.values() for x in self.all_manifests)) |
| 805 | |
| 806 | @property |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 807 | def paths(self): |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 808 | """Return all paths for this manifest. |
| 809 | |
| 810 | Return: |
| 811 | A dictionary of {path: Project()}. `path` is relative to this manifest. |
| 812 | """ |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 813 | self._Load() |
| 814 | return self._paths |
| 815 | |
| 816 | @property |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 817 | def projects(self): |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 818 | """Return a list of all Projects in this manifest.""" |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 819 | self._Load() |
Anthony King | d58bfe5 | 2014-05-05 23:30:49 +0100 | [diff] [blame] | 820 | return list(self._paths.values()) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 821 | |
| 822 | @property |
| 823 | def remotes(self): |
| 824 | self._Load() |
| 825 | return self._remotes |
| 826 | |
| 827 | @property |
| 828 | def default(self): |
| 829 | self._Load() |
| 830 | return self._default |
| 831 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 832 | @property |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 833 | def submanifests(self): |
| 834 | """All submanifests in this manifest.""" |
| 835 | self._Load() |
| 836 | return self._submanifests |
| 837 | |
| 838 | @property |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 839 | def repo_hooks_project(self): |
| 840 | self._Load() |
| 841 | return self._repo_hooks_project |
| 842 | |
| 843 | @property |
Raman Tenneti | 1bb4fb2 | 2021-01-07 16:50:45 -0800 | [diff] [blame] | 844 | def superproject(self): |
| 845 | self._Load() |
| 846 | return self._superproject |
| 847 | |
| 848 | @property |
Raman Tenneti | 1c3f57e | 2021-05-04 12:32:13 -0700 | [diff] [blame] | 849 | def contactinfo(self): |
| 850 | self._Load() |
| 851 | return self._contactinfo |
| 852 | |
| 853 | @property |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 854 | def notice(self): |
| 855 | self._Load() |
| 856 | return self._notice |
| 857 | |
| 858 | @property |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 859 | def manifest_server(self): |
| 860 | self._Load() |
Shawn O. Pearce | 34fb20f | 2011-11-30 13:41:02 -0800 | [diff] [blame] | 861 | return self._manifest_server |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 862 | |
| 863 | @property |
Xin Li | d79a4bc | 2020-05-20 16:03:45 -0700 | [diff] [blame] | 864 | def CloneBundle(self): |
LaMont Jones | d82be3e | 2022-04-05 19:30:46 +0000 | [diff] [blame] | 865 | clone_bundle = self.manifestProject.clone_bundle |
Xin Li | d79a4bc | 2020-05-20 16:03:45 -0700 | [diff] [blame] | 866 | if clone_bundle is None: |
LaMont Jones | d82be3e | 2022-04-05 19:30:46 +0000 | [diff] [blame] | 867 | return False if self.manifestProject.partial_clone else True |
Xin Li | d79a4bc | 2020-05-20 16:03:45 -0700 | [diff] [blame] | 868 | else: |
| 869 | return clone_bundle |
| 870 | |
| 871 | @property |
Xin Li | 745be2e | 2019-06-03 11:24:30 -0700 | [diff] [blame] | 872 | def CloneFilter(self): |
LaMont Jones | d82be3e | 2022-04-05 19:30:46 +0000 | [diff] [blame] | 873 | if self.manifestProject.partial_clone: |
| 874 | return self.manifestProject.clone_filter |
Xin Li | 745be2e | 2019-06-03 11:24:30 -0700 | [diff] [blame] | 875 | return None |
| 876 | |
| 877 | @property |
Raman Tenneti | f32f243 | 2021-04-12 20:57:25 -0700 | [diff] [blame] | 878 | def PartialCloneExclude(self): |
LaMont Jones | d82be3e | 2022-04-05 19:30:46 +0000 | [diff] [blame] | 879 | exclude = self.manifest.manifestProject.partial_clone_exclude or '' |
Raman Tenneti | f32f243 | 2021-04-12 20:57:25 -0700 | [diff] [blame] | 880 | return set(x.strip() for x in exclude.split(',')) |
| 881 | |
| 882 | @property |
Michael Kelly | c34b91c | 2021-07-02 09:25:48 -0700 | [diff] [blame] | 883 | def UseLocalManifests(self): |
| 884 | return self._load_local_manifests |
| 885 | |
| 886 | def SetUseLocalManifests(self, value): |
| 887 | self._load_local_manifests = value |
| 888 | |
| 889 | @property |
Raman Tenneti | feb2891 | 2021-05-02 19:47:29 -0700 | [diff] [blame] | 890 | def HasLocalManifests(self): |
| 891 | return self._load_local_manifests and self.local_manifests |
| 892 | |
LaMont Jones | 87cce68 | 2022-02-14 17:48:31 +0000 | [diff] [blame] | 893 | def IsFromLocalManifest(self, project): |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 894 | """Is the project from a local manifest?""" |
LaMont Jones | 87cce68 | 2022-02-14 17:48:31 +0000 | [diff] [blame] | 895 | return any(x.startswith(LOCAL_MANIFEST_GROUP_PREFIX) |
| 896 | for x in project.groups) |
| 897 | |
Raman Tenneti | feb2891 | 2021-05-02 19:47:29 -0700 | [diff] [blame] | 898 | @property |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 899 | def IsMirror(self): |
LaMont Jones | d82be3e | 2022-04-05 19:30:46 +0000 | [diff] [blame] | 900 | return self.manifestProject.mirror |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 901 | |
Julien Campergue | 335f5ef | 2013-10-16 11:02:35 +0200 | [diff] [blame] | 902 | @property |
Mike Frysinger | 979d5bd | 2020-02-09 02:28:34 -0500 | [diff] [blame] | 903 | def UseGitWorktrees(self): |
LaMont Jones | d82be3e | 2022-04-05 19:30:46 +0000 | [diff] [blame] | 904 | return self.manifestProject.use_worktree |
Mike Frysinger | 979d5bd | 2020-02-09 02:28:34 -0500 | [diff] [blame] | 905 | |
| 906 | @property |
Julien Campergue | 335f5ef | 2013-10-16 11:02:35 +0200 | [diff] [blame] | 907 | def IsArchive(self): |
LaMont Jones | d82be3e | 2022-04-05 19:30:46 +0000 | [diff] [blame] | 908 | return self.manifestProject.archive |
Julien Campergue | 335f5ef | 2013-10-16 11:02:35 +0200 | [diff] [blame] | 909 | |
Martin Kelly | e4e94d2 | 2017-03-21 16:05:12 -0700 | [diff] [blame] | 910 | @property |
| 911 | def HasSubmodules(self): |
LaMont Jones | d82be3e | 2022-04-05 19:30:46 +0000 | [diff] [blame] | 912 | return self.manifestProject.submodules |
Martin Kelly | e4e94d2 | 2017-03-21 16:05:12 -0700 | [diff] [blame] | 913 | |
XD Trol | 630876f | 2022-01-17 23:29:04 +0800 | [diff] [blame] | 914 | @property |
| 915 | def EnableGitLfs(self): |
LaMont Jones | d82be3e | 2022-04-05 19:30:46 +0000 | [diff] [blame] | 916 | return self.manifestProject.git_lfs |
XD Trol | 630876f | 2022-01-17 23:29:04 +0800 | [diff] [blame] | 917 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 918 | def FindManifestByPath(self, path): |
| 919 | """Returns the manifest containing path.""" |
| 920 | path = os.path.abspath(path) |
| 921 | manifest = self._outer_client or self |
| 922 | old = None |
| 923 | while manifest._submanifests and manifest != old: |
| 924 | old = manifest |
| 925 | for name in manifest._submanifests: |
| 926 | tree = manifest._submanifests[name] |
| 927 | if path.startswith(tree.repo_client.manifest.topdir): |
| 928 | manifest = tree.repo_client |
| 929 | break |
| 930 | return manifest |
| 931 | |
| 932 | @property |
| 933 | def subdir(self): |
| 934 | """Returns the path for per-submanifest objects for this manifest.""" |
| 935 | return self.SubmanifestInfoDir(self.path_prefix) |
| 936 | |
| 937 | def SubmanifestInfoDir(self, submanifest_path, object_path=''): |
| 938 | """Return the path to submanifest-specific info for a submanifest. |
| 939 | |
| 940 | Return the full path of the directory in which to put per-manifest objects. |
| 941 | |
| 942 | Args: |
| 943 | submanifest_path: a string, the path of the submanifest, relative to the |
| 944 | outermost topdir. If empty, then repodir is returned. |
| 945 | object_path: a string, relative path to append to the submanifest info |
| 946 | directory path. |
| 947 | """ |
| 948 | if submanifest_path: |
| 949 | return os.path.join(self.repodir, SUBMANIFEST_DIR, submanifest_path, |
| 950 | object_path) |
| 951 | else: |
| 952 | return os.path.join(self.repodir, object_path) |
| 953 | |
| 954 | def SubmanifestProject(self, submanifest_path): |
| 955 | """Return a manifestProject for a submanifest.""" |
| 956 | subdir = self.SubmanifestInfoDir(submanifest_path) |
LaMont Jones | 9b72cf2 | 2022-03-29 21:54:22 +0000 | [diff] [blame] | 957 | mp = ManifestProject(self, 'manifests', |
| 958 | gitdir=os.path.join(subdir, 'manifests.git'), |
| 959 | worktree=os.path.join(subdir, 'manifests')) |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 960 | return mp |
| 961 | |
Raman Tenneti | 080877e | 2021-03-09 15:19:06 -0800 | [diff] [blame] | 962 | def GetDefaultGroupsStr(self): |
| 963 | """Returns the default group string for the platform.""" |
| 964 | return 'default,platform-' + platform.system().lower() |
| 965 | |
| 966 | def GetGroupsStr(self): |
| 967 | """Returns the manifest group string that should be synced.""" |
LaMont Jones | d82be3e | 2022-04-05 19:30:46 +0000 | [diff] [blame] | 968 | groups = self.manifestProject.manifest_groups |
Raman Tenneti | 080877e | 2021-03-09 15:19:06 -0800 | [diff] [blame] | 969 | if not groups: |
| 970 | groups = self.GetDefaultGroupsStr() |
| 971 | return groups |
| 972 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 973 | def _Unload(self): |
| 974 | self._loaded = False |
| 975 | self._projects = {} |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 976 | self._paths = {} |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 977 | self._remotes = {} |
| 978 | self._default = None |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 979 | self._submanifests = {} |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 980 | self._repo_hooks_project = None |
Raman Tenneti | 1bb4fb2 | 2021-01-07 16:50:45 -0800 | [diff] [blame] | 981 | self._superproject = {} |
Raman Tenneti | 993af5e | 2021-05-12 12:00:31 -0700 | [diff] [blame] | 982 | self._contactinfo = ContactInfo(Wrapper().BUG_URL) |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 983 | self._notice = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 984 | self.branch = None |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 985 | self._manifest_server = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 986 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 987 | def _Load(self, initial_client=None, submanifest_depth=0): |
| 988 | if submanifest_depth > MAX_SUBMANIFEST_DEPTH: |
| 989 | raise ManifestParseError('maximum submanifest depth %d exceeded.' % |
| 990 | MAX_SUBMANIFEST_DEPTH) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 991 | if not self._loaded: |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 992 | if self._outer_client and self._outer_client != self: |
| 993 | # This will load all clients. |
| 994 | self._outer_client._Load(initial_client=self) |
| 995 | |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 996 | m = self.manifestProject |
| 997 | b = m.GetBranch(m.CurrentBranch).merge |
Shawn O. Pearce | 21c5c34 | 2009-06-25 16:47:30 -0700 | [diff] [blame] | 998 | if b is not None and b.startswith(R_HEADS): |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 999 | b = b[len(R_HEADS):] |
| 1000 | self.branch = b |
| 1001 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1002 | parent_groups = self.parent_groups |
LaMont Jones | b308db1 | 2022-02-25 17:05:21 +0000 | [diff] [blame] | 1003 | if self.path_prefix: |
| 1004 | parent_groups = f'{SUBMANIFEST_GROUP_PREFIX}:path:{self.path_prefix},{parent_groups}' |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1005 | |
Mike Frysinger | 5413397 | 2021-03-01 21:38:08 -0500 | [diff] [blame] | 1006 | # The manifestFile was specified by the user which is why we allow include |
| 1007 | # paths to point anywhere. |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 1008 | nodes = [] |
Mike Frysinger | 5413397 | 2021-03-01 21:38:08 -0500 | [diff] [blame] | 1009 | nodes.append(self._ParseManifestXml( |
| 1010 | self.manifestFile, self.manifestProject.worktree, |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1011 | parent_groups=parent_groups, restrict_includes=False)) |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 1012 | |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 1013 | if self._load_local_manifests and self.local_manifests: |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 1014 | try: |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 1015 | for local_file in sorted(platform_utils.listdir(self.local_manifests)): |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 1016 | if local_file.endswith('.xml'): |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 1017 | local = os.path.join(self.local_manifests, local_file) |
Mike Frysinger | 5413397 | 2021-03-01 21:38:08 -0500 | [diff] [blame] | 1018 | # Since local manifests are entirely managed by the user, allow |
| 1019 | # them to point anywhere the user wants. |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1020 | local_group = f'{LOCAL_MANIFEST_GROUP_PREFIX}:{local_file[:-4]}' |
Mike Frysinger | 5413397 | 2021-03-01 21:38:08 -0500 | [diff] [blame] | 1021 | nodes.append(self._ParseManifestXml( |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1022 | local, self.subdir, |
| 1023 | parent_groups=f'{local_group},{parent_groups}', |
Raman Tenneti | 78f4dd3 | 2021-06-07 13:27:37 -0700 | [diff] [blame] | 1024 | restrict_includes=False)) |
Basil Gello | c745350 | 2018-05-25 20:23:52 +0300 | [diff] [blame] | 1025 | except OSError: |
| 1026 | pass |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 1027 | |
Joe Onorato | 26e2475 | 2013-01-11 12:35:53 -0800 | [diff] [blame] | 1028 | try: |
| 1029 | self._ParseManifest(nodes) |
| 1030 | except ManifestParseError as e: |
| 1031 | # There was a problem parsing, unload ourselves in case they catch |
| 1032 | # this error and try again later, we will show the correct error |
| 1033 | self._Unload() |
| 1034 | raise e |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 1035 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 1036 | if self.IsMirror: |
| 1037 | self._AddMetaProjectMirror(self.repoProject) |
| 1038 | self._AddMetaProjectMirror(self.manifestProject) |
| 1039 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1040 | self._loaded = True |
| 1041 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1042 | # Now that we have loaded this manifest, load any submanifest manifests |
| 1043 | # as well. We need to do this after self._loaded is set to avoid looping. |
| 1044 | if self._outer_client: |
| 1045 | for name in self._submanifests: |
| 1046 | tree = self._submanifests[name] |
| 1047 | spec = tree.ToSubmanifestSpec(self) |
| 1048 | present = os.path.exists(os.path.join(self.subdir, MANIFEST_FILE_NAME)) |
| 1049 | if present and tree.present and not tree.repo_client: |
| 1050 | if initial_client and initial_client.topdir == self.topdir: |
| 1051 | tree.repo_client = self |
| 1052 | tree.present = present |
| 1053 | elif not os.path.exists(self.subdir): |
| 1054 | tree.present = False |
LaMont Jones | 55ee304 | 2022-04-06 17:10:21 +0000 | [diff] [blame^] | 1055 | if present and tree.present: |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1056 | tree.repo_client._Load(initial_client=initial_client, |
| 1057 | submanifest_depth=submanifest_depth + 1) |
| 1058 | |
Mike Frysinger | 5413397 | 2021-03-01 21:38:08 -0500 | [diff] [blame] | 1059 | def _ParseManifestXml(self, path, include_root, parent_groups='', |
| 1060 | restrict_includes=True): |
| 1061 | """Parse a manifest XML and return the computed nodes. |
| 1062 | |
| 1063 | Args: |
| 1064 | path: The XML file to read & parse. |
| 1065 | include_root: The path to interpret include "name"s relative to. |
| 1066 | parent_groups: The groups to apply to this projects. |
| 1067 | restrict_includes: Whether to constrain the "name" attribute of includes. |
| 1068 | |
| 1069 | Returns: |
| 1070 | List of XML nodes. |
| 1071 | """ |
David Pursehouse | f7fc8a9 | 2012-11-13 04:00:28 +0900 | [diff] [blame] | 1072 | try: |
| 1073 | root = xml.dom.minidom.parse(path) |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 1074 | except (OSError, xml.parsers.expat.ExpatError) as e: |
David Pursehouse | f7fc8a9 | 2012-11-13 04:00:28 +0900 | [diff] [blame] | 1075 | raise ManifestParseError("error parsing manifest %s: %s" % (path, e)) |
| 1076 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1077 | if not root or not root.childNodes: |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 1078 | raise ManifestParseError("no root node in %s" % (path,)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1079 | |
Jooncheol Park | 34acdd2 | 2012-08-27 02:25:59 +0900 | [diff] [blame] | 1080 | for manifest in root.childNodes: |
| 1081 | if manifest.nodeName == 'manifest': |
| 1082 | break |
| 1083 | else: |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 1084 | raise ManifestParseError("no <manifest> in %s" % (path,)) |
| 1085 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 1086 | nodes = [] |
David Pursehouse | 65b0ba5 | 2018-06-24 16:21:51 +0900 | [diff] [blame] | 1087 | for node in manifest.childNodes: |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 1088 | if node.nodeName == 'include': |
| 1089 | name = self._reqatt(node, 'name') |
Mike Frysinger | 5413397 | 2021-03-01 21:38:08 -0500 | [diff] [blame] | 1090 | if restrict_includes: |
| 1091 | msg = self._CheckLocalPath(name) |
| 1092 | if msg: |
| 1093 | raise ManifestInvalidPathError( |
| 1094 | '<include> invalid "name": %s: %s' % (name, msg)) |
Fredrik de Groot | 352c93b | 2020-10-06 12:55:14 +0200 | [diff] [blame] | 1095 | include_groups = '' |
| 1096 | if parent_groups: |
| 1097 | include_groups = parent_groups |
| 1098 | if node.hasAttribute('groups'): |
| 1099 | include_groups = node.getAttribute('groups') + ',' + include_groups |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 1100 | fp = os.path.join(include_root, name) |
| 1101 | if not os.path.isfile(fp): |
Mike Frysinger | 5413397 | 2021-03-01 21:38:08 -0500 | [diff] [blame] | 1102 | raise ManifestParseError("include [%s/]%s doesn't exist or isn't a file" |
| 1103 | % (include_root, name)) |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 1104 | try: |
Fredrik de Groot | 352c93b | 2020-10-06 12:55:14 +0200 | [diff] [blame] | 1105 | nodes.extend(self._ParseManifestXml(fp, include_root, include_groups)) |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 1106 | # should isolate this to the exact exception, but that's |
| 1107 | # tricky. actual parsing implementation may vary. |
Mike Frysinger | 5413397 | 2021-03-01 21:38:08 -0500 | [diff] [blame] | 1108 | except (KeyboardInterrupt, RuntimeError, SystemExit, ManifestParseError): |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 1109 | raise |
| 1110 | except Exception as e: |
| 1111 | raise ManifestParseError( |
Mike Frysinger | ec558df | 2019-07-05 01:38:05 -0400 | [diff] [blame] | 1112 | "failed parsing included manifest %s: %s" % (name, e)) |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 1113 | else: |
Fredrik de Groot | 352c93b | 2020-10-06 12:55:14 +0200 | [diff] [blame] | 1114 | if parent_groups and node.nodeName == 'project': |
| 1115 | nodeGroups = parent_groups |
| 1116 | if node.hasAttribute('groups'): |
| 1117 | nodeGroups = node.getAttribute('groups') + ',' + nodeGroups |
| 1118 | node.setAttribute('groups', nodeGroups) |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 1119 | nodes.append(node) |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 1120 | return nodes |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 1121 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 1122 | def _ParseManifest(self, node_list): |
| 1123 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1124 | if node.nodeName == 'remote': |
| 1125 | remote = self._ParseRemote(node) |
David Pursehouse | 717ece9 | 2012-11-13 08:49:16 +0900 | [diff] [blame] | 1126 | if remote: |
| 1127 | if remote.name in self._remotes: |
| 1128 | if remote != self._remotes[remote.name]: |
| 1129 | raise ManifestParseError( |
| 1130 | 'remote %s already exists with different attributes' % |
| 1131 | (remote.name)) |
| 1132 | else: |
| 1133 | self._remotes[remote.name] = remote |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1134 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 1135 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1136 | if node.nodeName == 'default': |
Julien Campergue | 7487992 | 2013-10-09 14:38:46 +0200 | [diff] [blame] | 1137 | new_default = self._ParseDefault(node) |
Jack Neus | b8c8448 | 2021-06-15 14:28:30 +0000 | [diff] [blame] | 1138 | emptyDefault = not node.hasAttributes() and not node.hasChildNodes() |
Julien Campergue | 7487992 | 2013-10-09 14:38:46 +0200 | [diff] [blame] | 1139 | if self._default is None: |
| 1140 | self._default = new_default |
Jack Neus | b8c8448 | 2021-06-15 14:28:30 +0000 | [diff] [blame] | 1141 | elif not emptyDefault and new_default != self._default: |
David Pursehouse | 37128b6 | 2013-10-15 10:48:40 +0900 | [diff] [blame] | 1142 | raise ManifestParseError('duplicate default in %s' % |
| 1143 | (self.manifestFile)) |
Julien Campergue | 7487992 | 2013-10-09 14:38:46 +0200 | [diff] [blame] | 1144 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1145 | if self._default is None: |
| 1146 | self._default = _Default() |
| 1147 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1148 | submanifest_paths = set() |
| 1149 | for node in itertools.chain(*node_list): |
| 1150 | if node.nodeName == 'submanifest': |
| 1151 | submanifest = self._ParseSubmanifest(node) |
| 1152 | if submanifest: |
| 1153 | if submanifest.name in self._submanifests: |
| 1154 | if submanifest != self._submanifests[submanifest.name]: |
| 1155 | raise ManifestParseError( |
| 1156 | 'submanifest %s already exists with different attributes' % |
| 1157 | (submanifest.name)) |
| 1158 | else: |
| 1159 | self._submanifests[submanifest.name] = submanifest |
| 1160 | submanifest_paths.add(submanifest.relpath) |
| 1161 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 1162 | for node in itertools.chain(*node_list): |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 1163 | if node.nodeName == 'notice': |
| 1164 | if self._notice is not None: |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 1165 | raise ManifestParseError( |
| 1166 | 'duplicate notice in %s' % |
| 1167 | (self.manifestFile)) |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 1168 | self._notice = self._ParseNotice(node) |
| 1169 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 1170 | for node in itertools.chain(*node_list): |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 1171 | if node.nodeName == 'manifest-server': |
| 1172 | url = self._reqatt(node, 'url') |
| 1173 | if self._manifest_server is not None: |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 1174 | raise ManifestParseError( |
| 1175 | 'duplicate manifest-server in %s' % |
| 1176 | (self.manifestFile)) |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 1177 | self._manifest_server = url |
| 1178 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1179 | def recursively_add_projects(project): |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 1180 | projects = self._projects.setdefault(project.name, []) |
| 1181 | if project.relpath is None: |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1182 | raise ManifestParseError( |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 1183 | 'missing path for %s in %s' % |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1184 | (project.name, self.manifestFile)) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 1185 | if project.relpath in self._paths: |
| 1186 | raise ManifestParseError( |
| 1187 | 'duplicate path %s in %s' % |
| 1188 | (project.relpath, self.manifestFile)) |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1189 | for tree in submanifest_paths: |
| 1190 | if project.relpath.startswith(tree): |
| 1191 | raise ManifestParseError( |
| 1192 | 'project %s conflicts with submanifest path %s' % |
| 1193 | (project.relpath, tree)) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 1194 | self._paths[project.relpath] = project |
| 1195 | projects.append(project) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1196 | for subproject in project.subprojects: |
| 1197 | recursively_add_projects(subproject) |
| 1198 | |
Jack Neus | a84f43a | 2021-09-21 22:23:55 +0000 | [diff] [blame] | 1199 | repo_hooks_project = None |
| 1200 | enabled_repo_hooks = None |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 1201 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1202 | if node.nodeName == 'project': |
| 1203 | project = self._ParseProject(node) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1204 | recursively_add_projects(project) |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 1205 | if node.nodeName == 'extend-project': |
| 1206 | name = self._reqatt(node, 'name') |
| 1207 | |
| 1208 | if name not in self._projects: |
| 1209 | raise ManifestParseError('extend-project element specifies non-existent ' |
| 1210 | 'project: %s' % name) |
| 1211 | |
| 1212 | path = node.getAttribute('path') |
Michael Kelly | 37c21c2 | 2020-06-13 02:10:40 -0700 | [diff] [blame] | 1213 | dest_path = node.getAttribute('dest-path') |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 1214 | groups = node.getAttribute('groups') |
| 1215 | if groups: |
Mike Frysinger | 51e39d5 | 2020-12-04 05:32:06 -0500 | [diff] [blame] | 1216 | groups = self._ParseList(groups) |
Luis Hector Chavez | 7d52585 | 2018-03-15 09:54:08 -0700 | [diff] [blame] | 1217 | revision = node.getAttribute('revision') |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1218 | remote_name = node.getAttribute('remote') |
| 1219 | if not remote_name: |
| 1220 | remote = self._default.remote |
| 1221 | else: |
Kyunam Jo | bd0aae9 | 2020-02-04 11:38:53 +0900 | [diff] [blame] | 1222 | remote = self._get_remote(node) |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 1223 | |
Michael Kelly | 37c21c2 | 2020-06-13 02:10:40 -0700 | [diff] [blame] | 1224 | named_projects = self._projects[name] |
| 1225 | if dest_path and not path and len(named_projects) > 1: |
| 1226 | raise ManifestParseError('extend-project cannot use dest-path when ' |
| 1227 | 'matching multiple projects: %s' % name) |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 1228 | for p in self._projects[name]: |
| 1229 | if path and p.relpath != path: |
| 1230 | continue |
| 1231 | if groups: |
| 1232 | p.groups.extend(groups) |
Luis Hector Chavez | 7d52585 | 2018-03-15 09:54:08 -0700 | [diff] [blame] | 1233 | if revision: |
Michael Kelly | 2f3c331 | 2020-07-21 19:40:38 -0700 | [diff] [blame] | 1234 | p.SetRevision(revision) |
| 1235 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1236 | if remote_name: |
Kyunam Jo | bd0aae9 | 2020-02-04 11:38:53 +0900 | [diff] [blame] | 1237 | p.remote = remote.ToRemoteSpec(name) |
Michael Kelly | 2f3c331 | 2020-07-21 19:40:38 -0700 | [diff] [blame] | 1238 | |
Michael Kelly | 37c21c2 | 2020-06-13 02:10:40 -0700 | [diff] [blame] | 1239 | if dest_path: |
| 1240 | del self._paths[p.relpath] |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1241 | relpath, worktree, gitdir, objdir, _ = self.GetProjectPaths( |
| 1242 | name, dest_path, remote.name) |
Michael Kelly | 37c21c2 | 2020-06-13 02:10:40 -0700 | [diff] [blame] | 1243 | p.UpdatePaths(relpath, worktree, gitdir, objdir) |
| 1244 | self._paths[p.relpath] = p |
| 1245 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 1246 | if node.nodeName == 'repo-hooks': |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 1247 | # Only one project can be the hooks project |
Jack Neus | a84f43a | 2021-09-21 22:23:55 +0000 | [diff] [blame] | 1248 | if repo_hooks_project is not None: |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 1249 | raise ManifestParseError( |
| 1250 | 'duplicate repo-hooks in %s' % |
| 1251 | (self.manifestFile)) |
| 1252 | |
Jack Neus | a84f43a | 2021-09-21 22:23:55 +0000 | [diff] [blame] | 1253 | # Get the name of the project and the (space-separated) list of enabled. |
| 1254 | repo_hooks_project = self._reqatt(node, 'in-project') |
| 1255 | enabled_repo_hooks = self._ParseList(self._reqatt(node, 'enabled-list')) |
Raman Tenneti | 1bb4fb2 | 2021-01-07 16:50:45 -0800 | [diff] [blame] | 1256 | if node.nodeName == 'superproject': |
| 1257 | name = self._reqatt(node, 'name') |
| 1258 | # There can only be one superproject. |
| 1259 | if self._superproject.get('name'): |
| 1260 | raise ManifestParseError( |
| 1261 | 'duplicate superproject in %s' % |
| 1262 | (self.manifestFile)) |
| 1263 | self._superproject['name'] = name |
| 1264 | remote_name = node.getAttribute('remote') |
| 1265 | if not remote_name: |
| 1266 | remote = self._default.remote |
| 1267 | else: |
| 1268 | remote = self._get_remote(node) |
| 1269 | if remote is None: |
| 1270 | raise ManifestParseError("no remote for superproject %s within %s" % |
| 1271 | (name, self.manifestFile)) |
| 1272 | self._superproject['remote'] = remote.ToRemoteSpec(name) |
Xin Li | e0b16a2 | 2021-09-26 23:20:32 -0700 | [diff] [blame] | 1273 | revision = node.getAttribute('revision') or remote.revision |
| 1274 | if not revision: |
| 1275 | revision = self._default.revisionExpr |
| 1276 | if not revision: |
| 1277 | raise ManifestParseError('no revision for superproject %s within %s' % |
| 1278 | (name, self.manifestFile)) |
| 1279 | self._superproject['revision'] = revision |
Raman Tenneti | 1c3f57e | 2021-05-04 12:32:13 -0700 | [diff] [blame] | 1280 | if node.nodeName == 'contactinfo': |
| 1281 | bugurl = self._reqatt(node, 'bugurl') |
| 1282 | # This element can be repeated, later entries will clobber earlier ones. |
Raman Tenneti | 993af5e | 2021-05-12 12:00:31 -0700 | [diff] [blame] | 1283 | self._contactinfo = ContactInfo(bugurl) |
| 1284 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 1285 | if node.nodeName == 'remove-project': |
| 1286 | name = self._reqatt(node, 'name') |
David James | b8433df | 2014-01-30 10:11:17 -0800 | [diff] [blame] | 1287 | |
Michael Kelly | 06da998 | 2021-06-30 01:58:28 -0700 | [diff] [blame] | 1288 | if name in self._projects: |
| 1289 | for p in self._projects[name]: |
| 1290 | del self._paths[p.relpath] |
| 1291 | del self._projects[name] |
| 1292 | |
| 1293 | # If the manifest removes the hooks project, treat it as if it deleted |
| 1294 | # the repo-hooks element too. |
Jack Neus | a84f43a | 2021-09-21 22:23:55 +0000 | [diff] [blame] | 1295 | if repo_hooks_project == name: |
| 1296 | repo_hooks_project = None |
Michael Kelly | 06da998 | 2021-06-30 01:58:28 -0700 | [diff] [blame] | 1297 | elif not XmlBool(node, 'optional', False): |
David Pursehouse | f910748 | 2012-11-16 19:12:32 +0900 | [diff] [blame] | 1298 | raise ManifestParseError('remove-project element specifies non-existent ' |
| 1299 | 'project: %s' % name) |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 1300 | |
Jack Neus | a84f43a | 2021-09-21 22:23:55 +0000 | [diff] [blame] | 1301 | # Store repo hooks project information. |
| 1302 | if repo_hooks_project: |
| 1303 | # Store a reference to the Project. |
| 1304 | try: |
| 1305 | repo_hooks_projects = self._projects[repo_hooks_project] |
| 1306 | except KeyError: |
| 1307 | raise ManifestParseError( |
| 1308 | 'project %s not found for repo-hooks' % |
| 1309 | (repo_hooks_project)) |
| 1310 | |
| 1311 | if len(repo_hooks_projects) != 1: |
| 1312 | raise ManifestParseError( |
| 1313 | 'internal error parsing repo-hooks in %s' % |
| 1314 | (self.manifestFile)) |
| 1315 | self._repo_hooks_project = repo_hooks_projects[0] |
| 1316 | # Store the enabled hooks in the Project object. |
| 1317 | self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks |
| 1318 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 1319 | def _AddMetaProjectMirror(self, m): |
| 1320 | name = None |
| 1321 | m_url = m.GetRemote(m.remote.name).url |
| 1322 | if m_url.endswith('/.git'): |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 1323 | raise ManifestParseError('refusing to mirror %s' % m_url) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 1324 | |
| 1325 | if self._default and self._default.remote: |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 1326 | url = self._default.remote.resolvedFetchUrl |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 1327 | if not url.endswith('/'): |
| 1328 | url += '/' |
| 1329 | if m_url.startswith(url): |
| 1330 | remote = self._default.remote |
| 1331 | name = m_url[len(url):] |
| 1332 | |
| 1333 | if name is None: |
| 1334 | s = m_url.rindex('/') + 1 |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 1335 | manifestUrl = self.manifestProject.config.GetString('remote.origin.url') |
Shawn O. Pearce | f35b2d9 | 2012-08-02 11:46:22 -0700 | [diff] [blame] | 1336 | remote = _XmlRemote('origin', fetch=m_url[:s], manifestUrl=manifestUrl) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 1337 | name = m_url[s:] |
| 1338 | |
| 1339 | if name.endswith('.git'): |
| 1340 | name = name[:-4] |
| 1341 | |
| 1342 | if name not in self._projects: |
| 1343 | m.PreSync() |
| 1344 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
David Pursehouse | e5913ae | 2020-02-12 13:56:59 +0900 | [diff] [blame] | 1345 | project = Project(manifest=self, |
| 1346 | name=name, |
| 1347 | remote=remote.ToRemoteSpec(name), |
| 1348 | gitdir=gitdir, |
| 1349 | objdir=gitdir, |
| 1350 | worktree=None, |
| 1351 | relpath=name or None, |
| 1352 | revisionExpr=m.revisionExpr, |
| 1353 | revisionId=None) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 1354 | self._projects[project.name] = [project] |
Kwanhong Lee | ccd218c | 2014-02-17 13:07:32 +0900 | [diff] [blame] | 1355 | self._paths[project.relpath] = project |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 1356 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1357 | def _ParseRemote(self, node): |
| 1358 | """ |
| 1359 | reads a <remote> element from the manifest file |
| 1360 | """ |
| 1361 | name = self._reqatt(node, 'name') |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 1362 | alias = node.getAttribute('alias') |
| 1363 | if alias == '': |
| 1364 | alias = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1365 | fetch = self._reqatt(node, 'fetch') |
Steve Rae | d648045 | 2016-08-10 15:00:00 -0700 | [diff] [blame] | 1366 | pushUrl = node.getAttribute('pushurl') |
| 1367 | if pushUrl == '': |
| 1368 | pushUrl = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1369 | review = node.getAttribute('review') |
Shawn O. Pearce | ae6e094 | 2008-11-06 10:25:35 -0800 | [diff] [blame] | 1370 | if review == '': |
| 1371 | review = None |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 1372 | revision = node.getAttribute('revision') |
| 1373 | if revision == '': |
| 1374 | revision = None |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 1375 | manifestUrl = self.manifestProject.config.GetString('remote.origin.url') |
Jack Neus | 6ea0cae | 2021-07-20 20:52:33 +0000 | [diff] [blame] | 1376 | |
| 1377 | remote = _XmlRemote(name, alias, fetch, pushUrl, manifestUrl, review, revision) |
| 1378 | |
| 1379 | for n in node.childNodes: |
| 1380 | if n.nodeName == 'annotation': |
| 1381 | self._ParseAnnotation(remote, n) |
| 1382 | |
| 1383 | return remote |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1384 | |
| 1385 | def _ParseDefault(self, node): |
| 1386 | """ |
| 1387 | reads a <default> element from the manifest file |
| 1388 | """ |
| 1389 | d = _Default() |
| 1390 | d.remote = self._get_remote(node) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 1391 | d.revisionExpr = node.getAttribute('revision') |
| 1392 | if d.revisionExpr == '': |
| 1393 | d.revisionExpr = None |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 1394 | |
Bryan Jacobs | f609f91 | 2013-05-06 13:36:24 -0400 | [diff] [blame] | 1395 | d.destBranchExpr = node.getAttribute('dest-branch') or None |
Nasser Grainawi | da40341 | 2018-05-04 12:53:29 -0600 | [diff] [blame] | 1396 | d.upstreamExpr = node.getAttribute('upstream') or None |
Bryan Jacobs | f609f91 | 2013-05-06 13:36:24 -0400 | [diff] [blame] | 1397 | |
Mike Frysinger | bb8ee7f | 2020-02-22 05:30:12 -0500 | [diff] [blame] | 1398 | d.sync_j = XmlInt(node, 'sync-j', 1) |
| 1399 | if d.sync_j <= 0: |
| 1400 | raise ManifestParseError('%s: sync-j must be greater than 0, not "%s"' % |
| 1401 | (self.manifestFile, d.sync_j)) |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 1402 | |
Mike Frysinger | bb8ee7f | 2020-02-22 05:30:12 -0500 | [diff] [blame] | 1403 | d.sync_c = XmlBool(node, 'sync-c', False) |
| 1404 | d.sync_s = XmlBool(node, 'sync-s', False) |
| 1405 | d.sync_tags = XmlBool(node, 'sync-tags', True) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1406 | return d |
| 1407 | |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 1408 | def _ParseNotice(self, node): |
| 1409 | """ |
| 1410 | reads a <notice> element from the manifest file |
| 1411 | |
| 1412 | The <notice> element is distinct from other tags in the XML in that the |
| 1413 | data is conveyed between the start and end tag (it's not an empty-element |
| 1414 | tag). |
| 1415 | |
| 1416 | The white space (carriage returns, indentation) for the notice element is |
| 1417 | relevant and is parsed in a way that is based on how python docstrings work. |
| 1418 | In fact, the code is remarkably similar to here: |
| 1419 | http://www.python.org/dev/peps/pep-0257/ |
| 1420 | """ |
| 1421 | # Get the data out of the node... |
| 1422 | notice = node.childNodes[0].data |
| 1423 | |
| 1424 | # Figure out minimum indentation, skipping the first line (the same line |
| 1425 | # as the <notice> tag)... |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 1426 | minIndent = sys.maxsize |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 1427 | lines = notice.splitlines() |
| 1428 | for line in lines[1:]: |
| 1429 | lstrippedLine = line.lstrip() |
| 1430 | if lstrippedLine: |
| 1431 | indent = len(line) - len(lstrippedLine) |
| 1432 | minIndent = min(indent, minIndent) |
| 1433 | |
| 1434 | # Strip leading / trailing blank lines and also indentation. |
| 1435 | cleanLines = [lines[0].strip()] |
| 1436 | for line in lines[1:]: |
| 1437 | cleanLines.append(line[minIndent:].rstrip()) |
| 1438 | |
| 1439 | # Clear completely blank lines from front and back... |
| 1440 | while cleanLines and not cleanLines[0]: |
| 1441 | del cleanLines[0] |
| 1442 | while cleanLines and not cleanLines[-1]: |
| 1443 | del cleanLines[-1] |
| 1444 | |
| 1445 | return '\n'.join(cleanLines) |
| 1446 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1447 | def _ParseSubmanifest(self, node): |
| 1448 | """Reads a <submanifest> element from the manifest file.""" |
| 1449 | name = self._reqatt(node, 'name') |
| 1450 | remote = node.getAttribute('remote') |
| 1451 | if remote == '': |
| 1452 | remote = None |
| 1453 | project = node.getAttribute('project') |
| 1454 | if project == '': |
| 1455 | project = None |
| 1456 | revision = node.getAttribute('revision') |
| 1457 | if revision == '': |
| 1458 | revision = None |
| 1459 | manifestName = node.getAttribute('manifest-name') |
| 1460 | if manifestName == '': |
| 1461 | manifestName = None |
| 1462 | groups = '' |
| 1463 | if node.hasAttribute('groups'): |
| 1464 | groups = node.getAttribute('groups') |
| 1465 | groups = self._ParseList(groups) |
| 1466 | path = node.getAttribute('path') |
| 1467 | if path == '': |
| 1468 | path = None |
| 1469 | if revision: |
| 1470 | msg = self._CheckLocalPath(revision.split('/')[-1]) |
| 1471 | if msg: |
| 1472 | raise ManifestInvalidPathError( |
| 1473 | '<submanifest> invalid "revision": %s: %s' % (revision, msg)) |
| 1474 | else: |
| 1475 | msg = self._CheckLocalPath(name) |
| 1476 | if msg: |
| 1477 | raise ManifestInvalidPathError( |
| 1478 | '<submanifest> invalid "name": %s: %s' % (name, msg)) |
| 1479 | else: |
| 1480 | msg = self._CheckLocalPath(path) |
| 1481 | if msg: |
| 1482 | raise ManifestInvalidPathError( |
| 1483 | '<submanifest> invalid "path": %s: %s' % (path, msg)) |
| 1484 | |
| 1485 | submanifest = _XmlSubmanifest(name, remote, project, revision, manifestName, |
| 1486 | groups, path, self) |
| 1487 | |
| 1488 | for n in node.childNodes: |
| 1489 | if n.nodeName == 'annotation': |
| 1490 | self._ParseAnnotation(submanifest, n) |
| 1491 | |
| 1492 | return submanifest |
| 1493 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1494 | def _JoinName(self, parent_name, name): |
| 1495 | return os.path.join(parent_name, name) |
| 1496 | |
| 1497 | def _UnjoinName(self, parent_name, name): |
| 1498 | return os.path.relpath(name, parent_name) |
| 1499 | |
David Pursehouse | e5913ae | 2020-02-12 13:56:59 +0900 | [diff] [blame] | 1500 | def _ParseProject(self, node, parent=None, **extra_proj_attrs): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1501 | """ |
| 1502 | reads a <project> element from the manifest file |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 1503 | """ |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1504 | name = self._reqatt(node, 'name') |
Mike Frysinger | a29424e | 2021-02-25 21:53:49 -0500 | [diff] [blame] | 1505 | msg = self._CheckLocalPath(name, dir_ok=True) |
| 1506 | if msg: |
| 1507 | raise ManifestInvalidPathError( |
| 1508 | '<project> invalid "name": %s: %s' % (name, msg)) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1509 | if parent: |
| 1510 | name = self._JoinName(parent.name, name) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1511 | |
| 1512 | remote = self._get_remote(node) |
| 1513 | if remote is None: |
| 1514 | remote = self._default.remote |
| 1515 | if remote is None: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 1516 | raise ManifestParseError("no remote for project %s within %s" % |
David Pursehouse | abdf750 | 2020-02-12 14:58:39 +0900 | [diff] [blame] | 1517 | (name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1518 | |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 1519 | revisionExpr = node.getAttribute('revision') or remote.revision |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 1520 | if not revisionExpr: |
| 1521 | revisionExpr = self._default.revisionExpr |
| 1522 | if not revisionExpr: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 1523 | raise ManifestParseError("no revision for project %s within %s" % |
David Pursehouse | abdf750 | 2020-02-12 14:58:39 +0900 | [diff] [blame] | 1524 | (name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1525 | |
| 1526 | path = node.getAttribute('path') |
| 1527 | if not path: |
| 1528 | path = name |
Mike Frysinger | a29424e | 2021-02-25 21:53:49 -0500 | [diff] [blame] | 1529 | else: |
Mike Frysinger | 0458faa | 2021-03-10 23:35:44 -0500 | [diff] [blame] | 1530 | # NB: The "." project is handled specially in Project.Sync_LocalHalf. |
| 1531 | msg = self._CheckLocalPath(path, dir_ok=True, cwd_dot_ok=True) |
Mike Frysinger | a29424e | 2021-02-25 21:53:49 -0500 | [diff] [blame] | 1532 | if msg: |
| 1533 | raise ManifestInvalidPathError( |
| 1534 | '<project> invalid "path": %s: %s' % (path, msg)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1535 | |
Mike Frysinger | bb8ee7f | 2020-02-22 05:30:12 -0500 | [diff] [blame] | 1536 | rebase = XmlBool(node, 'rebase', True) |
| 1537 | sync_c = XmlBool(node, 'sync-c', False) |
| 1538 | sync_s = XmlBool(node, 'sync-s', self._default.sync_s) |
| 1539 | sync_tags = XmlBool(node, 'sync-tags', self._default.sync_tags) |
Mike Pontillo | d315382 | 2012-02-28 11:53:24 -0800 | [diff] [blame] | 1540 | |
Mike Frysinger | bb8ee7f | 2020-02-22 05:30:12 -0500 | [diff] [blame] | 1541 | clone_depth = XmlInt(node, 'clone-depth') |
| 1542 | if clone_depth is not None and clone_depth <= 0: |
| 1543 | raise ManifestParseError('%s: clone-depth must be greater than 0, not "%s"' % |
| 1544 | (self.manifestFile, clone_depth)) |
David Pursehouse | ede7f12 | 2012-11-27 22:25:30 +0900 | [diff] [blame] | 1545 | |
Bryan Jacobs | f609f91 | 2013-05-06 13:36:24 -0400 | [diff] [blame] | 1546 | dest_branch = node.getAttribute('dest-branch') or self._default.destBranchExpr |
| 1547 | |
Nasser Grainawi | da40341 | 2018-05-04 12:53:29 -0600 | [diff] [blame] | 1548 | upstream = node.getAttribute('upstream') or self._default.upstreamExpr |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 1549 | |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 1550 | groups = '' |
| 1551 | if node.hasAttribute('groups'): |
| 1552 | groups = node.getAttribute('groups') |
Mike Frysinger | 51e39d5 | 2020-12-04 05:32:06 -0500 | [diff] [blame] | 1553 | groups = self._ParseList(groups) |
Brian Harring | 7da1314 | 2012-06-15 02:24:20 -0700 | [diff] [blame] | 1554 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1555 | if parent is None: |
Mike Frysinger | 979d5bd | 2020-02-09 02:28:34 -0500 | [diff] [blame] | 1556 | relpath, worktree, gitdir, objdir, use_git_worktrees = \ |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1557 | self.GetProjectPaths(name, path, remote.name) |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 1558 | else: |
Mike Frysinger | 979d5bd | 2020-02-09 02:28:34 -0500 | [diff] [blame] | 1559 | use_git_worktrees = False |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 1560 | relpath, worktree, gitdir, objdir = \ |
| 1561 | self.GetSubprojectPaths(parent, name, path) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1562 | |
| 1563 | default_groups = ['all', 'name:%s' % name, 'path:%s' % relpath] |
| 1564 | groups.extend(set(default_groups).difference(groups)) |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 1565 | |
Scott Fan | db83b1b | 2013-02-28 09:34:14 +0800 | [diff] [blame] | 1566 | if self.IsMirror and node.hasAttribute('force-path'): |
Mike Frysinger | bb8ee7f | 2020-02-22 05:30:12 -0500 | [diff] [blame] | 1567 | if XmlBool(node, 'force-path', False): |
Scott Fan | db83b1b | 2013-02-28 09:34:14 +0800 | [diff] [blame] | 1568 | gitdir = os.path.join(self.topdir, '%s.git' % path) |
| 1569 | |
David Pursehouse | e5913ae | 2020-02-12 13:56:59 +0900 | [diff] [blame] | 1570 | project = Project(manifest=self, |
| 1571 | name=name, |
| 1572 | remote=remote.ToRemoteSpec(name), |
| 1573 | gitdir=gitdir, |
| 1574 | objdir=objdir, |
| 1575 | worktree=worktree, |
| 1576 | relpath=relpath, |
| 1577 | revisionExpr=revisionExpr, |
| 1578 | revisionId=None, |
| 1579 | rebase=rebase, |
| 1580 | groups=groups, |
| 1581 | sync_c=sync_c, |
| 1582 | sync_s=sync_s, |
| 1583 | sync_tags=sync_tags, |
| 1584 | clone_depth=clone_depth, |
| 1585 | upstream=upstream, |
| 1586 | parent=parent, |
| 1587 | dest_branch=dest_branch, |
Mike Frysinger | 979d5bd | 2020-02-09 02:28:34 -0500 | [diff] [blame] | 1588 | use_git_worktrees=use_git_worktrees, |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 1589 | **extra_proj_attrs) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1590 | |
| 1591 | for n in node.childNodes: |
Shawn O. Pearce | 242b526 | 2009-05-19 13:00:29 -0700 | [diff] [blame] | 1592 | if n.nodeName == 'copyfile': |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1593 | self._ParseCopyFile(project, n) |
Jeff Hamilton | e0df232 | 2014-04-21 17:10:59 -0500 | [diff] [blame] | 1594 | if n.nodeName == 'linkfile': |
| 1595 | self._ParseLinkFile(project, n) |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 1596 | if n.nodeName == 'annotation': |
| 1597 | self._ParseAnnotation(project, n) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1598 | if n.nodeName == 'project': |
David Pursehouse | e5913ae | 2020-02-12 13:56:59 +0900 | [diff] [blame] | 1599 | project.subprojects.append(self._ParseProject(n, parent=project)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1600 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1601 | return project |
| 1602 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1603 | def GetProjectPaths(self, name, path, remote): |
| 1604 | """Return the paths for a project. |
| 1605 | |
| 1606 | Args: |
| 1607 | name: a string, the name of the project. |
| 1608 | path: a string, the path of the project. |
| 1609 | remote: a string, the remote.name of the project. |
| 1610 | """ |
Mike Frysinger | cebf227 | 2020-05-26 01:02:29 -0400 | [diff] [blame] | 1611 | # The manifest entries might have trailing slashes. Normalize them to avoid |
| 1612 | # unexpected filesystem behavior since we do string concatenation below. |
| 1613 | path = path.rstrip('/') |
| 1614 | name = name.rstrip('/') |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1615 | remote = remote.rstrip('/') |
Mike Frysinger | 979d5bd | 2020-02-09 02:28:34 -0500 | [diff] [blame] | 1616 | use_git_worktrees = False |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1617 | use_remote_name = bool(self._outer_client._submanifests) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1618 | relpath = path |
| 1619 | if self.IsMirror: |
| 1620 | worktree = None |
| 1621 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 1622 | objdir = gitdir |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1623 | else: |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1624 | if use_remote_name: |
| 1625 | namepath = os.path.join(remote, f'{name}.git') |
| 1626 | else: |
| 1627 | namepath = f'{name}.git' |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1628 | worktree = os.path.join(self.topdir, path).replace('\\', '/') |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1629 | gitdir = os.path.join(self.subdir, 'projects', '%s.git' % path) |
Mike Frysinger | 979d5bd | 2020-02-09 02:28:34 -0500 | [diff] [blame] | 1630 | # We allow people to mix git worktrees & non-git worktrees for now. |
| 1631 | # This allows for in situ migration of repo clients. |
| 1632 | if os.path.exists(gitdir) or not self.UseGitWorktrees: |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1633 | objdir = os.path.join(self.subdir, 'project-objects', namepath) |
Mike Frysinger | 979d5bd | 2020-02-09 02:28:34 -0500 | [diff] [blame] | 1634 | else: |
| 1635 | use_git_worktrees = True |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1636 | gitdir = os.path.join(self.repodir, 'worktrees', namepath) |
Mike Frysinger | 979d5bd | 2020-02-09 02:28:34 -0500 | [diff] [blame] | 1637 | objdir = gitdir |
| 1638 | return relpath, worktree, gitdir, objdir, use_git_worktrees |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 1639 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1640 | def GetProjectsWithName(self, name, all_manifests=False): |
| 1641 | """All projects with |name|. |
| 1642 | |
| 1643 | Args: |
| 1644 | name: a string, the name of the project. |
| 1645 | all_manifests: a boolean, if True, then all manifests are searched. If |
| 1646 | False, then only this manifest is searched. |
| 1647 | """ |
| 1648 | if all_manifests: |
| 1649 | return list(itertools.chain.from_iterable( |
| 1650 | x._projects.get(name, []) for x in self.all_manifests)) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 1651 | return self._projects.get(name, []) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1652 | |
| 1653 | def GetSubprojectName(self, parent, submodule_path): |
| 1654 | return os.path.join(parent.name, submodule_path) |
| 1655 | |
| 1656 | def _JoinRelpath(self, parent_relpath, relpath): |
| 1657 | return os.path.join(parent_relpath, relpath) |
| 1658 | |
| 1659 | def _UnjoinRelpath(self, parent_relpath, relpath): |
| 1660 | return os.path.relpath(relpath, parent_relpath) |
| 1661 | |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 1662 | def GetSubprojectPaths(self, parent, name, path): |
Mike Frysinger | cebf227 | 2020-05-26 01:02:29 -0400 | [diff] [blame] | 1663 | # The manifest entries might have trailing slashes. Normalize them to avoid |
| 1664 | # unexpected filesystem behavior since we do string concatenation below. |
| 1665 | path = path.rstrip('/') |
| 1666 | name = name.rstrip('/') |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1667 | relpath = self._JoinRelpath(parent.relpath, path) |
| 1668 | gitdir = os.path.join(parent.gitdir, 'subprojects', '%s.git' % path) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 1669 | objdir = os.path.join(parent.gitdir, 'subproject-objects', '%s.git' % name) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1670 | if self.IsMirror: |
| 1671 | worktree = None |
| 1672 | else: |
| 1673 | worktree = os.path.join(parent.worktree, path).replace('\\', '/') |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 1674 | return relpath, worktree, gitdir, objdir |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 1675 | |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1676 | @staticmethod |
Mike Frysinger | a00c5f4 | 2021-02-25 18:26:31 -0500 | [diff] [blame] | 1677 | def _CheckLocalPath(path, dir_ok=False, cwd_dot_ok=False): |
| 1678 | """Verify |path| is reasonable for use in filesystem paths. |
| 1679 | |
Mike Frysinger | a29424e | 2021-02-25 21:53:49 -0500 | [diff] [blame] | 1680 | Used with <copyfile> & <linkfile> & <project> elements. |
Mike Frysinger | a00c5f4 | 2021-02-25 18:26:31 -0500 | [diff] [blame] | 1681 | |
| 1682 | This only validates the |path| in isolation: it does not check against the |
| 1683 | current filesystem state. Thus it is suitable as a first-past in a parser. |
| 1684 | |
| 1685 | It enforces a number of constraints: |
| 1686 | * No empty paths. |
| 1687 | * No "~" in paths. |
| 1688 | * No Unicode codepoints that filesystems might elide when normalizing. |
| 1689 | * No relative path components like "." or "..". |
| 1690 | * No absolute paths. |
| 1691 | * No ".git" or ".repo*" path components. |
| 1692 | |
| 1693 | Args: |
| 1694 | path: The path name to validate. |
| 1695 | dir_ok: Whether |path| may force a directory (e.g. end in a /). |
| 1696 | cwd_dot_ok: Whether |path| may be just ".". |
| 1697 | |
| 1698 | Returns: |
| 1699 | None if |path| is OK, a failure message otherwise. |
| 1700 | """ |
| 1701 | if not path: |
| 1702 | return 'empty paths not allowed' |
| 1703 | |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1704 | if '~' in path: |
| 1705 | return '~ not allowed (due to 8.3 filenames on Windows filesystems)' |
| 1706 | |
Mike Frysinger | f69c7ee | 2021-04-29 23:15:31 -0400 | [diff] [blame] | 1707 | path_codepoints = set(path) |
| 1708 | |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1709 | # Some filesystems (like Apple's HFS+) try to normalize Unicode codepoints |
| 1710 | # which means there are alternative names for ".git". Reject paths with |
| 1711 | # these in it as there shouldn't be any reasonable need for them here. |
| 1712 | # The set of codepoints here was cribbed from jgit's implementation: |
| 1713 | # https://eclipse.googlesource.com/jgit/jgit/+/9110037e3e9461ff4dac22fee84ef3694ed57648/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java#884 |
| 1714 | BAD_CODEPOINTS = { |
| 1715 | u'\u200C', # ZERO WIDTH NON-JOINER |
| 1716 | u'\u200D', # ZERO WIDTH JOINER |
| 1717 | u'\u200E', # LEFT-TO-RIGHT MARK |
| 1718 | u'\u200F', # RIGHT-TO-LEFT MARK |
| 1719 | u'\u202A', # LEFT-TO-RIGHT EMBEDDING |
| 1720 | u'\u202B', # RIGHT-TO-LEFT EMBEDDING |
| 1721 | u'\u202C', # POP DIRECTIONAL FORMATTING |
| 1722 | u'\u202D', # LEFT-TO-RIGHT OVERRIDE |
| 1723 | u'\u202E', # RIGHT-TO-LEFT OVERRIDE |
| 1724 | u'\u206A', # INHIBIT SYMMETRIC SWAPPING |
| 1725 | u'\u206B', # ACTIVATE SYMMETRIC SWAPPING |
| 1726 | u'\u206C', # INHIBIT ARABIC FORM SHAPING |
| 1727 | u'\u206D', # ACTIVATE ARABIC FORM SHAPING |
| 1728 | u'\u206E', # NATIONAL DIGIT SHAPES |
| 1729 | u'\u206F', # NOMINAL DIGIT SHAPES |
| 1730 | u'\uFEFF', # ZERO WIDTH NO-BREAK SPACE |
| 1731 | } |
Mike Frysinger | f69c7ee | 2021-04-29 23:15:31 -0400 | [diff] [blame] | 1732 | if BAD_CODEPOINTS & path_codepoints: |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1733 | # This message is more expansive than reality, but should be fine. |
| 1734 | return 'Unicode combining characters not allowed' |
| 1735 | |
Mike Frysinger | f69c7ee | 2021-04-29 23:15:31 -0400 | [diff] [blame] | 1736 | # Reject newlines as there shouldn't be any legitmate use for them, they'll |
| 1737 | # be confusing to users, and they can easily break tools that expect to be |
| 1738 | # able to iterate over newline delimited lists. This even applies to our |
| 1739 | # own code like .repo/project.list. |
| 1740 | if {'\r', '\n'} & path_codepoints: |
| 1741 | return 'Newlines not allowed' |
| 1742 | |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1743 | # Assume paths might be used on case-insensitive filesystems. |
| 1744 | path = path.lower() |
| 1745 | |
Mike Frysinger | d925459 | 2020-02-19 22:36:26 -0500 | [diff] [blame] | 1746 | # Split up the path by its components. We can't use os.path.sep exclusively |
| 1747 | # as some platforms (like Windows) will convert / to \ and that bypasses all |
| 1748 | # our constructed logic here. Especially since manifest authors only use |
| 1749 | # / in their paths. |
| 1750 | resep = re.compile(r'[/%s]' % re.escape(os.path.sep)) |
Mike Frysinger | 0458faa | 2021-03-10 23:35:44 -0500 | [diff] [blame] | 1751 | # Strip off trailing slashes as those only produce '' elements, and we use |
| 1752 | # parts to look for individual bad components. |
| 1753 | parts = resep.split(path.rstrip('/')) |
Mike Frysinger | d925459 | 2020-02-19 22:36:26 -0500 | [diff] [blame] | 1754 | |
Mike Frysinger | ae62541 | 2020-02-10 17:10:03 -0500 | [diff] [blame] | 1755 | # Some people use src="." to create stable links to projects. Lets allow |
| 1756 | # that but reject all other uses of "." to keep things simple. |
Mike Frysinger | a00c5f4 | 2021-02-25 18:26:31 -0500 | [diff] [blame] | 1757 | if not cwd_dot_ok or parts != ['.']: |
Mike Frysinger | ae62541 | 2020-02-10 17:10:03 -0500 | [diff] [blame] | 1758 | for part in set(parts): |
| 1759 | if part in {'.', '..', '.git'} or part.startswith('.repo'): |
| 1760 | return 'bad component: %s' % (part,) |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1761 | |
Mike Frysinger | a00c5f4 | 2021-02-25 18:26:31 -0500 | [diff] [blame] | 1762 | if not dir_ok and resep.match(path[-1]): |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1763 | return 'dirs not allowed' |
| 1764 | |
Mike Frysinger | d925459 | 2020-02-19 22:36:26 -0500 | [diff] [blame] | 1765 | # NB: The two abspath checks here are to handle platforms with multiple |
| 1766 | # filesystem path styles (e.g. Windows). |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1767 | norm = os.path.normpath(path) |
Mike Frysinger | d925459 | 2020-02-19 22:36:26 -0500 | [diff] [blame] | 1768 | if (norm == '..' or |
| 1769 | (len(norm) >= 3 and norm.startswith('..') and resep.match(norm[0])) or |
| 1770 | os.path.isabs(norm) or |
| 1771 | norm.startswith('/')): |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1772 | return 'path cannot be outside' |
| 1773 | |
| 1774 | @classmethod |
| 1775 | def _ValidateFilePaths(cls, element, src, dest): |
| 1776 | """Verify |src| & |dest| are reasonable for <copyfile> & <linkfile>. |
| 1777 | |
| 1778 | We verify the path independent of any filesystem state as we won't have a |
| 1779 | checkout available to compare to. i.e. This is for parsing validation |
| 1780 | purposes only. |
| 1781 | |
| 1782 | We'll do full/live sanity checking before we do the actual filesystem |
| 1783 | modifications in _CopyFile/_LinkFile/etc... |
| 1784 | """ |
| 1785 | # |dest| is the file we write to or symlink we create. |
| 1786 | # It is relative to the top of the repo client checkout. |
| 1787 | msg = cls._CheckLocalPath(dest) |
| 1788 | if msg: |
| 1789 | raise ManifestInvalidPathError( |
| 1790 | '<%s> invalid "dest": %s: %s' % (element, dest, msg)) |
| 1791 | |
| 1792 | # |src| is the file we read from or path we point to for symlinks. |
| 1793 | # It is relative to the top of the git project checkout. |
Mike Frysinger | a00c5f4 | 2021-02-25 18:26:31 -0500 | [diff] [blame] | 1794 | is_linkfile = element == 'linkfile' |
| 1795 | msg = cls._CheckLocalPath(src, dir_ok=is_linkfile, cwd_dot_ok=is_linkfile) |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1796 | if msg: |
| 1797 | raise ManifestInvalidPathError( |
| 1798 | '<%s> invalid "src": %s: %s' % (element, src, msg)) |
| 1799 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1800 | def _ParseCopyFile(self, project, node): |
| 1801 | src = self._reqatt(node, 'src') |
| 1802 | dest = self._reqatt(node, 'dest') |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 1803 | if not self.IsMirror: |
| 1804 | # src is project relative; |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1805 | # dest is relative to the top of the tree. |
| 1806 | # We only validate paths if we actually plan to process them. |
| 1807 | self._ValidateFilePaths('copyfile', src, dest) |
Mike Frysinger | e6a202f | 2019-08-02 15:57:57 -0400 | [diff] [blame] | 1808 | project.AddCopyFile(src, dest, self.topdir) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1809 | |
Jeff Hamilton | e0df232 | 2014-04-21 17:10:59 -0500 | [diff] [blame] | 1810 | def _ParseLinkFile(self, project, node): |
| 1811 | src = self._reqatt(node, 'src') |
| 1812 | dest = self._reqatt(node, 'dest') |
| 1813 | if not self.IsMirror: |
| 1814 | # src is project relative; |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 1815 | # dest is relative to the top of the tree. |
| 1816 | # We only validate paths if we actually plan to process them. |
| 1817 | self._ValidateFilePaths('linkfile', src, dest) |
Mike Frysinger | e6a202f | 2019-08-02 15:57:57 -0400 | [diff] [blame] | 1818 | project.AddLinkFile(src, dest, self.topdir) |
Jeff Hamilton | e0df232 | 2014-04-21 17:10:59 -0500 | [diff] [blame] | 1819 | |
Jack Neus | 6ea0cae | 2021-07-20 20:52:33 +0000 | [diff] [blame] | 1820 | def _ParseAnnotation(self, element, node): |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 1821 | name = self._reqatt(node, 'name') |
| 1822 | value = self._reqatt(node, 'value') |
| 1823 | try: |
| 1824 | keep = self._reqatt(node, 'keep').lower() |
| 1825 | except ManifestParseError: |
| 1826 | keep = "true" |
| 1827 | if keep != "true" and keep != "false": |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 1828 | raise ManifestParseError('optional "keep" attribute must be ' |
David Pursehouse | abdf750 | 2020-02-12 14:58:39 +0900 | [diff] [blame] | 1829 | '"true" or "false"') |
Jack Neus | 6ea0cae | 2021-07-20 20:52:33 +0000 | [diff] [blame] | 1830 | element.AddAnnotation(name, value, keep) |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 1831 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1832 | def _get_remote(self, node): |
| 1833 | name = node.getAttribute('remote') |
| 1834 | if not name: |
| 1835 | return None |
| 1836 | |
| 1837 | v = self._remotes.get(name) |
| 1838 | if not v: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 1839 | raise ManifestParseError("remote %s not defined in %s" % |
David Pursehouse | abdf750 | 2020-02-12 14:58:39 +0900 | [diff] [blame] | 1840 | (name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1841 | return v |
| 1842 | |
| 1843 | def _reqatt(self, node, attname): |
| 1844 | """ |
| 1845 | reads a required attribute from the node. |
| 1846 | """ |
| 1847 | v = node.getAttribute(attname) |
| 1848 | if not v: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 1849 | raise ManifestParseError("no %s in <%s> within %s" % |
David Pursehouse | abdf750 | 2020-02-12 14:58:39 +0900 | [diff] [blame] | 1850 | (attname, node.nodeName, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1851 | return v |
Julien Campergue | dd65422 | 2014-01-09 16:21:37 +0100 | [diff] [blame] | 1852 | |
| 1853 | def projectsDiff(self, manifest): |
| 1854 | """return the projects differences between two manifests. |
| 1855 | |
| 1856 | The diff will be from self to given manifest. |
| 1857 | |
| 1858 | """ |
| 1859 | fromProjects = self.paths |
| 1860 | toProjects = manifest.paths |
| 1861 | |
Anthony King | 7446c59 | 2014-05-06 09:19:39 +0100 | [diff] [blame] | 1862 | fromKeys = sorted(fromProjects.keys()) |
| 1863 | toKeys = sorted(toProjects.keys()) |
Julien Campergue | dd65422 | 2014-01-09 16:21:37 +0100 | [diff] [blame] | 1864 | |
| 1865 | diff = {'added': [], 'removed': [], 'changed': [], 'unreachable': []} |
| 1866 | |
| 1867 | for proj in fromKeys: |
David Pursehouse | eeff353 | 2020-02-12 11:24:10 +0900 | [diff] [blame] | 1868 | if proj not in toKeys: |
Julien Campergue | dd65422 | 2014-01-09 16:21:37 +0100 | [diff] [blame] | 1869 | diff['removed'].append(fromProjects[proj]) |
| 1870 | else: |
| 1871 | fromProj = fromProjects[proj] |
| 1872 | toProj = toProjects[proj] |
| 1873 | try: |
| 1874 | fromRevId = fromProj.GetCommitRevisionId() |
| 1875 | toRevId = toProj.GetCommitRevisionId() |
| 1876 | except ManifestInvalidRevisionError: |
| 1877 | diff['unreachable'].append((fromProj, toProj)) |
| 1878 | else: |
| 1879 | if fromRevId != toRevId: |
| 1880 | diff['changed'].append((fromProj, toProj)) |
| 1881 | toKeys.remove(proj) |
| 1882 | |
| 1883 | for proj in toKeys: |
| 1884 | diff['added'].append(toProjects[proj]) |
| 1885 | |
| 1886 | return diff |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 1887 | |
| 1888 | |
| 1889 | class GitcManifest(XmlManifest): |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 1890 | """Parser for GitC (git-in-the-cloud) manifests.""" |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 1891 | |
David Pursehouse | e5913ae | 2020-02-12 13:56:59 +0900 | [diff] [blame] | 1892 | def _ParseProject(self, node, parent=None): |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 1893 | """Override _ParseProject and add support for GITC specific attributes.""" |
Mike Frysinger | 5d9c497 | 2021-02-19 13:34:09 -0500 | [diff] [blame] | 1894 | return super()._ParseProject( |
Simran Basi | b9a1b73 | 2015-08-20 12:19:28 -0700 | [diff] [blame] | 1895 | node, parent=parent, old_revision=node.getAttribute('old-revision')) |
| 1896 | |
| 1897 | def _output_manifest_project_extras(self, p, e): |
| 1898 | """Output GITC Specific Project attributes""" |
| 1899 | if p.old_revision: |
Stefan Beller | 6685106 | 2016-06-17 16:40:08 -0700 | [diff] [blame] | 1900 | e.setAttribute('old-revision', str(p.old_revision)) |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 1901 | |
| 1902 | |
| 1903 | class RepoClient(XmlManifest): |
| 1904 | """Manages a repo client checkout.""" |
| 1905 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1906 | def __init__(self, repodir, manifest_file=None, submanifest_path='', **kwargs): |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 1907 | self.isGitcClient = False |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1908 | submanifest_path = submanifest_path or '' |
| 1909 | if submanifest_path: |
| 1910 | self._CheckLocalPath(submanifest_path) |
| 1911 | prefix = os.path.join(repodir, SUBMANIFEST_DIR, submanifest_path) |
| 1912 | else: |
| 1913 | prefix = repodir |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 1914 | |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1915 | if os.path.exists(os.path.join(prefix, LOCAL_MANIFEST_NAME)): |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 1916 | print('error: %s is not supported; put local manifests in `%s` instead' % |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1917 | (LOCAL_MANIFEST_NAME, os.path.join(prefix, LOCAL_MANIFESTS_DIR_NAME)), |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 1918 | file=sys.stderr) |
| 1919 | sys.exit(1) |
| 1920 | |
| 1921 | if manifest_file is None: |
LaMont Jones | cc879a9 | 2021-11-18 22:40:18 +0000 | [diff] [blame] | 1922 | manifest_file = os.path.join(prefix, MANIFEST_FILE_NAME) |
| 1923 | local_manifests = os.path.abspath(os.path.join(prefix, LOCAL_MANIFESTS_DIR_NAME)) |
| 1924 | super().__init__(repodir, manifest_file, local_manifests, |
| 1925 | submanifest_path=submanifest_path, **kwargs) |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 1926 | |
| 1927 | # TODO: Completely separate manifest logic out of the client. |
| 1928 | self.manifest = self |
| 1929 | |
| 1930 | |
| 1931 | class GitcClient(RepoClient, GitcManifest): |
| 1932 | """Manages a GitC client checkout.""" |
| 1933 | |
| 1934 | def __init__(self, repodir, gitc_client_name): |
| 1935 | """Initialize the GitcManifest object.""" |
| 1936 | self.gitc_client_name = gitc_client_name |
| 1937 | self.gitc_client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(), |
| 1938 | gitc_client_name) |
| 1939 | |
Mike Frysinger | 5d9c497 | 2021-02-19 13:34:09 -0500 | [diff] [blame] | 1940 | super().__init__(repodir, os.path.join(self.gitc_client_dir, '.manifest')) |
Mike Frysinger | 8c1e9cb | 2020-09-06 14:53:18 -0400 | [diff] [blame] | 1941 | self.isGitcClient = True |