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