blob: 03925176c32c0517d8e27870f369bc7f593c86a1 [file] [log] [blame]
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001# 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 Tenneti993af5e2021-05-12 12:00:31 -070015import collections
Colin Cross23acdd32012-04-21 00:33:54 -070016import itertools
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070017import os
Raman Tenneti080877e2021-03-09 15:19:06 -080018import platform
Conley Owensdb728cd2011-09-26 16:34:01 -070019import re
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070020import sys
Mike Frysingeracf63b22019-06-13 02:24:21 -040021import urllib.parse
Mike Frysinger64477332023-08-21 21:20:32 -040022import xml.dom.minidom
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070023
Mike Frysinger64477332023-08-21 21:20:32 -040024from error import ManifestInvalidPathError
25from error import ManifestInvalidRevisionError
26from error import ManifestParseError
Daniel Kutik035f22a2022-12-13 12:34:23 +010027from git_config import GitConfig
Mike Frysinger64477332023-08-21 21:20:32 -040028from git_refs import HEAD
29from git_refs import R_HEADS
LaMont Jonesd56e2eb2022-04-07 18:14:46 +000030from git_superproject import Superproject
Renaud Paquayd5cec5e2016-11-01 11:24:03 -070031import platform_utils
Mike Frysinger64477332023-08-21 21:20:32 -040032from project import Annotation
33from project import ManifestProject
34from project import Project
35from project import RemoteSpec
36from project import RepoProject
Raman Tenneti993af5e2021-05-12 12:00:31 -070037from wrapper import Wrapper
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070038
Mike Frysinger64477332023-08-21 21:20:32 -040039
Gavin Makea2e3302023-03-11 06:46:20 +000040MANIFEST_FILE_NAME = "manifest.xml"
41LOCAL_MANIFEST_NAME = "local_manifest.xml"
42LOCAL_MANIFESTS_DIR_NAME = "local_manifests"
43SUBMANIFEST_DIR = "submanifests"
LaMont Jonescc879a92021-11-18 22:40:18 +000044# Limit submanifests to an arbitrary depth for loop detection.
45MAX_SUBMANIFEST_DEPTH = 8
LaMont Jonesb308db12022-02-25 17:05:21 +000046# Add all projects from sub manifest into a group.
Gavin Makea2e3302023-03-11 06:46:20 +000047SUBMANIFEST_GROUP_PREFIX = "submanifest:"
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070048
Raman Tenneti78f4dd32021-06-07 13:27:37 -070049# Add all projects from local manifest into a group.
Gavin Makea2e3302023-03-11 06:46:20 +000050LOCAL_MANIFEST_GROUP_PREFIX = "local:"
Raman Tenneti78f4dd32021-06-07 13:27:37 -070051
Raman Tenneti993af5e2021-05-12 12:00:31 -070052# ContactInfo has the self-registered bug url, supplied by the manifest authors.
Gavin Makea2e3302023-03-11 06:46:20 +000053ContactInfo = collections.namedtuple("ContactInfo", "bugurl")
Raman Tenneti993af5e2021-05-12 12:00:31 -070054
Anthony Kingcb07ba72015-03-28 23:26:04 +000055# urljoin gets confused if the scheme is not known.
Gavin Makea2e3302023-03-11 06:46:20 +000056urllib.parse.uses_relative.extend(
57 ["ssh", "git", "persistent-https", "sso", "rpc"]
58)
59urllib.parse.uses_netloc.extend(
60 ["ssh", "git", "persistent-https", "sso", "rpc"]
61)
Conley Owensdb728cd2011-09-26 16:34:01 -070062
David Pursehouse819827a2020-02-12 15:20:19 +090063
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050064def XmlBool(node, attr, default=None):
Gavin Makea2e3302023-03-11 06:46:20 +000065 """Determine boolean value of |node|'s |attr|.
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050066
Gavin Makea2e3302023-03-11 06:46:20 +000067 Invalid values will issue a non-fatal warning.
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050068
Gavin Makea2e3302023-03-11 06:46:20 +000069 Args:
70 node: XML node whose attributes we access.
71 attr: The attribute to access.
72 default: If the attribute is not set (value is empty), then use this.
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050073
Gavin Makea2e3302023-03-11 06:46:20 +000074 Returns:
75 True if the attribute is a valid string representing true.
76 False if the attribute is a valid string representing false.
77 |default| otherwise.
78 """
79 value = node.getAttribute(attr)
80 s = value.lower()
81 if s == "":
82 return default
83 elif s in {"yes", "true", "1"}:
84 return True
85 elif s in {"no", "false", "0"}:
86 return False
87 else:
88 print(
89 'warning: manifest: %s="%s": ignoring invalid XML boolean'
90 % (attr, value),
91 file=sys.stderr,
92 )
93 return default
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050094
95
96def XmlInt(node, attr, default=None):
Gavin Makea2e3302023-03-11 06:46:20 +000097 """Determine integer value of |node|'s |attr|.
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050098
Gavin Makea2e3302023-03-11 06:46:20 +000099 Args:
100 node: XML node whose attributes we access.
101 attr: The attribute to access.
102 default: If the attribute is not set (value is empty), then use this.
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500103
Gavin Makea2e3302023-03-11 06:46:20 +0000104 Returns:
105 The number if the attribute is a valid number.
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500106
Gavin Makea2e3302023-03-11 06:46:20 +0000107 Raises:
108 ManifestParseError: The number is invalid.
109 """
110 value = node.getAttribute(attr)
111 if not value:
112 return default
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500113
Gavin Makea2e3302023-03-11 06:46:20 +0000114 try:
115 return int(value)
116 except ValueError:
117 raise ManifestParseError(
118 'manifest: invalid %s="%s" integer' % (attr, value)
119 )
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500120
121
Mike Frysingerd4aee652023-10-19 05:13:32 -0400122class _Default:
Gavin Makea2e3302023-03-11 06:46:20 +0000123 """Project defaults within the manifest."""
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700124
Gavin Makea2e3302023-03-11 06:46:20 +0000125 revisionExpr = None
126 destBranchExpr = None
127 upstreamExpr = None
128 remote = None
129 sync_j = None
130 sync_c = False
131 sync_s = False
132 sync_tags = True
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700133
Gavin Makea2e3302023-03-11 06:46:20 +0000134 def __eq__(self, other):
135 if not isinstance(other, _Default):
136 return False
137 return self.__dict__ == other.__dict__
Julien Campergue74879922013-10-09 14:38:46 +0200138
Gavin Makea2e3302023-03-11 06:46:20 +0000139 def __ne__(self, other):
140 if not isinstance(other, _Default):
141 return True
142 return self.__dict__ != other.__dict__
Julien Campergue74879922013-10-09 14:38:46 +0200143
David Pursehouse819827a2020-02-12 15:20:19 +0900144
Mike Frysingerd4aee652023-10-19 05:13:32 -0400145class _XmlRemote:
Gavin Makea2e3302023-03-11 06:46:20 +0000146 def __init__(
147 self,
148 name,
149 alias=None,
150 fetch=None,
151 pushUrl=None,
152 manifestUrl=None,
153 review=None,
154 revision=None,
155 ):
156 self.name = name
157 self.fetchUrl = fetch
158 self.pushUrl = pushUrl
159 self.manifestUrl = manifestUrl
160 self.remoteAlias = alias
161 self.reviewUrl = review
162 self.revision = revision
163 self.resolvedFetchUrl = self._resolveFetchUrl()
164 self.annotations = []
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700165
Gavin Makea2e3302023-03-11 06:46:20 +0000166 def __eq__(self, other):
167 if not isinstance(other, _XmlRemote):
168 return False
169 return (
170 sorted(self.annotations) == sorted(other.annotations)
171 and self.name == other.name
172 and self.fetchUrl == other.fetchUrl
173 and self.pushUrl == other.pushUrl
174 and self.remoteAlias == other.remoteAlias
175 and self.reviewUrl == other.reviewUrl
176 and self.revision == other.revision
177 )
David Pursehouse717ece92012-11-13 08:49:16 +0900178
Gavin Makea2e3302023-03-11 06:46:20 +0000179 def __ne__(self, other):
180 return not self.__eq__(other)
David Pursehouse717ece92012-11-13 08:49:16 +0900181
Gavin Makea2e3302023-03-11 06:46:20 +0000182 def _resolveFetchUrl(self):
183 if self.fetchUrl is None:
184 return ""
185 url = self.fetchUrl.rstrip("/")
186 manifestUrl = self.manifestUrl.rstrip("/")
187 # urljoin will gets confused over quite a few things. The ones we care
188 # about here are:
189 # * no scheme in the base url, like <hostname:port>
190 # We handle no scheme by replacing it with an obscure protocol, gopher
191 # and then replacing it with the original when we are done.
Anthony Kingcb07ba72015-03-28 23:26:04 +0000192
Gavin Makea2e3302023-03-11 06:46:20 +0000193 if manifestUrl.find(":") != manifestUrl.find("/") - 1:
194 url = urllib.parse.urljoin("gopher://" + manifestUrl, url)
195 url = re.sub(r"^gopher://", "", url)
196 else:
197 url = urllib.parse.urljoin(manifestUrl, url)
198 return url
Conley Owensceea3682011-10-20 10:45:47 -0700199
Gavin Makea2e3302023-03-11 06:46:20 +0000200 def ToRemoteSpec(self, projectName):
201 fetchUrl = self.resolvedFetchUrl.rstrip("/")
202 url = fetchUrl + "/" + projectName
203 remoteName = self.name
204 if self.remoteAlias:
205 remoteName = self.remoteAlias
206 return RemoteSpec(
207 remoteName,
208 url=url,
209 pushUrl=self.pushUrl,
210 review=self.reviewUrl,
211 orig_name=self.name,
212 fetchUrl=self.fetchUrl,
213 )
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700214
Gavin Makea2e3302023-03-11 06:46:20 +0000215 def AddAnnotation(self, name, value, keep):
216 self.annotations.append(Annotation(name, value, keep))
Jack Neus6ea0cae2021-07-20 20:52:33 +0000217
David Pursehouse819827a2020-02-12 15:20:19 +0900218
LaMont Jonescc879a92021-11-18 22:40:18 +0000219class _XmlSubmanifest:
Gavin Makea2e3302023-03-11 06:46:20 +0000220 """Manage the <submanifest> element specified in the manifest.
LaMont Jonescc879a92021-11-18 22:40:18 +0000221
Gavin Makea2e3302023-03-11 06:46:20 +0000222 Attributes:
223 name: a string, the name for this submanifest.
224 remote: a string, the remote.name for this submanifest.
225 project: a string, the name of the manifest project.
226 revision: a string, the commitish.
227 manifestName: a string, the submanifest file name.
228 groups: a list of strings, the groups to add to all projects in the
229 submanifest.
230 default_groups: a list of strings, the default groups to sync.
231 path: a string, the relative path for the submanifest checkout.
232 parent: an XmlManifest, the parent manifest.
233 annotations: (derived) a list of annotations.
234 present: (derived) a boolean, whether the sub manifest file is present.
235 """
LaMont Jonescc879a92021-11-18 22:40:18 +0000236
Gavin Makea2e3302023-03-11 06:46:20 +0000237 def __init__(
238 self,
239 name,
240 remote=None,
241 project=None,
242 revision=None,
243 manifestName=None,
244 groups=None,
245 default_groups=None,
246 path=None,
247 parent=None,
248 ):
249 self.name = name
250 self.remote = remote
251 self.project = project
252 self.revision = revision
253 self.manifestName = manifestName
254 self.groups = groups
255 self.default_groups = default_groups
256 self.path = path
257 self.parent = parent
258 self.annotations = []
259 outer_client = parent._outer_client or parent
260 if self.remote and not self.project:
261 raise ManifestParseError(
262 f"Submanifest {name}: must specify project when remote is "
263 "given."
264 )
265 # Construct the absolute path to the manifest file using the parent's
266 # method, so that we can correctly create our repo_client.
267 manifestFile = parent.SubmanifestInfoDir(
268 os.path.join(parent.path_prefix, self.relpath),
269 os.path.join("manifests", manifestName or "default.xml"),
270 )
271 linkFile = parent.SubmanifestInfoDir(
272 os.path.join(parent.path_prefix, self.relpath), MANIFEST_FILE_NAME
273 )
274 self.repo_client = RepoClient(
275 parent.repodir,
276 linkFile,
277 parent_groups=",".join(groups) or "",
278 submanifest_path=self.relpath,
279 outer_client=outer_client,
280 default_groups=default_groups,
281 )
LaMont Jonescc879a92021-11-18 22:40:18 +0000282
Gavin Makea2e3302023-03-11 06:46:20 +0000283 self.present = os.path.exists(manifestFile)
LaMont Jonescc879a92021-11-18 22:40:18 +0000284
Gavin Makea2e3302023-03-11 06:46:20 +0000285 def __eq__(self, other):
286 if not isinstance(other, _XmlSubmanifest):
287 return False
288 return (
289 self.name == other.name
290 and self.remote == other.remote
291 and self.project == other.project
292 and self.revision == other.revision
293 and self.manifestName == other.manifestName
294 and self.groups == other.groups
295 and self.default_groups == other.default_groups
296 and self.path == other.path
297 and sorted(self.annotations) == sorted(other.annotations)
298 )
LaMont Jonescc879a92021-11-18 22:40:18 +0000299
Gavin Makea2e3302023-03-11 06:46:20 +0000300 def __ne__(self, other):
301 return not self.__eq__(other)
LaMont Jonescc879a92021-11-18 22:40:18 +0000302
Gavin Makea2e3302023-03-11 06:46:20 +0000303 def ToSubmanifestSpec(self):
304 """Return a SubmanifestSpec object, populating attributes"""
305 mp = self.parent.manifestProject
306 remote = self.parent.remotes[
307 self.remote or self.parent.default.remote.name
308 ]
309 # If a project was given, generate the url from the remote and project.
310 # If not, use this manifestProject's url.
311 if self.project:
312 manifestUrl = remote.ToRemoteSpec(self.project).url
313 else:
314 manifestUrl = mp.GetRemote().url
315 manifestName = self.manifestName or "default.xml"
316 revision = self.revision or self.name
317 path = self.path or revision.split("/")[-1]
318 groups = self.groups or []
LaMont Jonescc879a92021-11-18 22:40:18 +0000319
Gavin Makea2e3302023-03-11 06:46:20 +0000320 return SubmanifestSpec(
321 self.name, manifestUrl, manifestName, revision, path, groups
322 )
LaMont Jonescc879a92021-11-18 22:40:18 +0000323
Gavin Makea2e3302023-03-11 06:46:20 +0000324 @property
325 def relpath(self):
326 """The path of this submanifest relative to the parent manifest."""
327 revision = self.revision or self.name
328 return self.path or revision.split("/")[-1]
LaMont Jonescc879a92021-11-18 22:40:18 +0000329
Gavin Makea2e3302023-03-11 06:46:20 +0000330 def GetGroupsStr(self):
331 """Returns the `groups` given for this submanifest."""
332 if self.groups:
333 return ",".join(self.groups)
334 return ""
LaMont Jones501733c2022-04-20 16:42:32 +0000335
Gavin Makea2e3302023-03-11 06:46:20 +0000336 def GetDefaultGroupsStr(self):
337 """Returns the `default-groups` given for this submanifest."""
338 return ",".join(self.default_groups or [])
339
340 def AddAnnotation(self, name, value, keep):
341 """Add annotations to the submanifest."""
342 self.annotations.append(Annotation(name, value, keep))
LaMont Jonescc879a92021-11-18 22:40:18 +0000343
344
345class SubmanifestSpec:
Gavin Makea2e3302023-03-11 06:46:20 +0000346 """The submanifest element, with all fields expanded."""
LaMont Jonescc879a92021-11-18 22:40:18 +0000347
Gavin Makea2e3302023-03-11 06:46:20 +0000348 def __init__(self, name, manifestUrl, manifestName, revision, path, groups):
349 self.name = name
350 self.manifestUrl = manifestUrl
351 self.manifestName = manifestName
352 self.revision = revision
353 self.path = path
354 self.groups = groups or []
LaMont Jonescc879a92021-11-18 22:40:18 +0000355
356
Mike Frysingerd4aee652023-10-19 05:13:32 -0400357class XmlManifest:
Gavin Makea2e3302023-03-11 06:46:20 +0000358 """manages the repo configuration file"""
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700359
Gavin Makea2e3302023-03-11 06:46:20 +0000360 def __init__(
361 self,
362 repodir,
363 manifest_file,
364 local_manifests=None,
365 outer_client=None,
366 parent_groups="",
367 submanifest_path="",
368 default_groups=None,
369 ):
370 """Initialize.
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400371
Gavin Makea2e3302023-03-11 06:46:20 +0000372 Args:
373 repodir: Path to the .repo/ dir for holding all internal checkout
374 state. It must be in the top directory of the repo client
375 checkout.
376 manifest_file: Full path to the manifest file to parse. This will
377 usually be |repodir|/|MANIFEST_FILE_NAME|.
378 local_manifests: Full path to the directory of local override
379 manifests. This will usually be
380 |repodir|/|LOCAL_MANIFESTS_DIR_NAME|.
381 outer_client: RepoClient of the outer manifest.
382 parent_groups: a string, the groups to apply to this projects.
383 submanifest_path: The submanifest root relative to the repo root.
384 default_groups: a string, the default manifest groups to use.
385 """
386 # TODO(vapier): Move this out of this class.
387 self.globalConfig = GitConfig.ForUser()
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400388
Gavin Makea2e3302023-03-11 06:46:20 +0000389 self.repodir = os.path.abspath(repodir)
390 self._CheckLocalPath(submanifest_path)
391 self.topdir = os.path.dirname(self.repodir)
392 if submanifest_path:
393 # This avoids a trailing os.path.sep when submanifest_path is empty.
394 self.topdir = os.path.join(self.topdir, submanifest_path)
395 if manifest_file != os.path.abspath(manifest_file):
396 raise ManifestParseError("manifest_file must be abspath")
397 self.manifestFile = manifest_file
398 if not outer_client or outer_client == self:
399 # manifestFileOverrides only exists in the outer_client's manifest,
400 # since that is the only instance left when Unload() is called on
401 # the outer manifest.
402 self.manifestFileOverrides = {}
403 self.local_manifests = local_manifests
404 self._load_local_manifests = True
405 self.parent_groups = parent_groups
406 self.default_groups = default_groups
LaMont Jonescc879a92021-11-18 22:40:18 +0000407
Gavin Makea2e3302023-03-11 06:46:20 +0000408 if outer_client and self.isGitcClient:
409 raise ManifestParseError(
410 "Multi-manifest is incompatible with `gitc-init`"
411 )
LaMont Jonescc879a92021-11-18 22:40:18 +0000412
Gavin Makea2e3302023-03-11 06:46:20 +0000413 if submanifest_path and not outer_client:
414 # If passing a submanifest_path, there must be an outer_client.
415 raise ManifestParseError(f"Bad call to {self.__class__.__name__}")
LaMont Jonescc879a92021-11-18 22:40:18 +0000416
Gavin Makea2e3302023-03-11 06:46:20 +0000417 # If self._outer_client is None, this is not a checkout that supports
418 # multi-tree.
419 self._outer_client = outer_client or self
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700420
Gavin Makea2e3302023-03-11 06:46:20 +0000421 self.repoProject = RepoProject(
422 self,
423 "repo",
424 gitdir=os.path.join(repodir, "repo/.git"),
425 worktree=os.path.join(repodir, "repo"),
426 )
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700427
Gavin Makea2e3302023-03-11 06:46:20 +0000428 mp = self.SubmanifestProject(self.path_prefix)
429 self.manifestProject = mp
Mike Frysinger979d5bd2020-02-09 02:28:34 -0500430
Gavin Makea2e3302023-03-11 06:46:20 +0000431 # This is a bit hacky, but we're in a chicken & egg situation: all the
432 # normal repo settings live in the manifestProject which we just setup
433 # above, so we couldn't easily query before that. We assume Project()
434 # init doesn't care if this changes afterwards.
435 if os.path.exists(mp.gitdir) and mp.use_worktree:
436 mp.use_git_worktrees = True
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700437
Gavin Makea2e3302023-03-11 06:46:20 +0000438 self.Unload()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700439
Gavin Makea2e3302023-03-11 06:46:20 +0000440 def Override(self, name, load_local_manifests=True):
441 """Use a different manifest, just for the current instantiation."""
442 path = None
Basil Gelloc7453502018-05-25 20:23:52 +0300443
Gavin Makea2e3302023-03-11 06:46:20 +0000444 # Look for a manifest by path in the filesystem (including the cwd).
445 if not load_local_manifests:
446 local_path = os.path.abspath(name)
447 if os.path.isfile(local_path):
448 path = local_path
Basil Gelloc7453502018-05-25 20:23:52 +0300449
Gavin Makea2e3302023-03-11 06:46:20 +0000450 # Look for manifests by name from the manifests repo.
451 if path is None:
452 path = os.path.join(self.manifestProject.worktree, name)
453 if not os.path.isfile(path):
454 raise ManifestParseError("manifest %s not found" % name)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700455
Gavin Makea2e3302023-03-11 06:46:20 +0000456 self._load_local_manifests = load_local_manifests
457 self._outer_client.manifestFileOverrides[self.path_prefix] = path
458 self.Unload()
459 self._Load()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700460
Gavin Makea2e3302023-03-11 06:46:20 +0000461 def Link(self, name):
462 """Update the repo metadata to use a different manifest."""
463 self.Override(name)
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700464
Gavin Makea2e3302023-03-11 06:46:20 +0000465 # Old versions of repo would generate symlinks we need to clean up.
466 platform_utils.remove(self.manifestFile, missing_ok=True)
467 # This file is interpreted as if it existed inside the manifest repo.
468 # That allows us to use <include> with the relative file name.
469 with open(self.manifestFile, "w") as fp:
470 fp.write(
471 """<?xml version="1.0" encoding="UTF-8"?>
Mike Frysingera269b1c2020-02-21 00:49:41 -0500472<!--
473DO NOT EDIT THIS FILE! It is generated by repo and changes will be discarded.
474If you want to use a different manifest, use `repo init -m <file>` instead.
475
476If you want to customize your checkout by overriding manifest settings, use
477the local_manifests/ directory instead.
478
479For more information on repo manifests, check out:
480https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
481-->
482<manifest>
483 <include name="%s" />
484</manifest>
Gavin Makea2e3302023-03-11 06:46:20 +0000485"""
486 % (name,)
487 )
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700488
Gavin Makea2e3302023-03-11 06:46:20 +0000489 def _RemoteToXml(self, r, doc, root):
490 e = doc.createElement("remote")
491 root.appendChild(e)
492 e.setAttribute("name", r.name)
493 e.setAttribute("fetch", r.fetchUrl)
494 if r.pushUrl is not None:
495 e.setAttribute("pushurl", r.pushUrl)
496 if r.remoteAlias is not None:
497 e.setAttribute("alias", r.remoteAlias)
498 if r.reviewUrl is not None:
499 e.setAttribute("review", r.reviewUrl)
500 if r.revision is not None:
501 e.setAttribute("revision", r.revision)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800502
Gavin Makea2e3302023-03-11 06:46:20 +0000503 for a in r.annotations:
504 if a.keep == "true":
505 ae = doc.createElement("annotation")
506 ae.setAttribute("name", a.name)
507 ae.setAttribute("value", a.value)
508 e.appendChild(ae)
Jack Neus6ea0cae2021-07-20 20:52:33 +0000509
Gavin Makea2e3302023-03-11 06:46:20 +0000510 def _SubmanifestToXml(self, r, doc, root):
511 """Generate XML <submanifest/> node."""
512 e = doc.createElement("submanifest")
513 root.appendChild(e)
514 e.setAttribute("name", r.name)
515 if r.remote is not None:
516 e.setAttribute("remote", r.remote)
517 if r.project is not None:
518 e.setAttribute("project", r.project)
519 if r.manifestName is not None:
520 e.setAttribute("manifest-name", r.manifestName)
521 if r.revision is not None:
522 e.setAttribute("revision", r.revision)
523 if r.path is not None:
524 e.setAttribute("path", r.path)
525 if r.groups:
526 e.setAttribute("groups", r.GetGroupsStr())
527 if r.default_groups:
528 e.setAttribute("default-groups", r.GetDefaultGroupsStr())
LaMont Jonescc879a92021-11-18 22:40:18 +0000529
Gavin Makea2e3302023-03-11 06:46:20 +0000530 for a in r.annotations:
531 if a.keep == "true":
532 ae = doc.createElement("annotation")
533 ae.setAttribute("name", a.name)
534 ae.setAttribute("value", a.value)
535 e.appendChild(ae)
LaMont Jonescc879a92021-11-18 22:40:18 +0000536
Gavin Makea2e3302023-03-11 06:46:20 +0000537 def _ParseList(self, field):
538 """Parse fields that contain flattened lists.
Mike Frysinger51e39d52020-12-04 05:32:06 -0500539
Gavin Makea2e3302023-03-11 06:46:20 +0000540 These are whitespace & comma separated. Empty elements will be
541 discarded.
542 """
543 return [x for x in re.split(r"[,\s]+", field) if x]
Josh Triplett884a3872014-06-12 14:57:29 -0700544
Gavin Makea2e3302023-03-11 06:46:20 +0000545 def ToXml(
546 self,
547 peg_rev=False,
548 peg_rev_upstream=True,
549 peg_rev_dest_branch=True,
550 groups=None,
551 omit_local=False,
552 ):
553 """Return the current manifest XML."""
554 mp = self.manifestProject
Colin Cross5acde752012-03-28 20:15:45 -0700555
Gavin Makea2e3302023-03-11 06:46:20 +0000556 if groups is None:
557 groups = mp.manifest_groups
558 if groups:
559 groups = self._ParseList(groups)
Colin Cross5acde752012-03-28 20:15:45 -0700560
Gavin Makea2e3302023-03-11 06:46:20 +0000561 doc = xml.dom.minidom.Document()
562 root = doc.createElement("manifest")
563 if self.is_submanifest:
564 root.setAttribute("path", self.path_prefix)
565 doc.appendChild(root)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800566
Gavin Makea2e3302023-03-11 06:46:20 +0000567 # Save out the notice. There's a little bit of work here to give it the
568 # right whitespace, which assumes that the notice is automatically
569 # indented by 4 by minidom.
570 if self.notice:
571 notice_element = root.appendChild(doc.createElement("notice"))
572 notice_lines = self.notice.splitlines()
573 indented_notice = (
574 "\n".join(" " * 4 + line for line in notice_lines)
575 )[4:]
576 notice_element.appendChild(doc.createTextNode(indented_notice))
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700577
Gavin Makea2e3302023-03-11 06:46:20 +0000578 d = self.default
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800579
Gavin Makea2e3302023-03-11 06:46:20 +0000580 for r in sorted(self.remotes):
581 self._RemoteToXml(self.remotes[r], doc, root)
582 if self.remotes:
583 root.appendChild(doc.createTextNode(""))
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800584
Gavin Makea2e3302023-03-11 06:46:20 +0000585 have_default = False
586 e = doc.createElement("default")
587 if d.remote:
588 have_default = True
589 e.setAttribute("remote", d.remote.name)
590 if d.revisionExpr:
591 have_default = True
592 e.setAttribute("revision", d.revisionExpr)
593 if d.destBranchExpr:
594 have_default = True
595 e.setAttribute("dest-branch", d.destBranchExpr)
596 if d.upstreamExpr:
597 have_default = True
598 e.setAttribute("upstream", d.upstreamExpr)
599 if d.sync_j is not None:
600 have_default = True
601 e.setAttribute("sync-j", "%d" % d.sync_j)
602 if d.sync_c:
603 have_default = True
604 e.setAttribute("sync-c", "true")
605 if d.sync_s:
606 have_default = True
607 e.setAttribute("sync-s", "true")
608 if not d.sync_tags:
609 have_default = True
610 e.setAttribute("sync-tags", "false")
611 if have_default:
612 root.appendChild(e)
613 root.appendChild(doc.createTextNode(""))
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800614
Gavin Makea2e3302023-03-11 06:46:20 +0000615 if self._manifest_server:
616 e = doc.createElement("manifest-server")
617 e.setAttribute("url", self._manifest_server)
618 root.appendChild(e)
619 root.appendChild(doc.createTextNode(""))
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700620
Gavin Makea2e3302023-03-11 06:46:20 +0000621 for r in sorted(self.submanifests):
622 self._SubmanifestToXml(self.submanifests[r], doc, root)
623 if self.submanifests:
624 root.appendChild(doc.createTextNode(""))
LaMont Jonescc879a92021-11-18 22:40:18 +0000625
Gavin Makea2e3302023-03-11 06:46:20 +0000626 def output_projects(parent, parent_node, projects):
627 for project_name in projects:
628 for project in self._projects[project_name]:
629 output_project(parent, parent_node, project)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800630
Gavin Makea2e3302023-03-11 06:46:20 +0000631 def output_project(parent, parent_node, p):
632 if not p.MatchesGroups(groups):
633 return
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800634
Gavin Makea2e3302023-03-11 06:46:20 +0000635 if omit_local and self.IsFromLocalManifest(p):
636 return
LaMont Jonesa8cf5752022-07-15 20:31:33 +0000637
Gavin Makea2e3302023-03-11 06:46:20 +0000638 name = p.name
639 relpath = p.relpath
640 if parent:
641 name = self._UnjoinName(parent.name, name)
642 relpath = self._UnjoinRelpath(parent.relpath, relpath)
Colin Cross5acde752012-03-28 20:15:45 -0700643
Gavin Makea2e3302023-03-11 06:46:20 +0000644 e = doc.createElement("project")
645 parent_node.appendChild(e)
646 e.setAttribute("name", name)
647 if relpath != name:
648 e.setAttribute("path", relpath)
649 remoteName = None
650 if d.remote:
651 remoteName = d.remote.name
652 if not d.remote or p.remote.orig_name != remoteName:
653 remoteName = p.remote.orig_name
654 e.setAttribute("remote", remoteName)
655 if peg_rev:
656 if self.IsMirror:
657 value = p.bare_git.rev_parse(p.revisionExpr + "^0")
658 else:
659 value = p.work_git.rev_parse(HEAD + "^0")
660 e.setAttribute("revision", value)
661 if peg_rev_upstream:
662 if p.upstream:
663 e.setAttribute("upstream", p.upstream)
664 elif value != p.revisionExpr:
665 # Only save the origin if the origin is not a sha1, and
666 # the default isn't our value
667 e.setAttribute("upstream", p.revisionExpr)
668
669 if peg_rev_dest_branch:
670 if p.dest_branch:
671 e.setAttribute("dest-branch", p.dest_branch)
672 elif value != p.revisionExpr:
673 e.setAttribute("dest-branch", p.revisionExpr)
674
675 else:
676 revision = (
677 self.remotes[p.remote.orig_name].revision or d.revisionExpr
678 )
679 if not revision or revision != p.revisionExpr:
680 e.setAttribute("revision", p.revisionExpr)
681 elif p.revisionId:
682 e.setAttribute("revision", p.revisionId)
683 if p.upstream and (
684 p.upstream != p.revisionExpr or p.upstream != d.upstreamExpr
685 ):
686 e.setAttribute("upstream", p.upstream)
687
688 if p.dest_branch and p.dest_branch != d.destBranchExpr:
689 e.setAttribute("dest-branch", p.dest_branch)
690
691 for c in p.copyfiles:
692 ce = doc.createElement("copyfile")
693 ce.setAttribute("src", c.src)
694 ce.setAttribute("dest", c.dest)
695 e.appendChild(ce)
696
697 for lf in p.linkfiles:
698 le = doc.createElement("linkfile")
699 le.setAttribute("src", lf.src)
700 le.setAttribute("dest", lf.dest)
701 e.appendChild(le)
702
703 default_groups = ["all", "name:%s" % p.name, "path:%s" % p.relpath]
704 egroups = [g for g in p.groups if g not in default_groups]
705 if egroups:
706 e.setAttribute("groups", ",".join(egroups))
707
708 for a in p.annotations:
709 if a.keep == "true":
710 ae = doc.createElement("annotation")
711 ae.setAttribute("name", a.name)
712 ae.setAttribute("value", a.value)
713 e.appendChild(ae)
714
715 if p.sync_c:
716 e.setAttribute("sync-c", "true")
717
718 if p.sync_s:
719 e.setAttribute("sync-s", "true")
720
721 if not p.sync_tags:
722 e.setAttribute("sync-tags", "false")
723
724 if p.clone_depth:
725 e.setAttribute("clone-depth", str(p.clone_depth))
726
727 self._output_manifest_project_extras(p, e)
728
729 if p.subprojects:
730 subprojects = set(subp.name for subp in p.subprojects)
731 output_projects(p, e, list(sorted(subprojects)))
732
733 projects = set(p.name for p in self._paths.values() if not p.parent)
734 output_projects(None, root, list(sorted(projects)))
735
736 if self._repo_hooks_project:
737 root.appendChild(doc.createTextNode(""))
738 e = doc.createElement("repo-hooks")
739 e.setAttribute("in-project", self._repo_hooks_project.name)
740 e.setAttribute(
741 "enabled-list",
742 " ".join(self._repo_hooks_project.enabled_repo_hooks),
743 )
744 root.appendChild(e)
745
746 if self._superproject:
747 root.appendChild(doc.createTextNode(""))
748 e = doc.createElement("superproject")
749 e.setAttribute("name", self._superproject.name)
750 remoteName = None
751 if d.remote:
752 remoteName = d.remote.name
753 remote = self._superproject.remote
754 if not d.remote or remote.orig_name != remoteName:
755 remoteName = remote.orig_name
756 e.setAttribute("remote", remoteName)
757 revision = remote.revision or d.revisionExpr
758 if not revision or revision != self._superproject.revision:
759 e.setAttribute("revision", self._superproject.revision)
760 root.appendChild(e)
761
762 if self._contactinfo.bugurl != Wrapper().BUG_URL:
763 root.appendChild(doc.createTextNode(""))
764 e = doc.createElement("contactinfo")
765 e.setAttribute("bugurl", self._contactinfo.bugurl)
766 root.appendChild(e)
767
768 return doc
769
770 def ToDict(self, **kwargs):
771 """Return the current manifest as a dictionary."""
772 # Elements that may only appear once.
773 SINGLE_ELEMENTS = {
774 "notice",
775 "default",
776 "manifest-server",
777 "repo-hooks",
778 "superproject",
779 "contactinfo",
780 }
781 # Elements that may be repeated.
782 MULTI_ELEMENTS = {
783 "remote",
784 "remove-project",
785 "project",
786 "extend-project",
787 "include",
788 "submanifest",
789 # These are children of 'project' nodes.
790 "annotation",
791 "project",
792 "copyfile",
793 "linkfile",
794 }
795
796 doc = self.ToXml(**kwargs)
797 ret = {}
798
799 def append_children(ret, node):
800 for child in node.childNodes:
801 if child.nodeType == xml.dom.Node.ELEMENT_NODE:
802 attrs = child.attributes
803 element = dict(
804 (attrs.item(i).localName, attrs.item(i).value)
805 for i in range(attrs.length)
806 )
807 if child.nodeName in SINGLE_ELEMENTS:
808 ret[child.nodeName] = element
809 elif child.nodeName in MULTI_ELEMENTS:
810 ret.setdefault(child.nodeName, []).append(element)
811 else:
812 raise ManifestParseError(
813 'Unhandled element "%s"' % (child.nodeName,)
814 )
815
816 append_children(element, child)
817
818 append_children(ret, doc.firstChild)
819
820 return ret
821
822 def Save(self, fd, **kwargs):
823 """Write the current manifest out to the given file descriptor."""
824 doc = self.ToXml(**kwargs)
825 doc.writexml(fd, "", " ", "\n", "UTF-8")
826
827 def _output_manifest_project_extras(self, p, e):
828 """Manifests can modify e if they support extra project attributes."""
829
830 @property
831 def is_multimanifest(self):
832 """Whether this is a multimanifest checkout.
833
834 This is safe to use as long as the outermost manifest XML has been
835 parsed.
836 """
837 return bool(self._outer_client._submanifests)
838
839 @property
840 def is_submanifest(self):
841 """Whether this manifest is a submanifest.
842
843 This is safe to use as long as the outermost manifest XML has been
844 parsed.
845 """
846 return self._outer_client and self._outer_client != self
847
848 @property
849 def outer_client(self):
850 """The instance of the outermost manifest client."""
851 self._Load()
852 return self._outer_client
853
854 @property
855 def all_manifests(self):
856 """Generator yielding all (sub)manifests, in depth-first order."""
857 self._Load()
858 outer = self._outer_client
859 yield outer
Jason R. Coombs8dd85212023-10-20 06:48:20 -0400860 yield from outer.all_children
Gavin Makea2e3302023-03-11 06:46:20 +0000861
862 @property
863 def all_children(self):
864 """Generator yielding all (present) child submanifests."""
865 self._Load()
866 for child in self._submanifests.values():
867 if child.repo_client:
868 yield child.repo_client
Jason R. Coombs8dd85212023-10-20 06:48:20 -0400869 yield from child.repo_client.all_children
Gavin Makea2e3302023-03-11 06:46:20 +0000870
871 @property
872 def path_prefix(self):
873 """The path of this submanifest, relative to the outermost manifest."""
874 if not self._outer_client or self == self._outer_client:
875 return ""
876 return os.path.relpath(self.topdir, self._outer_client.topdir)
877
878 @property
879 def all_paths(self):
880 """All project paths for all (sub)manifests.
881
882 See also `paths`.
883
884 Returns:
885 A dictionary of {path: Project()}. `path` is relative to the outer
886 manifest.
887 """
888 ret = {}
889 for tree in self.all_manifests:
890 prefix = tree.path_prefix
891 ret.update(
892 {os.path.join(prefix, k): v for k, v in tree.paths.items()}
893 )
894 return ret
895
896 @property
897 def all_projects(self):
898 """All projects for all (sub)manifests. See `projects`."""
899 return list(
900 itertools.chain.from_iterable(
901 x._paths.values() for x in self.all_manifests
902 )
903 )
904
905 @property
906 def paths(self):
907 """Return all paths for this manifest.
908
909 Returns:
910 A dictionary of {path: Project()}. `path` is relative to this
911 manifest.
912 """
913 self._Load()
914 return self._paths
915
916 @property
917 def projects(self):
918 """Return a list of all Projects in this manifest."""
919 self._Load()
920 return list(self._paths.values())
921
922 @property
923 def remotes(self):
924 """Return a list of remotes for this manifest."""
925 self._Load()
926 return self._remotes
927
928 @property
929 def default(self):
930 """Return default values for this manifest."""
931 self._Load()
932 return self._default
933
934 @property
935 def submanifests(self):
936 """All submanifests in this manifest."""
937 self._Load()
938 return self._submanifests
939
940 @property
941 def repo_hooks_project(self):
942 self._Load()
943 return self._repo_hooks_project
944
945 @property
946 def superproject(self):
947 self._Load()
948 return self._superproject
949
950 @property
951 def contactinfo(self):
952 self._Load()
953 return self._contactinfo
954
955 @property
956 def notice(self):
957 self._Load()
958 return self._notice
959
960 @property
961 def manifest_server(self):
962 self._Load()
963 return self._manifest_server
964
965 @property
966 def CloneBundle(self):
967 clone_bundle = self.manifestProject.clone_bundle
968 if clone_bundle is None:
969 return False if self.manifestProject.partial_clone else True
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800970 else:
Gavin Makea2e3302023-03-11 06:46:20 +0000971 return clone_bundle
Sean McAllisteraf908cb2020-04-20 08:41:58 -0600972
Gavin Makea2e3302023-03-11 06:46:20 +0000973 @property
974 def CloneFilter(self):
975 if self.manifestProject.partial_clone:
976 return self.manifestProject.clone_filter
977 return None
Sean McAllisteraf908cb2020-04-20 08:41:58 -0600978
Gavin Makea2e3302023-03-11 06:46:20 +0000979 @property
Jason Chang17833322023-05-23 13:06:55 -0700980 def CloneFilterForDepth(self):
981 if self.manifestProject.clone_filter_for_depth:
982 return self.manifestProject.clone_filter_for_depth
983 return None
984
985 @property
Gavin Makea2e3302023-03-11 06:46:20 +0000986 def PartialCloneExclude(self):
987 exclude = self.manifest.manifestProject.partial_clone_exclude or ""
988 return set(x.strip() for x in exclude.split(","))
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800989
Gavin Makea2e3302023-03-11 06:46:20 +0000990 def SetManifestOverride(self, path):
991 """Override manifestFile. The caller must call Unload()"""
992 self._outer_client.manifest.manifestFileOverrides[
993 self.path_prefix
994 ] = path
Simon Ruggier7e59de22015-07-24 12:50:06 +0200995
Gavin Makea2e3302023-03-11 06:46:20 +0000996 @property
997 def UseLocalManifests(self):
998 return self._load_local_manifests
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800999
Gavin Makea2e3302023-03-11 06:46:20 +00001000 def SetUseLocalManifests(self, value):
1001 self._load_local_manifests = value
Jeff Hamiltone0df2322014-04-21 17:10:59 -05001002
Gavin Makea2e3302023-03-11 06:46:20 +00001003 @property
1004 def HasLocalManifests(self):
1005 return self._load_local_manifests and self.local_manifests
Colin Cross5acde752012-03-28 20:15:45 -07001006
Gavin Makea2e3302023-03-11 06:46:20 +00001007 def IsFromLocalManifest(self, project):
1008 """Is the project from a local manifest?"""
1009 return any(
1010 x.startswith(LOCAL_MANIFEST_GROUP_PREFIX) for x in project.groups
1011 )
James W. Mills24c13082012-04-12 15:04:13 -05001012
Gavin Makea2e3302023-03-11 06:46:20 +00001013 @property
1014 def IsMirror(self):
1015 return self.manifestProject.mirror
Anatol Pomazau79770d22012-04-20 14:41:59 -07001016
Gavin Makea2e3302023-03-11 06:46:20 +00001017 @property
1018 def UseGitWorktrees(self):
1019 return self.manifestProject.use_worktree
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001020
Gavin Makea2e3302023-03-11 06:46:20 +00001021 @property
1022 def IsArchive(self):
1023 return self.manifestProject.archive
YOUNG HO CHAa32c92c2018-02-14 16:57:31 +09001024
Gavin Makea2e3302023-03-11 06:46:20 +00001025 @property
1026 def HasSubmodules(self):
1027 return self.manifestProject.submodules
Dan Willemsen88409222015-08-17 15:29:10 -07001028
Gavin Makea2e3302023-03-11 06:46:20 +00001029 @property
1030 def EnableGitLfs(self):
1031 return self.manifestProject.git_lfs
Simran Basib9a1b732015-08-20 12:19:28 -07001032
Gavin Makea2e3302023-03-11 06:46:20 +00001033 def FindManifestByPath(self, path):
1034 """Returns the manifest containing path."""
1035 path = os.path.abspath(path)
1036 manifest = self._outer_client or self
1037 old = None
1038 while manifest._submanifests and manifest != old:
1039 old = manifest
1040 for name in manifest._submanifests:
1041 tree = manifest._submanifests[name]
1042 if path.startswith(tree.repo_client.manifest.topdir):
1043 manifest = tree.repo_client
1044 break
1045 return manifest
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001046
Gavin Makea2e3302023-03-11 06:46:20 +00001047 @property
1048 def subdir(self):
1049 """Returns the path for per-submanifest objects for this manifest."""
1050 return self.SubmanifestInfoDir(self.path_prefix)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001051
Gavin Makea2e3302023-03-11 06:46:20 +00001052 def SubmanifestInfoDir(self, submanifest_path, object_path=""):
1053 """Return the path to submanifest-specific info for a submanifest.
Doug Anderson37282b42011-03-04 11:54:18 -08001054
Gavin Makea2e3302023-03-11 06:46:20 +00001055 Return the full path of the directory in which to put per-manifest
1056 objects.
Raman Tenneti1bb4fb22021-01-07 16:50:45 -08001057
Gavin Makea2e3302023-03-11 06:46:20 +00001058 Args:
1059 submanifest_path: a string, the path of the submanifest, relative to
1060 the outermost topdir. If empty, then repodir is returned.
1061 object_path: a string, relative path to append to the submanifest
1062 info directory path.
1063 """
1064 if submanifest_path:
1065 return os.path.join(
1066 self.repodir, SUBMANIFEST_DIR, submanifest_path, object_path
1067 )
1068 else:
1069 return os.path.join(self.repodir, object_path)
Raman Tenneti1c3f57e2021-05-04 12:32:13 -07001070
Gavin Makea2e3302023-03-11 06:46:20 +00001071 def SubmanifestProject(self, submanifest_path):
1072 """Return a manifestProject for a submanifest."""
1073 subdir = self.SubmanifestInfoDir(submanifest_path)
1074 mp = ManifestProject(
1075 self,
1076 "manifests",
1077 gitdir=os.path.join(subdir, "manifests.git"),
1078 worktree=os.path.join(subdir, "manifests"),
1079 )
1080 return mp
Mike Frysinger23411d32020-09-02 04:31:10 -04001081
Gavin Makea2e3302023-03-11 06:46:20 +00001082 def GetDefaultGroupsStr(self, with_platform=True):
1083 """Returns the default group string to use.
Mike Frysinger23411d32020-09-02 04:31:10 -04001084
Gavin Makea2e3302023-03-11 06:46:20 +00001085 Args:
1086 with_platform: a boolean, whether to include the group for the
1087 underlying platform.
1088 """
1089 groups = ",".join(self.default_groups or ["default"])
1090 if with_platform:
1091 groups += f",platform-{platform.system().lower()}"
1092 return groups
Mike Frysinger23411d32020-09-02 04:31:10 -04001093
Gavin Makea2e3302023-03-11 06:46:20 +00001094 def GetGroupsStr(self):
1095 """Returns the manifest group string that should be synced."""
1096 return (
1097 self.manifestProject.manifest_groups or self.GetDefaultGroupsStr()
1098 )
Mike Frysinger23411d32020-09-02 04:31:10 -04001099
Gavin Makea2e3302023-03-11 06:46:20 +00001100 def Unload(self):
1101 """Unload the manifest.
Mike Frysinger23411d32020-09-02 04:31:10 -04001102
Gavin Makea2e3302023-03-11 06:46:20 +00001103 If the manifest files have been changed since Load() was called, this
1104 will cause the new/updated manifest to be used.
Mike Frysinger23411d32020-09-02 04:31:10 -04001105
Gavin Makea2e3302023-03-11 06:46:20 +00001106 """
1107 self._loaded = False
1108 self._projects = {}
1109 self._paths = {}
1110 self._remotes = {}
1111 self._default = None
1112 self._submanifests = {}
1113 self._repo_hooks_project = None
1114 self._superproject = None
1115 self._contactinfo = ContactInfo(Wrapper().BUG_URL)
1116 self._notice = None
1117 self.branch = None
1118 self._manifest_server = None
Mike Frysinger23411d32020-09-02 04:31:10 -04001119
Gavin Makea2e3302023-03-11 06:46:20 +00001120 def Load(self):
1121 """Read the manifest into memory."""
1122 # Do not expose internal arguments.
1123 self._Load()
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -08001124
Gavin Makea2e3302023-03-11 06:46:20 +00001125 def _Load(self, initial_client=None, submanifest_depth=0):
1126 if submanifest_depth > MAX_SUBMANIFEST_DEPTH:
1127 raise ManifestParseError(
1128 "maximum submanifest depth %d exceeded." % MAX_SUBMANIFEST_DEPTH
1129 )
1130 if not self._loaded:
1131 if self._outer_client and self._outer_client != self:
1132 # This will load all clients.
1133 self._outer_client._Load(initial_client=self)
Simran Basib9a1b732015-08-20 12:19:28 -07001134
Gavin Makea2e3302023-03-11 06:46:20 +00001135 savedManifestFile = self.manifestFile
1136 override = self._outer_client.manifestFileOverrides.get(
1137 self.path_prefix
1138 )
1139 if override:
1140 self.manifestFile = override
Mike Frysinger1d00a7e2021-12-21 00:40:31 -05001141
Gavin Makea2e3302023-03-11 06:46:20 +00001142 try:
1143 m = self.manifestProject
1144 b = m.GetBranch(m.CurrentBranch).merge
1145 if b is not None and b.startswith(R_HEADS):
1146 b = b[len(R_HEADS) :]
1147 self.branch = b
LaMont Jonescc879a92021-11-18 22:40:18 +00001148
Gavin Makea2e3302023-03-11 06:46:20 +00001149 parent_groups = self.parent_groups
1150 if self.path_prefix:
1151 parent_groups = (
1152 f"{SUBMANIFEST_GROUP_PREFIX}:path:"
1153 f"{self.path_prefix},{parent_groups}"
1154 )
LaMont Jonesff6b1da2022-06-01 21:03:34 +00001155
Gavin Makea2e3302023-03-11 06:46:20 +00001156 # The manifestFile was specified by the user which is why we
1157 # allow include paths to point anywhere.
1158 nodes = []
1159 nodes.append(
1160 self._ParseManifestXml(
1161 self.manifestFile,
1162 self.manifestProject.worktree,
1163 parent_groups=parent_groups,
1164 restrict_includes=False,
1165 )
1166 )
LaMont Jonescc879a92021-11-18 22:40:18 +00001167
Gavin Makea2e3302023-03-11 06:46:20 +00001168 if self._load_local_manifests and self.local_manifests:
1169 try:
1170 for local_file in sorted(
1171 platform_utils.listdir(self.local_manifests)
1172 ):
1173 if local_file.endswith(".xml"):
1174 local = os.path.join(
1175 self.local_manifests, local_file
1176 )
1177 # Since local manifests are entirely managed by
1178 # the user, allow them to point anywhere the
1179 # user wants.
1180 local_group = (
1181 f"{LOCAL_MANIFEST_GROUP_PREFIX}:"
1182 f"{local_file[:-4]}"
1183 )
1184 nodes.append(
1185 self._ParseManifestXml(
1186 local,
1187 self.subdir,
1188 parent_groups=(
1189 f"{local_group},{parent_groups}"
1190 ),
1191 restrict_includes=False,
1192 )
1193 )
1194 except OSError:
1195 pass
Raman Tenneti080877e2021-03-09 15:19:06 -08001196
Gavin Makea2e3302023-03-11 06:46:20 +00001197 try:
1198 self._ParseManifest(nodes)
1199 except ManifestParseError as e:
1200 # There was a problem parsing, unload ourselves in case they
1201 # catch this error and try again later, we will show the
1202 # correct error
1203 self.Unload()
1204 raise e
Raman Tenneti080877e2021-03-09 15:19:06 -08001205
Gavin Makea2e3302023-03-11 06:46:20 +00001206 if self.IsMirror:
1207 self._AddMetaProjectMirror(self.repoProject)
1208 self._AddMetaProjectMirror(self.manifestProject)
LaMont Jonesa2ff20d2022-04-07 16:49:06 +00001209
Gavin Makea2e3302023-03-11 06:46:20 +00001210 self._loaded = True
1211 finally:
1212 if override:
1213 self.manifestFile = savedManifestFile
LaMont Jonesa2ff20d2022-04-07 16:49:06 +00001214
Gavin Makea2e3302023-03-11 06:46:20 +00001215 # Now that we have loaded this manifest, load any submanifests as
1216 # well. We need to do this after self._loaded is set to avoid
1217 # looping.
1218 for name in self._submanifests:
1219 tree = self._submanifests[name]
1220 tree.ToSubmanifestSpec()
1221 present = os.path.exists(
1222 os.path.join(self.subdir, MANIFEST_FILE_NAME)
1223 )
1224 if present and tree.present and not tree.repo_client:
1225 if initial_client and initial_client.topdir == self.topdir:
1226 tree.repo_client = self
1227 tree.present = present
1228 elif not os.path.exists(self.subdir):
1229 tree.present = False
1230 if present and tree.present:
1231 tree.repo_client._Load(
1232 initial_client=initial_client,
1233 submanifest_depth=submanifest_depth + 1,
1234 )
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001235
Gavin Makea2e3302023-03-11 06:46:20 +00001236 def _ParseManifestXml(
Shuchuan Zeng3e3340d2023-04-18 10:36:50 +08001237 self,
1238 path,
1239 include_root,
1240 parent_groups="",
1241 restrict_includes=True,
1242 parent_node=None,
Gavin Makea2e3302023-03-11 06:46:20 +00001243 ):
1244 """Parse a manifest XML and return the computed nodes.
LaMont Jonesa2ff20d2022-04-07 16:49:06 +00001245
Gavin Makea2e3302023-03-11 06:46:20 +00001246 Args:
1247 path: The XML file to read & parse.
1248 include_root: The path to interpret include "name"s relative to.
1249 parent_groups: The groups to apply to this projects.
1250 restrict_includes: Whether to constrain the "name" attribute of
1251 includes.
Shuchuan Zeng3e3340d2023-04-18 10:36:50 +08001252 parent_node: The parent include node, to apply attribute to this
1253 projects.
LaMont Jonescc879a92021-11-18 22:40:18 +00001254
Gavin Makea2e3302023-03-11 06:46:20 +00001255 Returns:
1256 List of XML nodes.
1257 """
1258 try:
1259 root = xml.dom.minidom.parse(path)
1260 except (OSError, xml.parsers.expat.ExpatError) as e:
1261 raise ManifestParseError(
1262 "error parsing manifest %s: %s" % (path, e)
1263 )
David Pursehouse2d5a0df2012-11-13 02:50:36 +09001264
Gavin Makea2e3302023-03-11 06:46:20 +00001265 if not root or not root.childNodes:
1266 raise ManifestParseError("no root node in %s" % (path,))
Shawn O. Pearce5cc66792008-10-23 16:19:27 -07001267
Gavin Makea2e3302023-03-11 06:46:20 +00001268 for manifest in root.childNodes:
1269 if manifest.nodeName == "manifest":
1270 break
1271 else:
1272 raise ManifestParseError("no <manifest> in %s" % (path,))
Shawn O. Pearcee284ad12008-11-04 07:37:10 -08001273
LaMont Jonesb90a4222022-04-14 15:00:09 +00001274 nodes = []
Gavin Makea2e3302023-03-11 06:46:20 +00001275 for node in manifest.childNodes:
1276 if node.nodeName == "include":
1277 name = self._reqatt(node, "name")
1278 if restrict_includes:
1279 msg = self._CheckLocalPath(name)
1280 if msg:
1281 raise ManifestInvalidPathError(
1282 '<include> invalid "name": %s: %s' % (name, msg)
1283 )
1284 include_groups = ""
1285 if parent_groups:
1286 include_groups = parent_groups
1287 if node.hasAttribute("groups"):
1288 include_groups = (
1289 node.getAttribute("groups") + "," + include_groups
1290 )
1291 fp = os.path.join(include_root, name)
1292 if not os.path.isfile(fp):
1293 raise ManifestParseError(
1294 "include [%s/]%s doesn't exist or isn't a file"
1295 % (include_root, name)
1296 )
1297 try:
1298 nodes.extend(
Shuchuan Zeng3e3340d2023-04-18 10:36:50 +08001299 self._ParseManifestXml(
1300 fp, include_root, include_groups, parent_node=node
1301 )
Gavin Makea2e3302023-03-11 06:46:20 +00001302 )
1303 # should isolate this to the exact exception, but that's
1304 # tricky. actual parsing implementation may vary.
1305 except (
1306 KeyboardInterrupt,
1307 RuntimeError,
1308 SystemExit,
1309 ManifestParseError,
1310 ):
1311 raise
1312 except Exception as e:
1313 raise ManifestParseError(
1314 "failed parsing included manifest %s: %s" % (name, e)
1315 )
1316 else:
1317 if parent_groups and node.nodeName == "project":
1318 nodeGroups = parent_groups
1319 if node.hasAttribute("groups"):
1320 nodeGroups = (
1321 node.getAttribute("groups") + "," + nodeGroups
1322 )
1323 node.setAttribute("groups", nodeGroups)
Shuchuan Zeng3e3340d2023-04-18 10:36:50 +08001324 if (
1325 parent_node
1326 and node.nodeName == "project"
1327 and not node.hasAttribute("revision")
1328 ):
1329 node.setAttribute(
1330 "revision", parent_node.getAttribute("revision")
1331 )
Gavin Makea2e3302023-03-11 06:46:20 +00001332 nodes.append(node)
1333 return nodes
LaMont Jonesb90a4222022-04-14 15:00:09 +00001334
Gavin Makea2e3302023-03-11 06:46:20 +00001335 def _ParseManifest(self, node_list):
1336 for node in itertools.chain(*node_list):
1337 if node.nodeName == "remote":
1338 remote = self._ParseRemote(node)
1339 if remote:
1340 if remote.name in self._remotes:
1341 if remote != self._remotes[remote.name]:
1342 raise ManifestParseError(
1343 "remote %s already exists with different "
1344 "attributes" % (remote.name)
1345 )
1346 else:
1347 self._remotes[remote.name] = remote
LaMont Jonesb90a4222022-04-14 15:00:09 +00001348
Gavin Makea2e3302023-03-11 06:46:20 +00001349 for node in itertools.chain(*node_list):
1350 if node.nodeName == "default":
1351 new_default = self._ParseDefault(node)
1352 emptyDefault = (
1353 not node.hasAttributes() and not node.hasChildNodes()
1354 )
1355 if self._default is None:
1356 self._default = new_default
1357 elif not emptyDefault and new_default != self._default:
1358 raise ManifestParseError(
1359 "duplicate default in %s" % (self.manifestFile)
1360 )
LaMont Jonesb90a4222022-04-14 15:00:09 +00001361
Julien Campergue74879922013-10-09 14:38:46 +02001362 if self._default is None:
Gavin Makea2e3302023-03-11 06:46:20 +00001363 self._default = _Default()
Julien Campergue74879922013-10-09 14:38:46 +02001364
Gavin Makea2e3302023-03-11 06:46:20 +00001365 submanifest_paths = set()
1366 for node in itertools.chain(*node_list):
1367 if node.nodeName == "submanifest":
1368 submanifest = self._ParseSubmanifest(node)
1369 if submanifest:
1370 if submanifest.name in self._submanifests:
1371 if submanifest != self._submanifests[submanifest.name]:
1372 raise ManifestParseError(
1373 "submanifest %s already exists with different "
1374 "attributes" % (submanifest.name)
1375 )
1376 else:
1377 self._submanifests[submanifest.name] = submanifest
1378 submanifest_paths.add(submanifest.relpath)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001379
Gavin Makea2e3302023-03-11 06:46:20 +00001380 for node in itertools.chain(*node_list):
1381 if node.nodeName == "notice":
1382 if self._notice is not None:
1383 raise ManifestParseError(
1384 "duplicate notice in %s" % (self.manifestFile)
1385 )
1386 self._notice = self._ParseNotice(node)
LaMont Jonescc879a92021-11-18 22:40:18 +00001387
Gavin Makea2e3302023-03-11 06:46:20 +00001388 for node in itertools.chain(*node_list):
1389 if node.nodeName == "manifest-server":
1390 url = self._reqatt(node, "url")
1391 if self._manifest_server is not None:
1392 raise ManifestParseError(
1393 "duplicate manifest-server in %s" % (self.manifestFile)
1394 )
1395 self._manifest_server = url
Doug Anderson2b8db3c2010-11-01 15:08:06 -07001396
Gavin Makea2e3302023-03-11 06:46:20 +00001397 def recursively_add_projects(project):
1398 projects = self._projects.setdefault(project.name, [])
1399 if project.relpath is None:
1400 raise ManifestParseError(
1401 "missing path for %s in %s"
1402 % (project.name, self.manifestFile)
1403 )
1404 if project.relpath in self._paths:
1405 raise ManifestParseError(
1406 "duplicate path %s in %s"
1407 % (project.relpath, self.manifestFile)
1408 )
1409 for tree in submanifest_paths:
1410 if project.relpath.startswith(tree):
1411 raise ManifestParseError(
1412 "project %s conflicts with submanifest path %s"
1413 % (project.relpath, tree)
1414 )
1415 self._paths[project.relpath] = project
1416 projects.append(project)
1417 for subproject in project.subprojects:
1418 recursively_add_projects(subproject)
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -07001419
Gavin Makea2e3302023-03-11 06:46:20 +00001420 repo_hooks_project = None
1421 enabled_repo_hooks = None
1422 for node in itertools.chain(*node_list):
1423 if node.nodeName == "project":
1424 project = self._ParseProject(node)
1425 recursively_add_projects(project)
1426 if node.nodeName == "extend-project":
1427 name = self._reqatt(node, "name")
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001428
Gavin Makea2e3302023-03-11 06:46:20 +00001429 if name not in self._projects:
1430 raise ManifestParseError(
1431 "extend-project element specifies non-existent "
1432 "project: %s" % name
1433 )
1434
1435 path = node.getAttribute("path")
1436 dest_path = node.getAttribute("dest-path")
1437 groups = node.getAttribute("groups")
1438 if groups:
1439 groups = self._ParseList(groups)
1440 revision = node.getAttribute("revision")
1441 remote_name = node.getAttribute("remote")
1442 if not remote_name:
1443 remote = self._default.remote
1444 else:
1445 remote = self._get_remote(node)
1446 dest_branch = node.getAttribute("dest-branch")
1447 upstream = node.getAttribute("upstream")
1448
1449 named_projects = self._projects[name]
1450 if dest_path and not path and len(named_projects) > 1:
1451 raise ManifestParseError(
1452 "extend-project cannot use dest-path when "
1453 "matching multiple projects: %s" % name
1454 )
1455 for p in self._projects[name]:
1456 if path and p.relpath != path:
1457 continue
1458 if groups:
1459 p.groups.extend(groups)
1460 if revision:
1461 p.SetRevision(revision)
1462
1463 if remote_name:
1464 p.remote = remote.ToRemoteSpec(name)
1465 if dest_branch:
1466 p.dest_branch = dest_branch
1467 if upstream:
1468 p.upstream = upstream
1469
1470 if dest_path:
1471 del self._paths[p.relpath]
1472 (
1473 relpath,
1474 worktree,
1475 gitdir,
1476 objdir,
1477 _,
1478 ) = self.GetProjectPaths(name, dest_path, remote.name)
1479 p.UpdatePaths(relpath, worktree, gitdir, objdir)
1480 self._paths[p.relpath] = p
1481
1482 if node.nodeName == "repo-hooks":
1483 # Only one project can be the hooks project
1484 if repo_hooks_project is not None:
1485 raise ManifestParseError(
1486 "duplicate repo-hooks in %s" % (self.manifestFile)
1487 )
1488
1489 # Get the name of the project and the (space-separated) list of
1490 # enabled.
1491 repo_hooks_project = self._reqatt(node, "in-project")
1492 enabled_repo_hooks = self._ParseList(
1493 self._reqatt(node, "enabled-list")
1494 )
1495 if node.nodeName == "superproject":
1496 name = self._reqatt(node, "name")
1497 # There can only be one superproject.
1498 if self._superproject:
1499 raise ManifestParseError(
1500 "duplicate superproject in %s" % (self.manifestFile)
1501 )
1502 remote_name = node.getAttribute("remote")
1503 if not remote_name:
1504 remote = self._default.remote
1505 else:
1506 remote = self._get_remote(node)
1507 if remote is None:
1508 raise ManifestParseError(
1509 "no remote for superproject %s within %s"
1510 % (name, self.manifestFile)
1511 )
1512 revision = node.getAttribute("revision") or remote.revision
1513 if not revision:
1514 revision = self._default.revisionExpr
1515 if not revision:
1516 raise ManifestParseError(
1517 "no revision for superproject %s within %s"
1518 % (name, self.manifestFile)
1519 )
1520 self._superproject = Superproject(
1521 self,
1522 name=name,
1523 remote=remote.ToRemoteSpec(name),
1524 revision=revision,
1525 )
1526 if node.nodeName == "contactinfo":
1527 bugurl = self._reqatt(node, "bugurl")
1528 # This element can be repeated, later entries will clobber
1529 # earlier ones.
1530 self._contactinfo = ContactInfo(bugurl)
1531
1532 if node.nodeName == "remove-project":
Fredrik de Grootbe71c2f2023-05-31 16:56:34 +02001533 name = node.getAttribute("name")
1534 path = node.getAttribute("path")
Gavin Makea2e3302023-03-11 06:46:20 +00001535
Fredrik de Grootbe71c2f2023-05-31 16:56:34 +02001536 # Name or path needed.
1537 if not name and not path:
1538 raise ManifestParseError(
1539 "remove-project must have name and/or path"
1540 )
Gavin Makea2e3302023-03-11 06:46:20 +00001541
Fredrik de Grootbe71c2f2023-05-31 16:56:34 +02001542 removed_project = ""
1543
1544 # Find and remove projects based on name and/or path.
1545 for projname, projects in list(self._projects.items()):
1546 for p in projects:
1547 if name == projname and not path:
1548 del self._paths[p.relpath]
1549 if not removed_project:
1550 del self._projects[name]
1551 removed_project = name
1552 elif path == p.relpath and (
1553 name == projname or not name
1554 ):
1555 self._projects[projname].remove(p)
1556 del self._paths[p.relpath]
1557 removed_project = p.name
1558
1559 # If the manifest removes the hooks project, treat it as if
1560 # it deleted the repo-hooks element too.
1561 if (
1562 removed_project
1563 and removed_project not in self._projects
1564 and repo_hooks_project == removed_project
1565 ):
1566 repo_hooks_project = None
1567
1568 if not removed_project and not XmlBool(node, "optional", False):
Gavin Makea2e3302023-03-11 06:46:20 +00001569 raise ManifestParseError(
1570 "remove-project element specifies non-existent "
Fredrik de Grootbe71c2f2023-05-31 16:56:34 +02001571 "project: %s" % node.toxml()
Gavin Makea2e3302023-03-11 06:46:20 +00001572 )
1573
1574 # Store repo hooks project information.
1575 if repo_hooks_project:
1576 # Store a reference to the Project.
1577 try:
1578 repo_hooks_projects = self._projects[repo_hooks_project]
1579 except KeyError:
1580 raise ManifestParseError(
1581 "project %s not found for repo-hooks" % (repo_hooks_project)
1582 )
1583
1584 if len(repo_hooks_projects) != 1:
1585 raise ManifestParseError(
1586 "internal error parsing repo-hooks in %s"
1587 % (self.manifestFile)
1588 )
1589 self._repo_hooks_project = repo_hooks_projects[0]
1590 # Store the enabled hooks in the Project object.
1591 self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks
1592
1593 def _AddMetaProjectMirror(self, m):
1594 name = None
1595 m_url = m.GetRemote().url
1596 if m_url.endswith("/.git"):
1597 raise ManifestParseError("refusing to mirror %s" % m_url)
1598
1599 if self._default and self._default.remote:
1600 url = self._default.remote.resolvedFetchUrl
1601 if not url.endswith("/"):
1602 url += "/"
1603 if m_url.startswith(url):
1604 remote = self._default.remote
1605 name = m_url[len(url) :]
1606
1607 if name is None:
1608 s = m_url.rindex("/") + 1
1609 manifestUrl = self.manifestProject.config.GetString(
1610 "remote.origin.url"
1611 )
1612 remote = _XmlRemote(
1613 "origin", fetch=m_url[:s], manifestUrl=manifestUrl
1614 )
1615 name = m_url[s:]
1616
1617 if name.endswith(".git"):
1618 name = name[:-4]
Josh Triplett884a3872014-06-12 14:57:29 -07001619
1620 if name not in self._projects:
Gavin Makea2e3302023-03-11 06:46:20 +00001621 m.PreSync()
1622 gitdir = os.path.join(self.topdir, "%s.git" % name)
1623 project = Project(
1624 manifest=self,
1625 name=name,
1626 remote=remote.ToRemoteSpec(name),
1627 gitdir=gitdir,
1628 objdir=gitdir,
1629 worktree=None,
1630 relpath=name or None,
1631 revisionExpr=m.revisionExpr,
1632 revisionId=None,
1633 )
1634 self._projects[project.name] = [project]
1635 self._paths[project.relpath] = project
Josh Triplett884a3872014-06-12 14:57:29 -07001636
Gavin Makea2e3302023-03-11 06:46:20 +00001637 def _ParseRemote(self, node):
1638 """
1639 reads a <remote> element from the manifest file
1640 """
1641 name = self._reqatt(node, "name")
1642 alias = node.getAttribute("alias")
1643 if alias == "":
1644 alias = None
1645 fetch = self._reqatt(node, "fetch")
1646 pushUrl = node.getAttribute("pushurl")
1647 if pushUrl == "":
1648 pushUrl = None
1649 review = node.getAttribute("review")
1650 if review == "":
1651 review = None
1652 revision = node.getAttribute("revision")
1653 if revision == "":
1654 revision = None
1655 manifestUrl = self.manifestProject.config.GetString("remote.origin.url")
1656
1657 remote = _XmlRemote(
1658 name, alias, fetch, pushUrl, manifestUrl, review, revision
1659 )
1660
1661 for n in node.childNodes:
1662 if n.nodeName == "annotation":
1663 self._ParseAnnotation(remote, n)
1664
1665 return remote
1666
1667 def _ParseDefault(self, node):
1668 """
1669 reads a <default> element from the manifest file
1670 """
1671 d = _Default()
1672 d.remote = self._get_remote(node)
1673 d.revisionExpr = node.getAttribute("revision")
1674 if d.revisionExpr == "":
1675 d.revisionExpr = None
1676
1677 d.destBranchExpr = node.getAttribute("dest-branch") or None
1678 d.upstreamExpr = node.getAttribute("upstream") or None
1679
1680 d.sync_j = XmlInt(node, "sync-j", None)
1681 if d.sync_j is not None and d.sync_j <= 0:
1682 raise ManifestParseError(
1683 '%s: sync-j must be greater than 0, not "%s"'
1684 % (self.manifestFile, d.sync_j)
1685 )
1686
1687 d.sync_c = XmlBool(node, "sync-c", False)
1688 d.sync_s = XmlBool(node, "sync-s", False)
1689 d.sync_tags = XmlBool(node, "sync-tags", True)
1690 return d
1691
1692 def _ParseNotice(self, node):
1693 """
1694 reads a <notice> element from the manifest file
1695
1696 The <notice> element is distinct from other tags in the XML in that the
1697 data is conveyed between the start and end tag (it's not an
1698 empty-element tag).
1699
1700 The white space (carriage returns, indentation) for the notice element
1701 is relevant and is parsed in a way that is based on how python
1702 docstrings work. In fact, the code is remarkably similar to here:
1703 http://www.python.org/dev/peps/pep-0257/
1704 """
1705 # Get the data out of the node...
1706 notice = node.childNodes[0].data
1707
1708 # Figure out minimum indentation, skipping the first line (the same line
1709 # as the <notice> tag)...
1710 minIndent = sys.maxsize
1711 lines = notice.splitlines()
1712 for line in lines[1:]:
1713 lstrippedLine = line.lstrip()
1714 if lstrippedLine:
1715 indent = len(line) - len(lstrippedLine)
1716 minIndent = min(indent, minIndent)
1717
1718 # Strip leading / trailing blank lines and also indentation.
1719 cleanLines = [lines[0].strip()]
1720 for line in lines[1:]:
1721 cleanLines.append(line[minIndent:].rstrip())
1722
1723 # Clear completely blank lines from front and back...
1724 while cleanLines and not cleanLines[0]:
1725 del cleanLines[0]
1726 while cleanLines and not cleanLines[-1]:
1727 del cleanLines[-1]
1728
1729 return "\n".join(cleanLines)
1730
1731 def _ParseSubmanifest(self, node):
1732 """Reads a <submanifest> element from the manifest file."""
1733 name = self._reqatt(node, "name")
1734 remote = node.getAttribute("remote")
1735 if remote == "":
1736 remote = None
1737 project = node.getAttribute("project")
1738 if project == "":
1739 project = None
1740 revision = node.getAttribute("revision")
1741 if revision == "":
1742 revision = None
1743 manifestName = node.getAttribute("manifest-name")
1744 if manifestName == "":
1745 manifestName = None
1746 groups = ""
1747 if node.hasAttribute("groups"):
1748 groups = node.getAttribute("groups")
1749 groups = self._ParseList(groups)
1750 default_groups = self._ParseList(node.getAttribute("default-groups"))
1751 path = node.getAttribute("path")
1752 if path == "":
1753 path = None
1754 if revision:
1755 msg = self._CheckLocalPath(revision.split("/")[-1])
1756 if msg:
1757 raise ManifestInvalidPathError(
1758 '<submanifest> invalid "revision": %s: %s'
1759 % (revision, msg)
1760 )
1761 else:
1762 msg = self._CheckLocalPath(name)
1763 if msg:
1764 raise ManifestInvalidPathError(
1765 '<submanifest> invalid "name": %s: %s' % (name, msg)
1766 )
LaMont Jonescc879a92021-11-18 22:40:18 +00001767 else:
Gavin Makea2e3302023-03-11 06:46:20 +00001768 msg = self._CheckLocalPath(path)
1769 if msg:
1770 raise ManifestInvalidPathError(
1771 '<submanifest> invalid "path": %s: %s' % (path, msg)
1772 )
Josh Triplett884a3872014-06-12 14:57:29 -07001773
Gavin Makea2e3302023-03-11 06:46:20 +00001774 submanifest = _XmlSubmanifest(
1775 name,
1776 remote,
1777 project,
1778 revision,
1779 manifestName,
1780 groups,
1781 default_groups,
1782 path,
1783 self,
1784 )
Michael Kelly2f3c3312020-07-21 19:40:38 -07001785
Gavin Makea2e3302023-03-11 06:46:20 +00001786 for n in node.childNodes:
1787 if n.nodeName == "annotation":
1788 self._ParseAnnotation(submanifest, n)
Michael Kelly2f3c3312020-07-21 19:40:38 -07001789
Gavin Makea2e3302023-03-11 06:46:20 +00001790 return submanifest
Michael Kelly37c21c22020-06-13 02:10:40 -07001791
Gavin Makea2e3302023-03-11 06:46:20 +00001792 def _JoinName(self, parent_name, name):
1793 return os.path.join(parent_name, name)
Doug Anderson37282b42011-03-04 11:54:18 -08001794
Gavin Makea2e3302023-03-11 06:46:20 +00001795 def _UnjoinName(self, parent_name, name):
1796 return os.path.relpath(name, parent_name)
1797
1798 def _ParseProject(self, node, parent=None, **extra_proj_attrs):
1799 """
1800 reads a <project> element from the manifest file
1801 """
1802 name = self._reqatt(node, "name")
1803 msg = self._CheckLocalPath(name, dir_ok=True)
1804 if msg:
1805 raise ManifestInvalidPathError(
1806 '<project> invalid "name": %s: %s' % (name, msg)
1807 )
1808 if parent:
1809 name = self._JoinName(parent.name, name)
1810
1811 remote = self._get_remote(node)
Raman Tenneti1bb4fb22021-01-07 16:50:45 -08001812 if remote is None:
Gavin Makea2e3302023-03-11 06:46:20 +00001813 remote = self._default.remote
1814 if remote is None:
1815 raise ManifestParseError(
1816 "no remote for project %s within %s" % (name, self.manifestFile)
1817 )
Raman Tenneti993af5e2021-05-12 12:00:31 -07001818
Gavin Makea2e3302023-03-11 06:46:20 +00001819 revisionExpr = node.getAttribute("revision") or remote.revision
1820 if not revisionExpr:
1821 revisionExpr = self._default.revisionExpr
1822 if not revisionExpr:
1823 raise ManifestParseError(
1824 "no revision for project %s within %s"
1825 % (name, self.manifestFile)
1826 )
David Jamesb8433df2014-01-30 10:11:17 -08001827
Gavin Makea2e3302023-03-11 06:46:20 +00001828 path = node.getAttribute("path")
1829 if not path:
1830 path = name
Julien Camperguedd654222014-01-09 16:21:37 +01001831 else:
Gavin Makea2e3302023-03-11 06:46:20 +00001832 # NB: The "." project is handled specially in
1833 # Project.Sync_LocalHalf.
1834 msg = self._CheckLocalPath(path, dir_ok=True, cwd_dot_ok=True)
1835 if msg:
1836 raise ManifestInvalidPathError(
1837 '<project> invalid "path": %s: %s' % (path, msg)
1838 )
Julien Camperguedd654222014-01-09 16:21:37 +01001839
Gavin Makea2e3302023-03-11 06:46:20 +00001840 rebase = XmlBool(node, "rebase", True)
1841 sync_c = XmlBool(node, "sync-c", False)
1842 sync_s = XmlBool(node, "sync-s", self._default.sync_s)
1843 sync_tags = XmlBool(node, "sync-tags", self._default.sync_tags)
Julien Camperguedd654222014-01-09 16:21:37 +01001844
Gavin Makea2e3302023-03-11 06:46:20 +00001845 clone_depth = XmlInt(node, "clone-depth")
1846 if clone_depth is not None and clone_depth <= 0:
1847 raise ManifestParseError(
1848 '%s: clone-depth must be greater than 0, not "%s"'
1849 % (self.manifestFile, clone_depth)
1850 )
1851
1852 dest_branch = (
1853 node.getAttribute("dest-branch") or self._default.destBranchExpr
1854 )
1855
1856 upstream = node.getAttribute("upstream") or self._default.upstreamExpr
1857
1858 groups = ""
1859 if node.hasAttribute("groups"):
1860 groups = node.getAttribute("groups")
1861 groups = self._ParseList(groups)
1862
1863 if parent is None:
1864 (
1865 relpath,
1866 worktree,
1867 gitdir,
1868 objdir,
1869 use_git_worktrees,
1870 ) = self.GetProjectPaths(name, path, remote.name)
1871 else:
1872 use_git_worktrees = False
1873 relpath, worktree, gitdir, objdir = self.GetSubprojectPaths(
1874 parent, name, path
1875 )
1876
1877 default_groups = ["all", "name:%s" % name, "path:%s" % relpath]
1878 groups.extend(set(default_groups).difference(groups))
1879
1880 if self.IsMirror and node.hasAttribute("force-path"):
1881 if XmlBool(node, "force-path", False):
1882 gitdir = os.path.join(self.topdir, "%s.git" % path)
1883
1884 project = Project(
1885 manifest=self,
1886 name=name,
1887 remote=remote.ToRemoteSpec(name),
1888 gitdir=gitdir,
1889 objdir=objdir,
1890 worktree=worktree,
1891 relpath=relpath,
1892 revisionExpr=revisionExpr,
1893 revisionId=None,
1894 rebase=rebase,
1895 groups=groups,
1896 sync_c=sync_c,
1897 sync_s=sync_s,
1898 sync_tags=sync_tags,
1899 clone_depth=clone_depth,
1900 upstream=upstream,
1901 parent=parent,
1902 dest_branch=dest_branch,
1903 use_git_worktrees=use_git_worktrees,
1904 **extra_proj_attrs,
1905 )
1906
1907 for n in node.childNodes:
1908 if n.nodeName == "copyfile":
1909 self._ParseCopyFile(project, n)
1910 if n.nodeName == "linkfile":
1911 self._ParseLinkFile(project, n)
1912 if n.nodeName == "annotation":
1913 self._ParseAnnotation(project, n)
1914 if n.nodeName == "project":
1915 project.subprojects.append(
1916 self._ParseProject(n, parent=project)
1917 )
1918
1919 return project
1920
1921 def GetProjectPaths(self, name, path, remote):
1922 """Return the paths for a project.
1923
1924 Args:
1925 name: a string, the name of the project.
1926 path: a string, the path of the project.
1927 remote: a string, the remote.name of the project.
1928
1929 Returns:
1930 A tuple of (relpath, worktree, gitdir, objdir, use_git_worktrees)
1931 for the project with |name| and |path|.
1932 """
1933 # The manifest entries might have trailing slashes. Normalize them to
1934 # avoid unexpected filesystem behavior since we do string concatenation
1935 # below.
1936 path = path.rstrip("/")
1937 name = name.rstrip("/")
1938 remote = remote.rstrip("/")
1939 use_git_worktrees = False
1940 use_remote_name = self.is_multimanifest
1941 relpath = path
1942 if self.IsMirror:
1943 worktree = None
1944 gitdir = os.path.join(self.topdir, "%s.git" % name)
1945 objdir = gitdir
1946 else:
1947 if use_remote_name:
1948 namepath = os.path.join(remote, f"{name}.git")
1949 else:
1950 namepath = f"{name}.git"
1951 worktree = os.path.join(self.topdir, path).replace("\\", "/")
1952 gitdir = os.path.join(self.subdir, "projects", "%s.git" % path)
1953 # We allow people to mix git worktrees & non-git worktrees for now.
1954 # This allows for in situ migration of repo clients.
1955 if os.path.exists(gitdir) or not self.UseGitWorktrees:
1956 objdir = os.path.join(self.repodir, "project-objects", namepath)
1957 else:
1958 use_git_worktrees = True
1959 gitdir = os.path.join(self.repodir, "worktrees", namepath)
1960 objdir = gitdir
1961 return relpath, worktree, gitdir, objdir, use_git_worktrees
1962
1963 def GetProjectsWithName(self, name, all_manifests=False):
1964 """All projects with |name|.
1965
1966 Args:
1967 name: a string, the name of the project.
1968 all_manifests: a boolean, if True, then all manifests are searched.
1969 If False, then only this manifest is searched.
1970
1971 Returns:
1972 A list of Project instances with name |name|.
1973 """
1974 if all_manifests:
1975 return list(
1976 itertools.chain.from_iterable(
1977 x._projects.get(name, []) for x in self.all_manifests
1978 )
1979 )
1980 return self._projects.get(name, [])
1981
1982 def GetSubprojectName(self, parent, submodule_path):
1983 return os.path.join(parent.name, submodule_path)
1984
1985 def _JoinRelpath(self, parent_relpath, relpath):
1986 return os.path.join(parent_relpath, relpath)
1987
1988 def _UnjoinRelpath(self, parent_relpath, relpath):
1989 return os.path.relpath(relpath, parent_relpath)
1990
1991 def GetSubprojectPaths(self, parent, name, path):
1992 # The manifest entries might have trailing slashes. Normalize them to
1993 # avoid unexpected filesystem behavior since we do string concatenation
1994 # below.
1995 path = path.rstrip("/")
1996 name = name.rstrip("/")
1997 relpath = self._JoinRelpath(parent.relpath, path)
1998 gitdir = os.path.join(parent.gitdir, "subprojects", "%s.git" % path)
1999 objdir = os.path.join(
2000 parent.gitdir, "subproject-objects", "%s.git" % name
2001 )
2002 if self.IsMirror:
2003 worktree = None
2004 else:
2005 worktree = os.path.join(parent.worktree, path).replace("\\", "/")
2006 return relpath, worktree, gitdir, objdir
2007
2008 @staticmethod
2009 def _CheckLocalPath(path, dir_ok=False, cwd_dot_ok=False):
2010 """Verify |path| is reasonable for use in filesystem paths.
2011
2012 Used with <copyfile> & <linkfile> & <project> elements.
2013
2014 This only validates the |path| in isolation: it does not check against
2015 the current filesystem state. Thus it is suitable as a first-past in a
2016 parser.
2017
2018 It enforces a number of constraints:
2019 * No empty paths.
2020 * No "~" in paths.
2021 * No Unicode codepoints that filesystems might elide when normalizing.
2022 * No relative path components like "." or "..".
2023 * No absolute paths.
2024 * No ".git" or ".repo*" path components.
2025
2026 Args:
2027 path: The path name to validate.
2028 dir_ok: Whether |path| may force a directory (e.g. end in a /).
2029 cwd_dot_ok: Whether |path| may be just ".".
2030
2031 Returns:
2032 None if |path| is OK, a failure message otherwise.
2033 """
2034 if not path:
2035 return "empty paths not allowed"
2036
2037 if "~" in path:
2038 return "~ not allowed (due to 8.3 filenames on Windows filesystems)"
2039
2040 path_codepoints = set(path)
2041
2042 # Some filesystems (like Apple's HFS+) try to normalize Unicode
2043 # codepoints which means there are alternative names for ".git". Reject
2044 # paths with these in it as there shouldn't be any reasonable need for
2045 # them here. The set of codepoints here was cribbed from jgit's
2046 # implementation:
2047 # https://eclipse.googlesource.com/jgit/jgit/+/9110037e3e9461ff4dac22fee84ef3694ed57648/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java#884
2048 BAD_CODEPOINTS = {
2049 "\u200C", # ZERO WIDTH NON-JOINER
2050 "\u200D", # ZERO WIDTH JOINER
2051 "\u200E", # LEFT-TO-RIGHT MARK
2052 "\u200F", # RIGHT-TO-LEFT MARK
2053 "\u202A", # LEFT-TO-RIGHT EMBEDDING
2054 "\u202B", # RIGHT-TO-LEFT EMBEDDING
2055 "\u202C", # POP DIRECTIONAL FORMATTING
2056 "\u202D", # LEFT-TO-RIGHT OVERRIDE
2057 "\u202E", # RIGHT-TO-LEFT OVERRIDE
2058 "\u206A", # INHIBIT SYMMETRIC SWAPPING
2059 "\u206B", # ACTIVATE SYMMETRIC SWAPPING
2060 "\u206C", # INHIBIT ARABIC FORM SHAPING
2061 "\u206D", # ACTIVATE ARABIC FORM SHAPING
2062 "\u206E", # NATIONAL DIGIT SHAPES
2063 "\u206F", # NOMINAL DIGIT SHAPES
2064 "\uFEFF", # ZERO WIDTH NO-BREAK SPACE
2065 }
2066 if BAD_CODEPOINTS & path_codepoints:
2067 # This message is more expansive than reality, but should be fine.
2068 return "Unicode combining characters not allowed"
2069
2070 # Reject newlines as there shouldn't be any legitmate use for them,
2071 # they'll be confusing to users, and they can easily break tools that
2072 # expect to be able to iterate over newline delimited lists. This even
2073 # applies to our own code like .repo/project.list.
2074 if {"\r", "\n"} & path_codepoints:
2075 return "Newlines not allowed"
2076
2077 # Assume paths might be used on case-insensitive filesystems.
2078 path = path.lower()
2079
2080 # Split up the path by its components. We can't use os.path.sep
2081 # exclusively as some platforms (like Windows) will convert / to \ and
2082 # that bypasses all our constructed logic here. Especially since
2083 # manifest authors only use / in their paths.
2084 resep = re.compile(r"[/%s]" % re.escape(os.path.sep))
2085 # Strip off trailing slashes as those only produce '' elements, and we
2086 # use parts to look for individual bad components.
2087 parts = resep.split(path.rstrip("/"))
2088
2089 # Some people use src="." to create stable links to projects. Lets
2090 # allow that but reject all other uses of "." to keep things simple.
2091 if not cwd_dot_ok or parts != ["."]:
2092 for part in set(parts):
2093 if part in {".", "..", ".git"} or part.startswith(".repo"):
2094 return "bad component: %s" % (part,)
2095
2096 if not dir_ok and resep.match(path[-1]):
2097 return "dirs not allowed"
2098
2099 # NB: The two abspath checks here are to handle platforms with multiple
2100 # filesystem path styles (e.g. Windows).
2101 norm = os.path.normpath(path)
2102 if (
2103 norm == ".."
2104 or (
2105 len(norm) >= 3
2106 and norm.startswith("..")
2107 and resep.match(norm[0])
2108 )
2109 or os.path.isabs(norm)
2110 or norm.startswith("/")
2111 ):
2112 return "path cannot be outside"
2113
2114 @classmethod
2115 def _ValidateFilePaths(cls, element, src, dest):
2116 """Verify |src| & |dest| are reasonable for <copyfile> & <linkfile>.
2117
2118 We verify the path independent of any filesystem state as we won't have
2119 a checkout available to compare to. i.e. This is for parsing validation
2120 purposes only.
2121
2122 We'll do full/live sanity checking before we do the actual filesystem
2123 modifications in _CopyFile/_LinkFile/etc...
2124 """
2125 # |dest| is the file we write to or symlink we create.
2126 # It is relative to the top of the repo client checkout.
2127 msg = cls._CheckLocalPath(dest)
2128 if msg:
2129 raise ManifestInvalidPathError(
2130 '<%s> invalid "dest": %s: %s' % (element, dest, msg)
2131 )
2132
2133 # |src| is the file we read from or path we point to for symlinks.
2134 # It is relative to the top of the git project checkout.
2135 is_linkfile = element == "linkfile"
2136 msg = cls._CheckLocalPath(
2137 src, dir_ok=is_linkfile, cwd_dot_ok=is_linkfile
2138 )
2139 if msg:
2140 raise ManifestInvalidPathError(
2141 '<%s> invalid "src": %s: %s' % (element, src, msg)
2142 )
2143
2144 def _ParseCopyFile(self, project, node):
2145 src = self._reqatt(node, "src")
2146 dest = self._reqatt(node, "dest")
2147 if not self.IsMirror:
2148 # src is project relative;
2149 # dest is relative to the top of the tree.
2150 # We only validate paths if we actually plan to process them.
2151 self._ValidateFilePaths("copyfile", src, dest)
2152 project.AddCopyFile(src, dest, self.topdir)
2153
2154 def _ParseLinkFile(self, project, node):
2155 src = self._reqatt(node, "src")
2156 dest = self._reqatt(node, "dest")
2157 if not self.IsMirror:
2158 # src is project relative;
2159 # dest is relative to the top of the tree.
2160 # We only validate paths if we actually plan to process them.
2161 self._ValidateFilePaths("linkfile", src, dest)
2162 project.AddLinkFile(src, dest, self.topdir)
2163
2164 def _ParseAnnotation(self, element, node):
2165 name = self._reqatt(node, "name")
2166 value = self._reqatt(node, "value")
2167 try:
2168 keep = self._reqatt(node, "keep").lower()
2169 except ManifestParseError:
2170 keep = "true"
2171 if keep != "true" and keep != "false":
2172 raise ManifestParseError(
2173 'optional "keep" attribute must be ' '"true" or "false"'
2174 )
2175 element.AddAnnotation(name, value, keep)
2176
2177 def _get_remote(self, node):
2178 name = node.getAttribute("remote")
2179 if not name:
2180 return None
2181
2182 v = self._remotes.get(name)
2183 if not v:
2184 raise ManifestParseError(
2185 "remote %s not defined in %s" % (name, self.manifestFile)
2186 )
2187 return v
2188
2189 def _reqatt(self, node, attname):
2190 """
2191 reads a required attribute from the node.
2192 """
2193 v = node.getAttribute(attname)
2194 if not v:
2195 raise ManifestParseError(
2196 "no %s in <%s> within %s"
2197 % (attname, node.nodeName, self.manifestFile)
2198 )
2199 return v
2200
2201 def projectsDiff(self, manifest):
2202 """return the projects differences between two manifests.
2203
2204 The diff will be from self to given manifest.
2205
2206 """
2207 fromProjects = self.paths
2208 toProjects = manifest.paths
2209
2210 fromKeys = sorted(fromProjects.keys())
Sylvain25d6c7c2023-08-19 23:21:49 +02002211 toKeys = set(toProjects.keys())
Gavin Makea2e3302023-03-11 06:46:20 +00002212
2213 diff = {
2214 "added": [],
2215 "removed": [],
2216 "missing": [],
2217 "changed": [],
2218 "unreachable": [],
2219 }
2220
2221 for proj in fromKeys:
Sylvain25d6c7c2023-08-19 23:21:49 +02002222 fromProj = fromProjects[proj]
Gavin Makea2e3302023-03-11 06:46:20 +00002223 if proj not in toKeys:
Sylvain25d6c7c2023-08-19 23:21:49 +02002224 diff["removed"].append(fromProj)
2225 elif not fromProj.Exists:
Gavin Makea2e3302023-03-11 06:46:20 +00002226 diff["missing"].append(toProjects[proj])
2227 toKeys.remove(proj)
2228 else:
Gavin Makea2e3302023-03-11 06:46:20 +00002229 toProj = toProjects[proj]
2230 try:
2231 fromRevId = fromProj.GetCommitRevisionId()
2232 toRevId = toProj.GetCommitRevisionId()
2233 except ManifestInvalidRevisionError:
2234 diff["unreachable"].append((fromProj, toProj))
2235 else:
2236 if fromRevId != toRevId:
2237 diff["changed"].append((fromProj, toProj))
2238 toKeys.remove(proj)
2239
Sylvain25d6c7c2023-08-19 23:21:49 +02002240 diff["added"].extend(toProjects[proj] for proj in sorted(toKeys))
Gavin Makea2e3302023-03-11 06:46:20 +00002241
2242 return diff
Simran Basib9a1b732015-08-20 12:19:28 -07002243
2244
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002245class RepoClient(XmlManifest):
Gavin Makea2e3302023-03-11 06:46:20 +00002246 """Manages a repo client checkout."""
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002247
Gavin Makea2e3302023-03-11 06:46:20 +00002248 def __init__(
2249 self, repodir, manifest_file=None, submanifest_path="", **kwargs
2250 ):
2251 """Initialize.
LaMont Jonesff6b1da2022-06-01 21:03:34 +00002252
Gavin Makea2e3302023-03-11 06:46:20 +00002253 Args:
2254 repodir: Path to the .repo/ dir for holding all internal checkout
2255 state. It must be in the top directory of the repo client
2256 checkout.
2257 manifest_file: Full path to the manifest file to parse. This will
2258 usually be |repodir|/|MANIFEST_FILE_NAME|.
2259 submanifest_path: The submanifest root relative to the repo root.
2260 **kwargs: Additional keyword arguments, passed to XmlManifest.
2261 """
2262 self.isGitcClient = False
2263 submanifest_path = submanifest_path or ""
2264 if submanifest_path:
2265 self._CheckLocalPath(submanifest_path)
2266 prefix = os.path.join(repodir, SUBMANIFEST_DIR, submanifest_path)
2267 else:
2268 prefix = repodir
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002269
Gavin Makea2e3302023-03-11 06:46:20 +00002270 if os.path.exists(os.path.join(prefix, LOCAL_MANIFEST_NAME)):
2271 print(
2272 "error: %s is not supported; put local manifests in `%s` "
2273 "instead"
2274 % (
2275 LOCAL_MANIFEST_NAME,
2276 os.path.join(prefix, LOCAL_MANIFESTS_DIR_NAME),
2277 ),
2278 file=sys.stderr,
2279 )
2280 sys.exit(1)
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002281
Gavin Makea2e3302023-03-11 06:46:20 +00002282 if manifest_file is None:
2283 manifest_file = os.path.join(prefix, MANIFEST_FILE_NAME)
2284 local_manifests = os.path.abspath(
2285 os.path.join(prefix, LOCAL_MANIFESTS_DIR_NAME)
2286 )
2287 super().__init__(
2288 repodir,
2289 manifest_file,
2290 local_manifests,
2291 submanifest_path=submanifest_path,
2292 **kwargs,
2293 )
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002294
Gavin Makea2e3302023-03-11 06:46:20 +00002295 # TODO: Completely separate manifest logic out of the client.
2296 self.manifest = self