blob: 73be1b6eb9b108213cb7193e8bb5c4b6dbba4346 [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
David Pursehouse59bbb582013-05-17 10:49:33 +090021import xml.dom.minidom
Mike Frysingeracf63b22019-06-13 02:24:21 -040022import urllib.parse
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070023
Simran Basib9a1b732015-08-20 12:19:28 -070024import gitc_utils
Daniel Kutik035f22a2022-12-13 12:34:23 +010025from git_config import GitConfig
David Pursehousee00aa6b2012-09-11 14:33:51 +090026from git_refs import R_HEADS, HEAD
LaMont Jonesd56e2eb2022-04-07 18:14:46 +000027from git_superproject import Superproject
Renaud Paquayd5cec5e2016-11-01 11:24:03 -070028import platform_utils
Gavin Makea2e3302023-03-11 06:46:20 +000029from project import (
30 Annotation,
31 RemoteSpec,
32 Project,
33 RepoProject,
34 ManifestProject,
35)
36from error import (
37 ManifestParseError,
38 ManifestInvalidPathError,
39 ManifestInvalidRevisionError,
40)
Raman Tenneti993af5e2021-05-12 12:00:31 -070041from wrapper import Wrapper
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070042
Gavin Makea2e3302023-03-11 06:46:20 +000043MANIFEST_FILE_NAME = "manifest.xml"
44LOCAL_MANIFEST_NAME = "local_manifest.xml"
45LOCAL_MANIFESTS_DIR_NAME = "local_manifests"
46SUBMANIFEST_DIR = "submanifests"
LaMont Jonescc879a92021-11-18 22:40:18 +000047# Limit submanifests to an arbitrary depth for loop detection.
48MAX_SUBMANIFEST_DEPTH = 8
LaMont Jonesb308db12022-02-25 17:05:21 +000049# Add all projects from sub manifest into a group.
Gavin Makea2e3302023-03-11 06:46:20 +000050SUBMANIFEST_GROUP_PREFIX = "submanifest:"
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070051
Raman Tenneti78f4dd32021-06-07 13:27:37 -070052# Add all projects from local manifest into a group.
Gavin Makea2e3302023-03-11 06:46:20 +000053LOCAL_MANIFEST_GROUP_PREFIX = "local:"
Raman Tenneti78f4dd32021-06-07 13:27:37 -070054
Raman Tenneti993af5e2021-05-12 12:00:31 -070055# ContactInfo has the self-registered bug url, supplied by the manifest authors.
Gavin Makea2e3302023-03-11 06:46:20 +000056ContactInfo = collections.namedtuple("ContactInfo", "bugurl")
Raman Tenneti993af5e2021-05-12 12:00:31 -070057
Anthony Kingcb07ba72015-03-28 23:26:04 +000058# urljoin gets confused if the scheme is not known.
Gavin Makea2e3302023-03-11 06:46:20 +000059urllib.parse.uses_relative.extend(
60 ["ssh", "git", "persistent-https", "sso", "rpc"]
61)
62urllib.parse.uses_netloc.extend(
63 ["ssh", "git", "persistent-https", "sso", "rpc"]
64)
Conley Owensdb728cd2011-09-26 16:34:01 -070065
David Pursehouse819827a2020-02-12 15:20:19 +090066
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050067def XmlBool(node, attr, default=None):
Gavin Makea2e3302023-03-11 06:46:20 +000068 """Determine boolean value of |node|'s |attr|.
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050069
Gavin Makea2e3302023-03-11 06:46:20 +000070 Invalid values will issue a non-fatal warning.
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050071
Gavin Makea2e3302023-03-11 06:46:20 +000072 Args:
73 node: XML node whose attributes we access.
74 attr: The attribute to access.
75 default: If the attribute is not set (value is empty), then use this.
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050076
Gavin Makea2e3302023-03-11 06:46:20 +000077 Returns:
78 True if the attribute is a valid string representing true.
79 False if the attribute is a valid string representing false.
80 |default| otherwise.
81 """
82 value = node.getAttribute(attr)
83 s = value.lower()
84 if s == "":
85 return default
86 elif s in {"yes", "true", "1"}:
87 return True
88 elif s in {"no", "false", "0"}:
89 return False
90 else:
91 print(
92 'warning: manifest: %s="%s": ignoring invalid XML boolean'
93 % (attr, value),
94 file=sys.stderr,
95 )
96 return default
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050097
98
99def XmlInt(node, attr, default=None):
Gavin Makea2e3302023-03-11 06:46:20 +0000100 """Determine integer value of |node|'s |attr|.
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500101
Gavin Makea2e3302023-03-11 06:46:20 +0000102 Args:
103 node: XML node whose attributes we access.
104 attr: The attribute to access.
105 default: If the attribute is not set (value is empty), then use this.
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500106
Gavin Makea2e3302023-03-11 06:46:20 +0000107 Returns:
108 The number if the attribute is a valid number.
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500109
Gavin Makea2e3302023-03-11 06:46:20 +0000110 Raises:
111 ManifestParseError: The number is invalid.
112 """
113 value = node.getAttribute(attr)
114 if not value:
115 return default
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500116
Gavin Makea2e3302023-03-11 06:46:20 +0000117 try:
118 return int(value)
119 except ValueError:
120 raise ManifestParseError(
121 'manifest: invalid %s="%s" integer' % (attr, value)
122 )
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500123
124
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700125class _Default(object):
Gavin Makea2e3302023-03-11 06:46:20 +0000126 """Project defaults within the manifest."""
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700127
Gavin Makea2e3302023-03-11 06:46:20 +0000128 revisionExpr = None
129 destBranchExpr = None
130 upstreamExpr = None
131 remote = None
132 sync_j = None
133 sync_c = False
134 sync_s = False
135 sync_tags = True
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700136
Gavin Makea2e3302023-03-11 06:46:20 +0000137 def __eq__(self, other):
138 if not isinstance(other, _Default):
139 return False
140 return self.__dict__ == other.__dict__
Julien Campergue74879922013-10-09 14:38:46 +0200141
Gavin Makea2e3302023-03-11 06:46:20 +0000142 def __ne__(self, other):
143 if not isinstance(other, _Default):
144 return True
145 return self.__dict__ != other.__dict__
Julien Campergue74879922013-10-09 14:38:46 +0200146
David Pursehouse819827a2020-02-12 15:20:19 +0900147
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700148class _XmlRemote(object):
Gavin Makea2e3302023-03-11 06:46:20 +0000149 def __init__(
150 self,
151 name,
152 alias=None,
153 fetch=None,
154 pushUrl=None,
155 manifestUrl=None,
156 review=None,
157 revision=None,
158 ):
159 self.name = name
160 self.fetchUrl = fetch
161 self.pushUrl = pushUrl
162 self.manifestUrl = manifestUrl
163 self.remoteAlias = alias
164 self.reviewUrl = review
165 self.revision = revision
166 self.resolvedFetchUrl = self._resolveFetchUrl()
167 self.annotations = []
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700168
Gavin Makea2e3302023-03-11 06:46:20 +0000169 def __eq__(self, other):
170 if not isinstance(other, _XmlRemote):
171 return False
172 return (
173 sorted(self.annotations) == sorted(other.annotations)
174 and self.name == other.name
175 and self.fetchUrl == other.fetchUrl
176 and self.pushUrl == other.pushUrl
177 and self.remoteAlias == other.remoteAlias
178 and self.reviewUrl == other.reviewUrl
179 and self.revision == other.revision
180 )
David Pursehouse717ece92012-11-13 08:49:16 +0900181
Gavin Makea2e3302023-03-11 06:46:20 +0000182 def __ne__(self, other):
183 return not self.__eq__(other)
David Pursehouse717ece92012-11-13 08:49:16 +0900184
Gavin Makea2e3302023-03-11 06:46:20 +0000185 def _resolveFetchUrl(self):
186 if self.fetchUrl is None:
187 return ""
188 url = self.fetchUrl.rstrip("/")
189 manifestUrl = self.manifestUrl.rstrip("/")
190 # urljoin will gets confused over quite a few things. The ones we care
191 # about here are:
192 # * no scheme in the base url, like <hostname:port>
193 # We handle no scheme by replacing it with an obscure protocol, gopher
194 # and then replacing it with the original when we are done.
Anthony Kingcb07ba72015-03-28 23:26:04 +0000195
Gavin Makea2e3302023-03-11 06:46:20 +0000196 if manifestUrl.find(":") != manifestUrl.find("/") - 1:
197 url = urllib.parse.urljoin("gopher://" + manifestUrl, url)
198 url = re.sub(r"^gopher://", "", url)
199 else:
200 url = urllib.parse.urljoin(manifestUrl, url)
201 return url
Conley Owensceea3682011-10-20 10:45:47 -0700202
Gavin Makea2e3302023-03-11 06:46:20 +0000203 def ToRemoteSpec(self, projectName):
204 fetchUrl = self.resolvedFetchUrl.rstrip("/")
205 url = fetchUrl + "/" + projectName
206 remoteName = self.name
207 if self.remoteAlias:
208 remoteName = self.remoteAlias
209 return RemoteSpec(
210 remoteName,
211 url=url,
212 pushUrl=self.pushUrl,
213 review=self.reviewUrl,
214 orig_name=self.name,
215 fetchUrl=self.fetchUrl,
216 )
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700217
Gavin Makea2e3302023-03-11 06:46:20 +0000218 def AddAnnotation(self, name, value, keep):
219 self.annotations.append(Annotation(name, value, keep))
Jack Neus6ea0cae2021-07-20 20:52:33 +0000220
David Pursehouse819827a2020-02-12 15:20:19 +0900221
LaMont Jonescc879a92021-11-18 22:40:18 +0000222class _XmlSubmanifest:
Gavin Makea2e3302023-03-11 06:46:20 +0000223 """Manage the <submanifest> element specified in the manifest.
LaMont Jonescc879a92021-11-18 22:40:18 +0000224
Gavin Makea2e3302023-03-11 06:46:20 +0000225 Attributes:
226 name: a string, the name for this submanifest.
227 remote: a string, the remote.name for this submanifest.
228 project: a string, the name of the manifest project.
229 revision: a string, the commitish.
230 manifestName: a string, the submanifest file name.
231 groups: a list of strings, the groups to add to all projects in the
232 submanifest.
233 default_groups: a list of strings, the default groups to sync.
234 path: a string, the relative path for the submanifest checkout.
235 parent: an XmlManifest, the parent manifest.
236 annotations: (derived) a list of annotations.
237 present: (derived) a boolean, whether the sub manifest file is present.
238 """
LaMont Jonescc879a92021-11-18 22:40:18 +0000239
Gavin Makea2e3302023-03-11 06:46:20 +0000240 def __init__(
241 self,
242 name,
243 remote=None,
244 project=None,
245 revision=None,
246 manifestName=None,
247 groups=None,
248 default_groups=None,
249 path=None,
250 parent=None,
251 ):
252 self.name = name
253 self.remote = remote
254 self.project = project
255 self.revision = revision
256 self.manifestName = manifestName
257 self.groups = groups
258 self.default_groups = default_groups
259 self.path = path
260 self.parent = parent
261 self.annotations = []
262 outer_client = parent._outer_client or parent
263 if self.remote and not self.project:
264 raise ManifestParseError(
265 f"Submanifest {name}: must specify project when remote is "
266 "given."
267 )
268 # Construct the absolute path to the manifest file using the parent's
269 # method, so that we can correctly create our repo_client.
270 manifestFile = parent.SubmanifestInfoDir(
271 os.path.join(parent.path_prefix, self.relpath),
272 os.path.join("manifests", manifestName or "default.xml"),
273 )
274 linkFile = parent.SubmanifestInfoDir(
275 os.path.join(parent.path_prefix, self.relpath), MANIFEST_FILE_NAME
276 )
277 self.repo_client = RepoClient(
278 parent.repodir,
279 linkFile,
280 parent_groups=",".join(groups) or "",
281 submanifest_path=self.relpath,
282 outer_client=outer_client,
283 default_groups=default_groups,
284 )
LaMont Jonescc879a92021-11-18 22:40:18 +0000285
Gavin Makea2e3302023-03-11 06:46:20 +0000286 self.present = os.path.exists(manifestFile)
LaMont Jonescc879a92021-11-18 22:40:18 +0000287
Gavin Makea2e3302023-03-11 06:46:20 +0000288 def __eq__(self, other):
289 if not isinstance(other, _XmlSubmanifest):
290 return False
291 return (
292 self.name == other.name
293 and self.remote == other.remote
294 and self.project == other.project
295 and self.revision == other.revision
296 and self.manifestName == other.manifestName
297 and self.groups == other.groups
298 and self.default_groups == other.default_groups
299 and self.path == other.path
300 and sorted(self.annotations) == sorted(other.annotations)
301 )
LaMont Jonescc879a92021-11-18 22:40:18 +0000302
Gavin Makea2e3302023-03-11 06:46:20 +0000303 def __ne__(self, other):
304 return not self.__eq__(other)
LaMont Jonescc879a92021-11-18 22:40:18 +0000305
Gavin Makea2e3302023-03-11 06:46:20 +0000306 def ToSubmanifestSpec(self):
307 """Return a SubmanifestSpec object, populating attributes"""
308 mp = self.parent.manifestProject
309 remote = self.parent.remotes[
310 self.remote or self.parent.default.remote.name
311 ]
312 # If a project was given, generate the url from the remote and project.
313 # If not, use this manifestProject's url.
314 if self.project:
315 manifestUrl = remote.ToRemoteSpec(self.project).url
316 else:
317 manifestUrl = mp.GetRemote().url
318 manifestName = self.manifestName or "default.xml"
319 revision = self.revision or self.name
320 path = self.path or revision.split("/")[-1]
321 groups = self.groups or []
LaMont Jonescc879a92021-11-18 22:40:18 +0000322
Gavin Makea2e3302023-03-11 06:46:20 +0000323 return SubmanifestSpec(
324 self.name, manifestUrl, manifestName, revision, path, groups
325 )
LaMont Jonescc879a92021-11-18 22:40:18 +0000326
Gavin Makea2e3302023-03-11 06:46:20 +0000327 @property
328 def relpath(self):
329 """The path of this submanifest relative to the parent manifest."""
330 revision = self.revision or self.name
331 return self.path or revision.split("/")[-1]
LaMont Jonescc879a92021-11-18 22:40:18 +0000332
Gavin Makea2e3302023-03-11 06:46:20 +0000333 def GetGroupsStr(self):
334 """Returns the `groups` given for this submanifest."""
335 if self.groups:
336 return ",".join(self.groups)
337 return ""
LaMont Jones501733c2022-04-20 16:42:32 +0000338
Gavin Makea2e3302023-03-11 06:46:20 +0000339 def GetDefaultGroupsStr(self):
340 """Returns the `default-groups` given for this submanifest."""
341 return ",".join(self.default_groups or [])
342
343 def AddAnnotation(self, name, value, keep):
344 """Add annotations to the submanifest."""
345 self.annotations.append(Annotation(name, value, keep))
LaMont Jonescc879a92021-11-18 22:40:18 +0000346
347
348class SubmanifestSpec:
Gavin Makea2e3302023-03-11 06:46:20 +0000349 """The submanifest element, with all fields expanded."""
LaMont Jonescc879a92021-11-18 22:40:18 +0000350
Gavin Makea2e3302023-03-11 06:46:20 +0000351 def __init__(self, name, manifestUrl, manifestName, revision, path, groups):
352 self.name = name
353 self.manifestUrl = manifestUrl
354 self.manifestName = manifestName
355 self.revision = revision
356 self.path = path
357 self.groups = groups or []
LaMont Jonescc879a92021-11-18 22:40:18 +0000358
359
Shawn O. Pearcec8a300f2009-05-18 13:19:57 -0700360class XmlManifest(object):
Gavin Makea2e3302023-03-11 06:46:20 +0000361 """manages the repo configuration file"""
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700362
Gavin Makea2e3302023-03-11 06:46:20 +0000363 def __init__(
364 self,
365 repodir,
366 manifest_file,
367 local_manifests=None,
368 outer_client=None,
369 parent_groups="",
370 submanifest_path="",
371 default_groups=None,
372 ):
373 """Initialize.
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400374
Gavin Makea2e3302023-03-11 06:46:20 +0000375 Args:
376 repodir: Path to the .repo/ dir for holding all internal checkout
377 state. It must be in the top directory of the repo client
378 checkout.
379 manifest_file: Full path to the manifest file to parse. This will
380 usually be |repodir|/|MANIFEST_FILE_NAME|.
381 local_manifests: Full path to the directory of local override
382 manifests. This will usually be
383 |repodir|/|LOCAL_MANIFESTS_DIR_NAME|.
384 outer_client: RepoClient of the outer manifest.
385 parent_groups: a string, the groups to apply to this projects.
386 submanifest_path: The submanifest root relative to the repo root.
387 default_groups: a string, the default manifest groups to use.
388 """
389 # TODO(vapier): Move this out of this class.
390 self.globalConfig = GitConfig.ForUser()
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400391
Gavin Makea2e3302023-03-11 06:46:20 +0000392 self.repodir = os.path.abspath(repodir)
393 self._CheckLocalPath(submanifest_path)
394 self.topdir = os.path.dirname(self.repodir)
395 if submanifest_path:
396 # This avoids a trailing os.path.sep when submanifest_path is empty.
397 self.topdir = os.path.join(self.topdir, submanifest_path)
398 if manifest_file != os.path.abspath(manifest_file):
399 raise ManifestParseError("manifest_file must be abspath")
400 self.manifestFile = manifest_file
401 if not outer_client or outer_client == self:
402 # manifestFileOverrides only exists in the outer_client's manifest,
403 # since that is the only instance left when Unload() is called on
404 # the outer manifest.
405 self.manifestFileOverrides = {}
406 self.local_manifests = local_manifests
407 self._load_local_manifests = True
408 self.parent_groups = parent_groups
409 self.default_groups = default_groups
LaMont Jonescc879a92021-11-18 22:40:18 +0000410
Gavin Makea2e3302023-03-11 06:46:20 +0000411 if outer_client and self.isGitcClient:
412 raise ManifestParseError(
413 "Multi-manifest is incompatible with `gitc-init`"
414 )
LaMont Jonescc879a92021-11-18 22:40:18 +0000415
Gavin Makea2e3302023-03-11 06:46:20 +0000416 if submanifest_path and not outer_client:
417 # If passing a submanifest_path, there must be an outer_client.
418 raise ManifestParseError(f"Bad call to {self.__class__.__name__}")
LaMont Jonescc879a92021-11-18 22:40:18 +0000419
Gavin Makea2e3302023-03-11 06:46:20 +0000420 # If self._outer_client is None, this is not a checkout that supports
421 # multi-tree.
422 self._outer_client = outer_client or self
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700423
Gavin Makea2e3302023-03-11 06:46:20 +0000424 self.repoProject = RepoProject(
425 self,
426 "repo",
427 gitdir=os.path.join(repodir, "repo/.git"),
428 worktree=os.path.join(repodir, "repo"),
429 )
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700430
Gavin Makea2e3302023-03-11 06:46:20 +0000431 mp = self.SubmanifestProject(self.path_prefix)
432 self.manifestProject = mp
Mike Frysinger979d5bd2020-02-09 02:28:34 -0500433
Gavin Makea2e3302023-03-11 06:46:20 +0000434 # This is a bit hacky, but we're in a chicken & egg situation: all the
435 # normal repo settings live in the manifestProject which we just setup
436 # above, so we couldn't easily query before that. We assume Project()
437 # init doesn't care if this changes afterwards.
438 if os.path.exists(mp.gitdir) and mp.use_worktree:
439 mp.use_git_worktrees = True
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700440
Gavin Makea2e3302023-03-11 06:46:20 +0000441 self.Unload()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700442
Gavin Makea2e3302023-03-11 06:46:20 +0000443 def Override(self, name, load_local_manifests=True):
444 """Use a different manifest, just for the current instantiation."""
445 path = None
Basil Gelloc7453502018-05-25 20:23:52 +0300446
Gavin Makea2e3302023-03-11 06:46:20 +0000447 # Look for a manifest by path in the filesystem (including the cwd).
448 if not load_local_manifests:
449 local_path = os.path.abspath(name)
450 if os.path.isfile(local_path):
451 path = local_path
Basil Gelloc7453502018-05-25 20:23:52 +0300452
Gavin Makea2e3302023-03-11 06:46:20 +0000453 # Look for manifests by name from the manifests repo.
454 if path is None:
455 path = os.path.join(self.manifestProject.worktree, name)
456 if not os.path.isfile(path):
457 raise ManifestParseError("manifest %s not found" % name)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700458
Gavin Makea2e3302023-03-11 06:46:20 +0000459 self._load_local_manifests = load_local_manifests
460 self._outer_client.manifestFileOverrides[self.path_prefix] = path
461 self.Unload()
462 self._Load()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700463
Gavin Makea2e3302023-03-11 06:46:20 +0000464 def Link(self, name):
465 """Update the repo metadata to use a different manifest."""
466 self.Override(name)
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700467
Gavin Makea2e3302023-03-11 06:46:20 +0000468 # Old versions of repo would generate symlinks we need to clean up.
469 platform_utils.remove(self.manifestFile, missing_ok=True)
470 # This file is interpreted as if it existed inside the manifest repo.
471 # That allows us to use <include> with the relative file name.
472 with open(self.manifestFile, "w") as fp:
473 fp.write(
474 """<?xml version="1.0" encoding="UTF-8"?>
Mike Frysingera269b1c2020-02-21 00:49:41 -0500475<!--
476DO NOT EDIT THIS FILE! It is generated by repo and changes will be discarded.
477If you want to use a different manifest, use `repo init -m <file>` instead.
478
479If you want to customize your checkout by overriding manifest settings, use
480the local_manifests/ directory instead.
481
482For more information on repo manifests, check out:
483https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
484-->
485<manifest>
486 <include name="%s" />
487</manifest>
Gavin Makea2e3302023-03-11 06:46:20 +0000488"""
489 % (name,)
490 )
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700491
Gavin Makea2e3302023-03-11 06:46:20 +0000492 def _RemoteToXml(self, r, doc, root):
493 e = doc.createElement("remote")
494 root.appendChild(e)
495 e.setAttribute("name", r.name)
496 e.setAttribute("fetch", r.fetchUrl)
497 if r.pushUrl is not None:
498 e.setAttribute("pushurl", r.pushUrl)
499 if r.remoteAlias is not None:
500 e.setAttribute("alias", r.remoteAlias)
501 if r.reviewUrl is not None:
502 e.setAttribute("review", r.reviewUrl)
503 if r.revision is not None:
504 e.setAttribute("revision", r.revision)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800505
Gavin Makea2e3302023-03-11 06:46:20 +0000506 for a in r.annotations:
507 if a.keep == "true":
508 ae = doc.createElement("annotation")
509 ae.setAttribute("name", a.name)
510 ae.setAttribute("value", a.value)
511 e.appendChild(ae)
Jack Neus6ea0cae2021-07-20 20:52:33 +0000512
Gavin Makea2e3302023-03-11 06:46:20 +0000513 def _SubmanifestToXml(self, r, doc, root):
514 """Generate XML <submanifest/> node."""
515 e = doc.createElement("submanifest")
516 root.appendChild(e)
517 e.setAttribute("name", r.name)
518 if r.remote is not None:
519 e.setAttribute("remote", r.remote)
520 if r.project is not None:
521 e.setAttribute("project", r.project)
522 if r.manifestName is not None:
523 e.setAttribute("manifest-name", r.manifestName)
524 if r.revision is not None:
525 e.setAttribute("revision", r.revision)
526 if r.path is not None:
527 e.setAttribute("path", r.path)
528 if r.groups:
529 e.setAttribute("groups", r.GetGroupsStr())
530 if r.default_groups:
531 e.setAttribute("default-groups", r.GetDefaultGroupsStr())
LaMont Jonescc879a92021-11-18 22:40:18 +0000532
Gavin Makea2e3302023-03-11 06:46:20 +0000533 for a in r.annotations:
534 if a.keep == "true":
535 ae = doc.createElement("annotation")
536 ae.setAttribute("name", a.name)
537 ae.setAttribute("value", a.value)
538 e.appendChild(ae)
LaMont Jonescc879a92021-11-18 22:40:18 +0000539
Gavin Makea2e3302023-03-11 06:46:20 +0000540 def _ParseList(self, field):
541 """Parse fields that contain flattened lists.
Mike Frysinger51e39d52020-12-04 05:32:06 -0500542
Gavin Makea2e3302023-03-11 06:46:20 +0000543 These are whitespace & comma separated. Empty elements will be
544 discarded.
545 """
546 return [x for x in re.split(r"[,\s]+", field) if x]
Josh Triplett884a3872014-06-12 14:57:29 -0700547
Gavin Makea2e3302023-03-11 06:46:20 +0000548 def ToXml(
549 self,
550 peg_rev=False,
551 peg_rev_upstream=True,
552 peg_rev_dest_branch=True,
553 groups=None,
554 omit_local=False,
555 ):
556 """Return the current manifest XML."""
557 mp = self.manifestProject
Colin Cross5acde752012-03-28 20:15:45 -0700558
Gavin Makea2e3302023-03-11 06:46:20 +0000559 if groups is None:
560 groups = mp.manifest_groups
561 if groups:
562 groups = self._ParseList(groups)
Colin Cross5acde752012-03-28 20:15:45 -0700563
Gavin Makea2e3302023-03-11 06:46:20 +0000564 doc = xml.dom.minidom.Document()
565 root = doc.createElement("manifest")
566 if self.is_submanifest:
567 root.setAttribute("path", self.path_prefix)
568 doc.appendChild(root)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800569
Gavin Makea2e3302023-03-11 06:46:20 +0000570 # Save out the notice. There's a little bit of work here to give it the
571 # right whitespace, which assumes that the notice is automatically
572 # indented by 4 by minidom.
573 if self.notice:
574 notice_element = root.appendChild(doc.createElement("notice"))
575 notice_lines = self.notice.splitlines()
576 indented_notice = (
577 "\n".join(" " * 4 + line for line in notice_lines)
578 )[4:]
579 notice_element.appendChild(doc.createTextNode(indented_notice))
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700580
Gavin Makea2e3302023-03-11 06:46:20 +0000581 d = self.default
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800582
Gavin Makea2e3302023-03-11 06:46:20 +0000583 for r in sorted(self.remotes):
584 self._RemoteToXml(self.remotes[r], doc, root)
585 if self.remotes:
586 root.appendChild(doc.createTextNode(""))
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800587
Gavin Makea2e3302023-03-11 06:46:20 +0000588 have_default = False
589 e = doc.createElement("default")
590 if d.remote:
591 have_default = True
592 e.setAttribute("remote", d.remote.name)
593 if d.revisionExpr:
594 have_default = True
595 e.setAttribute("revision", d.revisionExpr)
596 if d.destBranchExpr:
597 have_default = True
598 e.setAttribute("dest-branch", d.destBranchExpr)
599 if d.upstreamExpr:
600 have_default = True
601 e.setAttribute("upstream", d.upstreamExpr)
602 if d.sync_j is not None:
603 have_default = True
604 e.setAttribute("sync-j", "%d" % d.sync_j)
605 if d.sync_c:
606 have_default = True
607 e.setAttribute("sync-c", "true")
608 if d.sync_s:
609 have_default = True
610 e.setAttribute("sync-s", "true")
611 if not d.sync_tags:
612 have_default = True
613 e.setAttribute("sync-tags", "false")
614 if have_default:
615 root.appendChild(e)
616 root.appendChild(doc.createTextNode(""))
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800617
Gavin Makea2e3302023-03-11 06:46:20 +0000618 if self._manifest_server:
619 e = doc.createElement("manifest-server")
620 e.setAttribute("url", self._manifest_server)
621 root.appendChild(e)
622 root.appendChild(doc.createTextNode(""))
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700623
Gavin Makea2e3302023-03-11 06:46:20 +0000624 for r in sorted(self.submanifests):
625 self._SubmanifestToXml(self.submanifests[r], doc, root)
626 if self.submanifests:
627 root.appendChild(doc.createTextNode(""))
LaMont Jonescc879a92021-11-18 22:40:18 +0000628
Gavin Makea2e3302023-03-11 06:46:20 +0000629 def output_projects(parent, parent_node, projects):
630 for project_name in projects:
631 for project in self._projects[project_name]:
632 output_project(parent, parent_node, project)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800633
Gavin Makea2e3302023-03-11 06:46:20 +0000634 def output_project(parent, parent_node, p):
635 if not p.MatchesGroups(groups):
636 return
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800637
Gavin Makea2e3302023-03-11 06:46:20 +0000638 if omit_local and self.IsFromLocalManifest(p):
639 return
LaMont Jonesa8cf5752022-07-15 20:31:33 +0000640
Gavin Makea2e3302023-03-11 06:46:20 +0000641 name = p.name
642 relpath = p.relpath
643 if parent:
644 name = self._UnjoinName(parent.name, name)
645 relpath = self._UnjoinRelpath(parent.relpath, relpath)
Colin Cross5acde752012-03-28 20:15:45 -0700646
Gavin Makea2e3302023-03-11 06:46:20 +0000647 e = doc.createElement("project")
648 parent_node.appendChild(e)
649 e.setAttribute("name", name)
650 if relpath != name:
651 e.setAttribute("path", relpath)
652 remoteName = None
653 if d.remote:
654 remoteName = d.remote.name
655 if not d.remote or p.remote.orig_name != remoteName:
656 remoteName = p.remote.orig_name
657 e.setAttribute("remote", remoteName)
658 if peg_rev:
659 if self.IsMirror:
660 value = p.bare_git.rev_parse(p.revisionExpr + "^0")
661 else:
662 value = p.work_git.rev_parse(HEAD + "^0")
663 e.setAttribute("revision", value)
664 if peg_rev_upstream:
665 if p.upstream:
666 e.setAttribute("upstream", p.upstream)
667 elif value != p.revisionExpr:
668 # Only save the origin if the origin is not a sha1, and
669 # the default isn't our value
670 e.setAttribute("upstream", p.revisionExpr)
671
672 if peg_rev_dest_branch:
673 if p.dest_branch:
674 e.setAttribute("dest-branch", p.dest_branch)
675 elif value != p.revisionExpr:
676 e.setAttribute("dest-branch", p.revisionExpr)
677
678 else:
679 revision = (
680 self.remotes[p.remote.orig_name].revision or d.revisionExpr
681 )
682 if not revision or revision != p.revisionExpr:
683 e.setAttribute("revision", p.revisionExpr)
684 elif p.revisionId:
685 e.setAttribute("revision", p.revisionId)
686 if p.upstream and (
687 p.upstream != p.revisionExpr or p.upstream != d.upstreamExpr
688 ):
689 e.setAttribute("upstream", p.upstream)
690
691 if p.dest_branch and p.dest_branch != d.destBranchExpr:
692 e.setAttribute("dest-branch", p.dest_branch)
693
694 for c in p.copyfiles:
695 ce = doc.createElement("copyfile")
696 ce.setAttribute("src", c.src)
697 ce.setAttribute("dest", c.dest)
698 e.appendChild(ce)
699
700 for lf in p.linkfiles:
701 le = doc.createElement("linkfile")
702 le.setAttribute("src", lf.src)
703 le.setAttribute("dest", lf.dest)
704 e.appendChild(le)
705
706 default_groups = ["all", "name:%s" % p.name, "path:%s" % p.relpath]
707 egroups = [g for g in p.groups if g not in default_groups]
708 if egroups:
709 e.setAttribute("groups", ",".join(egroups))
710
711 for a in p.annotations:
712 if a.keep == "true":
713 ae = doc.createElement("annotation")
714 ae.setAttribute("name", a.name)
715 ae.setAttribute("value", a.value)
716 e.appendChild(ae)
717
718 if p.sync_c:
719 e.setAttribute("sync-c", "true")
720
721 if p.sync_s:
722 e.setAttribute("sync-s", "true")
723
724 if not p.sync_tags:
725 e.setAttribute("sync-tags", "false")
726
727 if p.clone_depth:
728 e.setAttribute("clone-depth", str(p.clone_depth))
729
730 self._output_manifest_project_extras(p, e)
731
732 if p.subprojects:
733 subprojects = set(subp.name for subp in p.subprojects)
734 output_projects(p, e, list(sorted(subprojects)))
735
736 projects = set(p.name for p in self._paths.values() if not p.parent)
737 output_projects(None, root, list(sorted(projects)))
738
739 if self._repo_hooks_project:
740 root.appendChild(doc.createTextNode(""))
741 e = doc.createElement("repo-hooks")
742 e.setAttribute("in-project", self._repo_hooks_project.name)
743 e.setAttribute(
744 "enabled-list",
745 " ".join(self._repo_hooks_project.enabled_repo_hooks),
746 )
747 root.appendChild(e)
748
749 if self._superproject:
750 root.appendChild(doc.createTextNode(""))
751 e = doc.createElement("superproject")
752 e.setAttribute("name", self._superproject.name)
753 remoteName = None
754 if d.remote:
755 remoteName = d.remote.name
756 remote = self._superproject.remote
757 if not d.remote or remote.orig_name != remoteName:
758 remoteName = remote.orig_name
759 e.setAttribute("remote", remoteName)
760 revision = remote.revision or d.revisionExpr
761 if not revision or revision != self._superproject.revision:
762 e.setAttribute("revision", self._superproject.revision)
763 root.appendChild(e)
764
765 if self._contactinfo.bugurl != Wrapper().BUG_URL:
766 root.appendChild(doc.createTextNode(""))
767 e = doc.createElement("contactinfo")
768 e.setAttribute("bugurl", self._contactinfo.bugurl)
769 root.appendChild(e)
770
771 return doc
772
773 def ToDict(self, **kwargs):
774 """Return the current manifest as a dictionary."""
775 # Elements that may only appear once.
776 SINGLE_ELEMENTS = {
777 "notice",
778 "default",
779 "manifest-server",
780 "repo-hooks",
781 "superproject",
782 "contactinfo",
783 }
784 # Elements that may be repeated.
785 MULTI_ELEMENTS = {
786 "remote",
787 "remove-project",
788 "project",
789 "extend-project",
790 "include",
791 "submanifest",
792 # These are children of 'project' nodes.
793 "annotation",
794 "project",
795 "copyfile",
796 "linkfile",
797 }
798
799 doc = self.ToXml(**kwargs)
800 ret = {}
801
802 def append_children(ret, node):
803 for child in node.childNodes:
804 if child.nodeType == xml.dom.Node.ELEMENT_NODE:
805 attrs = child.attributes
806 element = dict(
807 (attrs.item(i).localName, attrs.item(i).value)
808 for i in range(attrs.length)
809 )
810 if child.nodeName in SINGLE_ELEMENTS:
811 ret[child.nodeName] = element
812 elif child.nodeName in MULTI_ELEMENTS:
813 ret.setdefault(child.nodeName, []).append(element)
814 else:
815 raise ManifestParseError(
816 'Unhandled element "%s"' % (child.nodeName,)
817 )
818
819 append_children(element, child)
820
821 append_children(ret, doc.firstChild)
822
823 return ret
824
825 def Save(self, fd, **kwargs):
826 """Write the current manifest out to the given file descriptor."""
827 doc = self.ToXml(**kwargs)
828 doc.writexml(fd, "", " ", "\n", "UTF-8")
829
830 def _output_manifest_project_extras(self, p, e):
831 """Manifests can modify e if they support extra project attributes."""
832
833 @property
834 def is_multimanifest(self):
835 """Whether this is a multimanifest checkout.
836
837 This is safe to use as long as the outermost manifest XML has been
838 parsed.
839 """
840 return bool(self._outer_client._submanifests)
841
842 @property
843 def is_submanifest(self):
844 """Whether this manifest is a submanifest.
845
846 This is safe to use as long as the outermost manifest XML has been
847 parsed.
848 """
849 return self._outer_client and self._outer_client != self
850
851 @property
852 def outer_client(self):
853 """The instance of the outermost manifest client."""
854 self._Load()
855 return self._outer_client
856
857 @property
858 def all_manifests(self):
859 """Generator yielding all (sub)manifests, in depth-first order."""
860 self._Load()
861 outer = self._outer_client
862 yield outer
863 for tree in outer.all_children:
864 yield tree
865
866 @property
867 def all_children(self):
868 """Generator yielding all (present) child submanifests."""
869 self._Load()
870 for child in self._submanifests.values():
871 if child.repo_client:
872 yield child.repo_client
873 for tree in child.repo_client.all_children:
874 yield tree
875
876 @property
877 def path_prefix(self):
878 """The path of this submanifest, relative to the outermost manifest."""
879 if not self._outer_client or self == self._outer_client:
880 return ""
881 return os.path.relpath(self.topdir, self._outer_client.topdir)
882
883 @property
884 def all_paths(self):
885 """All project paths for all (sub)manifests.
886
887 See also `paths`.
888
889 Returns:
890 A dictionary of {path: Project()}. `path` is relative to the outer
891 manifest.
892 """
893 ret = {}
894 for tree in self.all_manifests:
895 prefix = tree.path_prefix
896 ret.update(
897 {os.path.join(prefix, k): v for k, v in tree.paths.items()}
898 )
899 return ret
900
901 @property
902 def all_projects(self):
903 """All projects for all (sub)manifests. See `projects`."""
904 return list(
905 itertools.chain.from_iterable(
906 x._paths.values() for x in self.all_manifests
907 )
908 )
909
910 @property
911 def paths(self):
912 """Return all paths for this manifest.
913
914 Returns:
915 A dictionary of {path: Project()}. `path` is relative to this
916 manifest.
917 """
918 self._Load()
919 return self._paths
920
921 @property
922 def projects(self):
923 """Return a list of all Projects in this manifest."""
924 self._Load()
925 return list(self._paths.values())
926
927 @property
928 def remotes(self):
929 """Return a list of remotes for this manifest."""
930 self._Load()
931 return self._remotes
932
933 @property
934 def default(self):
935 """Return default values for this manifest."""
936 self._Load()
937 return self._default
938
939 @property
940 def submanifests(self):
941 """All submanifests in this manifest."""
942 self._Load()
943 return self._submanifests
944
945 @property
946 def repo_hooks_project(self):
947 self._Load()
948 return self._repo_hooks_project
949
950 @property
951 def superproject(self):
952 self._Load()
953 return self._superproject
954
955 @property
956 def contactinfo(self):
957 self._Load()
958 return self._contactinfo
959
960 @property
961 def notice(self):
962 self._Load()
963 return self._notice
964
965 @property
966 def manifest_server(self):
967 self._Load()
968 return self._manifest_server
969
970 @property
971 def CloneBundle(self):
972 clone_bundle = self.manifestProject.clone_bundle
973 if clone_bundle is None:
974 return False if self.manifestProject.partial_clone else True
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800975 else:
Gavin Makea2e3302023-03-11 06:46:20 +0000976 return clone_bundle
Sean McAllisteraf908cb2020-04-20 08:41:58 -0600977
Gavin Makea2e3302023-03-11 06:46:20 +0000978 @property
979 def CloneFilter(self):
980 if self.manifestProject.partial_clone:
981 return self.manifestProject.clone_filter
982 return None
Sean McAllisteraf908cb2020-04-20 08:41:58 -0600983
Gavin Makea2e3302023-03-11 06:46:20 +0000984 @property
Jason Chang17833322023-05-23 13:06:55 -0700985 def CloneFilterForDepth(self):
986 if self.manifestProject.clone_filter_for_depth:
987 return self.manifestProject.clone_filter_for_depth
988 return None
989
990 @property
Gavin Makea2e3302023-03-11 06:46:20 +0000991 def PartialCloneExclude(self):
992 exclude = self.manifest.manifestProject.partial_clone_exclude or ""
993 return set(x.strip() for x in exclude.split(","))
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800994
Gavin Makea2e3302023-03-11 06:46:20 +0000995 def SetManifestOverride(self, path):
996 """Override manifestFile. The caller must call Unload()"""
997 self._outer_client.manifest.manifestFileOverrides[
998 self.path_prefix
999 ] = path
Simon Ruggier7e59de22015-07-24 12:50:06 +02001000
Gavin Makea2e3302023-03-11 06:46:20 +00001001 @property
1002 def UseLocalManifests(self):
1003 return self._load_local_manifests
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -08001004
Gavin Makea2e3302023-03-11 06:46:20 +00001005 def SetUseLocalManifests(self, value):
1006 self._load_local_manifests = value
Jeff Hamiltone0df2322014-04-21 17:10:59 -05001007
Gavin Makea2e3302023-03-11 06:46:20 +00001008 @property
1009 def HasLocalManifests(self):
1010 return self._load_local_manifests and self.local_manifests
Colin Cross5acde752012-03-28 20:15:45 -07001011
Gavin Makea2e3302023-03-11 06:46:20 +00001012 def IsFromLocalManifest(self, project):
1013 """Is the project from a local manifest?"""
1014 return any(
1015 x.startswith(LOCAL_MANIFEST_GROUP_PREFIX) for x in project.groups
1016 )
James W. Mills24c13082012-04-12 15:04:13 -05001017
Gavin Makea2e3302023-03-11 06:46:20 +00001018 @property
1019 def IsMirror(self):
1020 return self.manifestProject.mirror
Anatol Pomazau79770d22012-04-20 14:41:59 -07001021
Gavin Makea2e3302023-03-11 06:46:20 +00001022 @property
1023 def UseGitWorktrees(self):
1024 return self.manifestProject.use_worktree
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001025
Gavin Makea2e3302023-03-11 06:46:20 +00001026 @property
1027 def IsArchive(self):
1028 return self.manifestProject.archive
YOUNG HO CHAa32c92c2018-02-14 16:57:31 +09001029
Gavin Makea2e3302023-03-11 06:46:20 +00001030 @property
1031 def HasSubmodules(self):
1032 return self.manifestProject.submodules
Dan Willemsen88409222015-08-17 15:29:10 -07001033
Gavin Makea2e3302023-03-11 06:46:20 +00001034 @property
1035 def EnableGitLfs(self):
1036 return self.manifestProject.git_lfs
Simran Basib9a1b732015-08-20 12:19:28 -07001037
Gavin Makea2e3302023-03-11 06:46:20 +00001038 def FindManifestByPath(self, path):
1039 """Returns the manifest containing path."""
1040 path = os.path.abspath(path)
1041 manifest = self._outer_client or self
1042 old = None
1043 while manifest._submanifests and manifest != old:
1044 old = manifest
1045 for name in manifest._submanifests:
1046 tree = manifest._submanifests[name]
1047 if path.startswith(tree.repo_client.manifest.topdir):
1048 manifest = tree.repo_client
1049 break
1050 return manifest
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001051
Gavin Makea2e3302023-03-11 06:46:20 +00001052 @property
1053 def subdir(self):
1054 """Returns the path for per-submanifest objects for this manifest."""
1055 return self.SubmanifestInfoDir(self.path_prefix)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001056
Gavin Makea2e3302023-03-11 06:46:20 +00001057 def SubmanifestInfoDir(self, submanifest_path, object_path=""):
1058 """Return the path to submanifest-specific info for a submanifest.
Doug Anderson37282b42011-03-04 11:54:18 -08001059
Gavin Makea2e3302023-03-11 06:46:20 +00001060 Return the full path of the directory in which to put per-manifest
1061 objects.
Raman Tenneti1bb4fb22021-01-07 16:50:45 -08001062
Gavin Makea2e3302023-03-11 06:46:20 +00001063 Args:
1064 submanifest_path: a string, the path of the submanifest, relative to
1065 the outermost topdir. If empty, then repodir is returned.
1066 object_path: a string, relative path to append to the submanifest
1067 info directory path.
1068 """
1069 if submanifest_path:
1070 return os.path.join(
1071 self.repodir, SUBMANIFEST_DIR, submanifest_path, object_path
1072 )
1073 else:
1074 return os.path.join(self.repodir, object_path)
Raman Tenneti1c3f57e2021-05-04 12:32:13 -07001075
Gavin Makea2e3302023-03-11 06:46:20 +00001076 def SubmanifestProject(self, submanifest_path):
1077 """Return a manifestProject for a submanifest."""
1078 subdir = self.SubmanifestInfoDir(submanifest_path)
1079 mp = ManifestProject(
1080 self,
1081 "manifests",
1082 gitdir=os.path.join(subdir, "manifests.git"),
1083 worktree=os.path.join(subdir, "manifests"),
1084 )
1085 return mp
Mike Frysinger23411d32020-09-02 04:31:10 -04001086
Gavin Makea2e3302023-03-11 06:46:20 +00001087 def GetDefaultGroupsStr(self, with_platform=True):
1088 """Returns the default group string to use.
Mike Frysinger23411d32020-09-02 04:31:10 -04001089
Gavin Makea2e3302023-03-11 06:46:20 +00001090 Args:
1091 with_platform: a boolean, whether to include the group for the
1092 underlying platform.
1093 """
1094 groups = ",".join(self.default_groups or ["default"])
1095 if with_platform:
1096 groups += f",platform-{platform.system().lower()}"
1097 return groups
Mike Frysinger23411d32020-09-02 04:31:10 -04001098
Gavin Makea2e3302023-03-11 06:46:20 +00001099 def GetGroupsStr(self):
1100 """Returns the manifest group string that should be synced."""
1101 return (
1102 self.manifestProject.manifest_groups or self.GetDefaultGroupsStr()
1103 )
Mike Frysinger23411d32020-09-02 04:31:10 -04001104
Gavin Makea2e3302023-03-11 06:46:20 +00001105 def Unload(self):
1106 """Unload the manifest.
Mike Frysinger23411d32020-09-02 04:31:10 -04001107
Gavin Makea2e3302023-03-11 06:46:20 +00001108 If the manifest files have been changed since Load() was called, this
1109 will cause the new/updated manifest to be used.
Mike Frysinger23411d32020-09-02 04:31:10 -04001110
Gavin Makea2e3302023-03-11 06:46:20 +00001111 """
1112 self._loaded = False
1113 self._projects = {}
1114 self._paths = {}
1115 self._remotes = {}
1116 self._default = None
1117 self._submanifests = {}
1118 self._repo_hooks_project = None
1119 self._superproject = None
1120 self._contactinfo = ContactInfo(Wrapper().BUG_URL)
1121 self._notice = None
1122 self.branch = None
1123 self._manifest_server = None
Mike Frysinger23411d32020-09-02 04:31:10 -04001124
Gavin Makea2e3302023-03-11 06:46:20 +00001125 def Load(self):
1126 """Read the manifest into memory."""
1127 # Do not expose internal arguments.
1128 self._Load()
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -08001129
Gavin Makea2e3302023-03-11 06:46:20 +00001130 def _Load(self, initial_client=None, submanifest_depth=0):
1131 if submanifest_depth > MAX_SUBMANIFEST_DEPTH:
1132 raise ManifestParseError(
1133 "maximum submanifest depth %d exceeded." % MAX_SUBMANIFEST_DEPTH
1134 )
1135 if not self._loaded:
1136 if self._outer_client and self._outer_client != self:
1137 # This will load all clients.
1138 self._outer_client._Load(initial_client=self)
Simran Basib9a1b732015-08-20 12:19:28 -07001139
Gavin Makea2e3302023-03-11 06:46:20 +00001140 savedManifestFile = self.manifestFile
1141 override = self._outer_client.manifestFileOverrides.get(
1142 self.path_prefix
1143 )
1144 if override:
1145 self.manifestFile = override
Mike Frysinger1d00a7e2021-12-21 00:40:31 -05001146
Gavin Makea2e3302023-03-11 06:46:20 +00001147 try:
1148 m = self.manifestProject
1149 b = m.GetBranch(m.CurrentBranch).merge
1150 if b is not None and b.startswith(R_HEADS):
1151 b = b[len(R_HEADS) :]
1152 self.branch = b
LaMont Jonescc879a92021-11-18 22:40:18 +00001153
Gavin Makea2e3302023-03-11 06:46:20 +00001154 parent_groups = self.parent_groups
1155 if self.path_prefix:
1156 parent_groups = (
1157 f"{SUBMANIFEST_GROUP_PREFIX}:path:"
1158 f"{self.path_prefix},{parent_groups}"
1159 )
LaMont Jonesff6b1da2022-06-01 21:03:34 +00001160
Gavin Makea2e3302023-03-11 06:46:20 +00001161 # The manifestFile was specified by the user which is why we
1162 # allow include paths to point anywhere.
1163 nodes = []
1164 nodes.append(
1165 self._ParseManifestXml(
1166 self.manifestFile,
1167 self.manifestProject.worktree,
1168 parent_groups=parent_groups,
1169 restrict_includes=False,
1170 )
1171 )
LaMont Jonescc879a92021-11-18 22:40:18 +00001172
Gavin Makea2e3302023-03-11 06:46:20 +00001173 if self._load_local_manifests and self.local_manifests:
1174 try:
1175 for local_file in sorted(
1176 platform_utils.listdir(self.local_manifests)
1177 ):
1178 if local_file.endswith(".xml"):
1179 local = os.path.join(
1180 self.local_manifests, local_file
1181 )
1182 # Since local manifests are entirely managed by
1183 # the user, allow them to point anywhere the
1184 # user wants.
1185 local_group = (
1186 f"{LOCAL_MANIFEST_GROUP_PREFIX}:"
1187 f"{local_file[:-4]}"
1188 )
1189 nodes.append(
1190 self._ParseManifestXml(
1191 local,
1192 self.subdir,
1193 parent_groups=(
1194 f"{local_group},{parent_groups}"
1195 ),
1196 restrict_includes=False,
1197 )
1198 )
1199 except OSError:
1200 pass
Raman Tenneti080877e2021-03-09 15:19:06 -08001201
Gavin Makea2e3302023-03-11 06:46:20 +00001202 try:
1203 self._ParseManifest(nodes)
1204 except ManifestParseError as e:
1205 # There was a problem parsing, unload ourselves in case they
1206 # catch this error and try again later, we will show the
1207 # correct error
1208 self.Unload()
1209 raise e
Raman Tenneti080877e2021-03-09 15:19:06 -08001210
Gavin Makea2e3302023-03-11 06:46:20 +00001211 if self.IsMirror:
1212 self._AddMetaProjectMirror(self.repoProject)
1213 self._AddMetaProjectMirror(self.manifestProject)
LaMont Jonesa2ff20d2022-04-07 16:49:06 +00001214
Gavin Makea2e3302023-03-11 06:46:20 +00001215 self._loaded = True
1216 finally:
1217 if override:
1218 self.manifestFile = savedManifestFile
LaMont Jonesa2ff20d2022-04-07 16:49:06 +00001219
Gavin Makea2e3302023-03-11 06:46:20 +00001220 # Now that we have loaded this manifest, load any submanifests as
1221 # well. We need to do this after self._loaded is set to avoid
1222 # looping.
1223 for name in self._submanifests:
1224 tree = self._submanifests[name]
1225 tree.ToSubmanifestSpec()
1226 present = os.path.exists(
1227 os.path.join(self.subdir, MANIFEST_FILE_NAME)
1228 )
1229 if present and tree.present and not tree.repo_client:
1230 if initial_client and initial_client.topdir == self.topdir:
1231 tree.repo_client = self
1232 tree.present = present
1233 elif not os.path.exists(self.subdir):
1234 tree.present = False
1235 if present and tree.present:
1236 tree.repo_client._Load(
1237 initial_client=initial_client,
1238 submanifest_depth=submanifest_depth + 1,
1239 )
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001240
Gavin Makea2e3302023-03-11 06:46:20 +00001241 def _ParseManifestXml(
Shuchuan Zeng3e3340d2023-04-18 10:36:50 +08001242 self,
1243 path,
1244 include_root,
1245 parent_groups="",
1246 restrict_includes=True,
1247 parent_node=None,
Gavin Makea2e3302023-03-11 06:46:20 +00001248 ):
1249 """Parse a manifest XML and return the computed nodes.
LaMont Jonesa2ff20d2022-04-07 16:49:06 +00001250
Gavin Makea2e3302023-03-11 06:46:20 +00001251 Args:
1252 path: The XML file to read & parse.
1253 include_root: The path to interpret include "name"s relative to.
1254 parent_groups: The groups to apply to this projects.
1255 restrict_includes: Whether to constrain the "name" attribute of
1256 includes.
Shuchuan Zeng3e3340d2023-04-18 10:36:50 +08001257 parent_node: The parent include node, to apply attribute to this
1258 projects.
LaMont Jonescc879a92021-11-18 22:40:18 +00001259
Gavin Makea2e3302023-03-11 06:46:20 +00001260 Returns:
1261 List of XML nodes.
1262 """
1263 try:
1264 root = xml.dom.minidom.parse(path)
1265 except (OSError, xml.parsers.expat.ExpatError) as e:
1266 raise ManifestParseError(
1267 "error parsing manifest %s: %s" % (path, e)
1268 )
David Pursehouse2d5a0df2012-11-13 02:50:36 +09001269
Gavin Makea2e3302023-03-11 06:46:20 +00001270 if not root or not root.childNodes:
1271 raise ManifestParseError("no root node in %s" % (path,))
Shawn O. Pearce5cc66792008-10-23 16:19:27 -07001272
Gavin Makea2e3302023-03-11 06:46:20 +00001273 for manifest in root.childNodes:
1274 if manifest.nodeName == "manifest":
1275 break
1276 else:
1277 raise ManifestParseError("no <manifest> in %s" % (path,))
Shawn O. Pearcee284ad12008-11-04 07:37:10 -08001278
LaMont Jonesb90a4222022-04-14 15:00:09 +00001279 nodes = []
Gavin Makea2e3302023-03-11 06:46:20 +00001280 for node in manifest.childNodes:
1281 if node.nodeName == "include":
1282 name = self._reqatt(node, "name")
1283 if restrict_includes:
1284 msg = self._CheckLocalPath(name)
1285 if msg:
1286 raise ManifestInvalidPathError(
1287 '<include> invalid "name": %s: %s' % (name, msg)
1288 )
1289 include_groups = ""
1290 if parent_groups:
1291 include_groups = parent_groups
1292 if node.hasAttribute("groups"):
1293 include_groups = (
1294 node.getAttribute("groups") + "," + include_groups
1295 )
1296 fp = os.path.join(include_root, name)
1297 if not os.path.isfile(fp):
1298 raise ManifestParseError(
1299 "include [%s/]%s doesn't exist or isn't a file"
1300 % (include_root, name)
1301 )
1302 try:
1303 nodes.extend(
Shuchuan Zeng3e3340d2023-04-18 10:36:50 +08001304 self._ParseManifestXml(
1305 fp, include_root, include_groups, parent_node=node
1306 )
Gavin Makea2e3302023-03-11 06:46:20 +00001307 )
1308 # should isolate this to the exact exception, but that's
1309 # tricky. actual parsing implementation may vary.
1310 except (
1311 KeyboardInterrupt,
1312 RuntimeError,
1313 SystemExit,
1314 ManifestParseError,
1315 ):
1316 raise
1317 except Exception as e:
1318 raise ManifestParseError(
1319 "failed parsing included manifest %s: %s" % (name, e)
1320 )
1321 else:
1322 if parent_groups and node.nodeName == "project":
1323 nodeGroups = parent_groups
1324 if node.hasAttribute("groups"):
1325 nodeGroups = (
1326 node.getAttribute("groups") + "," + nodeGroups
1327 )
1328 node.setAttribute("groups", nodeGroups)
Shuchuan Zeng3e3340d2023-04-18 10:36:50 +08001329 if (
1330 parent_node
1331 and node.nodeName == "project"
1332 and not node.hasAttribute("revision")
1333 ):
1334 node.setAttribute(
1335 "revision", parent_node.getAttribute("revision")
1336 )
Gavin Makea2e3302023-03-11 06:46:20 +00001337 nodes.append(node)
1338 return nodes
LaMont Jonesb90a4222022-04-14 15:00:09 +00001339
Gavin Makea2e3302023-03-11 06:46:20 +00001340 def _ParseManifest(self, node_list):
1341 for node in itertools.chain(*node_list):
1342 if node.nodeName == "remote":
1343 remote = self._ParseRemote(node)
1344 if remote:
1345 if remote.name in self._remotes:
1346 if remote != self._remotes[remote.name]:
1347 raise ManifestParseError(
1348 "remote %s already exists with different "
1349 "attributes" % (remote.name)
1350 )
1351 else:
1352 self._remotes[remote.name] = remote
LaMont Jonesb90a4222022-04-14 15:00:09 +00001353
Gavin Makea2e3302023-03-11 06:46:20 +00001354 for node in itertools.chain(*node_list):
1355 if node.nodeName == "default":
1356 new_default = self._ParseDefault(node)
1357 emptyDefault = (
1358 not node.hasAttributes() and not node.hasChildNodes()
1359 )
1360 if self._default is None:
1361 self._default = new_default
1362 elif not emptyDefault and new_default != self._default:
1363 raise ManifestParseError(
1364 "duplicate default in %s" % (self.manifestFile)
1365 )
LaMont Jonesb90a4222022-04-14 15:00:09 +00001366
Julien Campergue74879922013-10-09 14:38:46 +02001367 if self._default is None:
Gavin Makea2e3302023-03-11 06:46:20 +00001368 self._default = _Default()
Julien Campergue74879922013-10-09 14:38:46 +02001369
Gavin Makea2e3302023-03-11 06:46:20 +00001370 submanifest_paths = set()
1371 for node in itertools.chain(*node_list):
1372 if node.nodeName == "submanifest":
1373 submanifest = self._ParseSubmanifest(node)
1374 if submanifest:
1375 if submanifest.name in self._submanifests:
1376 if submanifest != self._submanifests[submanifest.name]:
1377 raise ManifestParseError(
1378 "submanifest %s already exists with different "
1379 "attributes" % (submanifest.name)
1380 )
1381 else:
1382 self._submanifests[submanifest.name] = submanifest
1383 submanifest_paths.add(submanifest.relpath)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001384
Gavin Makea2e3302023-03-11 06:46:20 +00001385 for node in itertools.chain(*node_list):
1386 if node.nodeName == "notice":
1387 if self._notice is not None:
1388 raise ManifestParseError(
1389 "duplicate notice in %s" % (self.manifestFile)
1390 )
1391 self._notice = self._ParseNotice(node)
LaMont Jonescc879a92021-11-18 22:40:18 +00001392
Gavin Makea2e3302023-03-11 06:46:20 +00001393 for node in itertools.chain(*node_list):
1394 if node.nodeName == "manifest-server":
1395 url = self._reqatt(node, "url")
1396 if self._manifest_server is not None:
1397 raise ManifestParseError(
1398 "duplicate manifest-server in %s" % (self.manifestFile)
1399 )
1400 self._manifest_server = url
Doug Anderson2b8db3c2010-11-01 15:08:06 -07001401
Gavin Makea2e3302023-03-11 06:46:20 +00001402 def recursively_add_projects(project):
1403 projects = self._projects.setdefault(project.name, [])
1404 if project.relpath is None:
1405 raise ManifestParseError(
1406 "missing path for %s in %s"
1407 % (project.name, self.manifestFile)
1408 )
1409 if project.relpath in self._paths:
1410 raise ManifestParseError(
1411 "duplicate path %s in %s"
1412 % (project.relpath, self.manifestFile)
1413 )
1414 for tree in submanifest_paths:
1415 if project.relpath.startswith(tree):
1416 raise ManifestParseError(
1417 "project %s conflicts with submanifest path %s"
1418 % (project.relpath, tree)
1419 )
1420 self._paths[project.relpath] = project
1421 projects.append(project)
1422 for subproject in project.subprojects:
1423 recursively_add_projects(subproject)
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -07001424
Gavin Makea2e3302023-03-11 06:46:20 +00001425 repo_hooks_project = None
1426 enabled_repo_hooks = None
1427 for node in itertools.chain(*node_list):
1428 if node.nodeName == "project":
1429 project = self._ParseProject(node)
1430 recursively_add_projects(project)
1431 if node.nodeName == "extend-project":
1432 name = self._reqatt(node, "name")
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001433
Gavin Makea2e3302023-03-11 06:46:20 +00001434 if name not in self._projects:
1435 raise ManifestParseError(
1436 "extend-project element specifies non-existent "
1437 "project: %s" % name
1438 )
1439
1440 path = node.getAttribute("path")
1441 dest_path = node.getAttribute("dest-path")
1442 groups = node.getAttribute("groups")
1443 if groups:
1444 groups = self._ParseList(groups)
1445 revision = node.getAttribute("revision")
1446 remote_name = node.getAttribute("remote")
1447 if not remote_name:
1448 remote = self._default.remote
1449 else:
1450 remote = self._get_remote(node)
1451 dest_branch = node.getAttribute("dest-branch")
1452 upstream = node.getAttribute("upstream")
1453
1454 named_projects = self._projects[name]
1455 if dest_path and not path and len(named_projects) > 1:
1456 raise ManifestParseError(
1457 "extend-project cannot use dest-path when "
1458 "matching multiple projects: %s" % name
1459 )
1460 for p in self._projects[name]:
1461 if path and p.relpath != path:
1462 continue
1463 if groups:
1464 p.groups.extend(groups)
1465 if revision:
1466 p.SetRevision(revision)
1467
1468 if remote_name:
1469 p.remote = remote.ToRemoteSpec(name)
1470 if dest_branch:
1471 p.dest_branch = dest_branch
1472 if upstream:
1473 p.upstream = upstream
1474
1475 if dest_path:
1476 del self._paths[p.relpath]
1477 (
1478 relpath,
1479 worktree,
1480 gitdir,
1481 objdir,
1482 _,
1483 ) = self.GetProjectPaths(name, dest_path, remote.name)
1484 p.UpdatePaths(relpath, worktree, gitdir, objdir)
1485 self._paths[p.relpath] = p
1486
1487 if node.nodeName == "repo-hooks":
1488 # Only one project can be the hooks project
1489 if repo_hooks_project is not None:
1490 raise ManifestParseError(
1491 "duplicate repo-hooks in %s" % (self.manifestFile)
1492 )
1493
1494 # Get the name of the project and the (space-separated) list of
1495 # enabled.
1496 repo_hooks_project = self._reqatt(node, "in-project")
1497 enabled_repo_hooks = self._ParseList(
1498 self._reqatt(node, "enabled-list")
1499 )
1500 if node.nodeName == "superproject":
1501 name = self._reqatt(node, "name")
1502 # There can only be one superproject.
1503 if self._superproject:
1504 raise ManifestParseError(
1505 "duplicate superproject in %s" % (self.manifestFile)
1506 )
1507 remote_name = node.getAttribute("remote")
1508 if not remote_name:
1509 remote = self._default.remote
1510 else:
1511 remote = self._get_remote(node)
1512 if remote is None:
1513 raise ManifestParseError(
1514 "no remote for superproject %s within %s"
1515 % (name, self.manifestFile)
1516 )
1517 revision = node.getAttribute("revision") or remote.revision
1518 if not revision:
1519 revision = self._default.revisionExpr
1520 if not revision:
1521 raise ManifestParseError(
1522 "no revision for superproject %s within %s"
1523 % (name, self.manifestFile)
1524 )
1525 self._superproject = Superproject(
1526 self,
1527 name=name,
1528 remote=remote.ToRemoteSpec(name),
1529 revision=revision,
1530 )
1531 if node.nodeName == "contactinfo":
1532 bugurl = self._reqatt(node, "bugurl")
1533 # This element can be repeated, later entries will clobber
1534 # earlier ones.
1535 self._contactinfo = ContactInfo(bugurl)
1536
1537 if node.nodeName == "remove-project":
Fredrik de Grootbe71c2f2023-05-31 16:56:34 +02001538 name = node.getAttribute("name")
1539 path = node.getAttribute("path")
Gavin Makea2e3302023-03-11 06:46:20 +00001540
Fredrik de Grootbe71c2f2023-05-31 16:56:34 +02001541 # Name or path needed.
1542 if not name and not path:
1543 raise ManifestParseError(
1544 "remove-project must have name and/or path"
1545 )
Gavin Makea2e3302023-03-11 06:46:20 +00001546
Fredrik de Grootbe71c2f2023-05-31 16:56:34 +02001547 removed_project = ""
1548
1549 # Find and remove projects based on name and/or path.
1550 for projname, projects in list(self._projects.items()):
1551 for p in projects:
1552 if name == projname and not path:
1553 del self._paths[p.relpath]
1554 if not removed_project:
1555 del self._projects[name]
1556 removed_project = name
1557 elif path == p.relpath and (
1558 name == projname or not name
1559 ):
1560 self._projects[projname].remove(p)
1561 del self._paths[p.relpath]
1562 removed_project = p.name
1563
1564 # If the manifest removes the hooks project, treat it as if
1565 # it deleted the repo-hooks element too.
1566 if (
1567 removed_project
1568 and removed_project not in self._projects
1569 and repo_hooks_project == removed_project
1570 ):
1571 repo_hooks_project = None
1572
1573 if not removed_project and not XmlBool(node, "optional", False):
Gavin Makea2e3302023-03-11 06:46:20 +00001574 raise ManifestParseError(
1575 "remove-project element specifies non-existent "
Fredrik de Grootbe71c2f2023-05-31 16:56:34 +02001576 "project: %s" % node.toxml()
Gavin Makea2e3302023-03-11 06:46:20 +00001577 )
1578
1579 # Store repo hooks project information.
1580 if repo_hooks_project:
1581 # Store a reference to the Project.
1582 try:
1583 repo_hooks_projects = self._projects[repo_hooks_project]
1584 except KeyError:
1585 raise ManifestParseError(
1586 "project %s not found for repo-hooks" % (repo_hooks_project)
1587 )
1588
1589 if len(repo_hooks_projects) != 1:
1590 raise ManifestParseError(
1591 "internal error parsing repo-hooks in %s"
1592 % (self.manifestFile)
1593 )
1594 self._repo_hooks_project = repo_hooks_projects[0]
1595 # Store the enabled hooks in the Project object.
1596 self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks
1597
1598 def _AddMetaProjectMirror(self, m):
1599 name = None
1600 m_url = m.GetRemote().url
1601 if m_url.endswith("/.git"):
1602 raise ManifestParseError("refusing to mirror %s" % m_url)
1603
1604 if self._default and self._default.remote:
1605 url = self._default.remote.resolvedFetchUrl
1606 if not url.endswith("/"):
1607 url += "/"
1608 if m_url.startswith(url):
1609 remote = self._default.remote
1610 name = m_url[len(url) :]
1611
1612 if name is None:
1613 s = m_url.rindex("/") + 1
1614 manifestUrl = self.manifestProject.config.GetString(
1615 "remote.origin.url"
1616 )
1617 remote = _XmlRemote(
1618 "origin", fetch=m_url[:s], manifestUrl=manifestUrl
1619 )
1620 name = m_url[s:]
1621
1622 if name.endswith(".git"):
1623 name = name[:-4]
Josh Triplett884a3872014-06-12 14:57:29 -07001624
1625 if name not in self._projects:
Gavin Makea2e3302023-03-11 06:46:20 +00001626 m.PreSync()
1627 gitdir = os.path.join(self.topdir, "%s.git" % name)
1628 project = Project(
1629 manifest=self,
1630 name=name,
1631 remote=remote.ToRemoteSpec(name),
1632 gitdir=gitdir,
1633 objdir=gitdir,
1634 worktree=None,
1635 relpath=name or None,
1636 revisionExpr=m.revisionExpr,
1637 revisionId=None,
1638 )
1639 self._projects[project.name] = [project]
1640 self._paths[project.relpath] = project
Josh Triplett884a3872014-06-12 14:57:29 -07001641
Gavin Makea2e3302023-03-11 06:46:20 +00001642 def _ParseRemote(self, node):
1643 """
1644 reads a <remote> element from the manifest file
1645 """
1646 name = self._reqatt(node, "name")
1647 alias = node.getAttribute("alias")
1648 if alias == "":
1649 alias = None
1650 fetch = self._reqatt(node, "fetch")
1651 pushUrl = node.getAttribute("pushurl")
1652 if pushUrl == "":
1653 pushUrl = None
1654 review = node.getAttribute("review")
1655 if review == "":
1656 review = None
1657 revision = node.getAttribute("revision")
1658 if revision == "":
1659 revision = None
1660 manifestUrl = self.manifestProject.config.GetString("remote.origin.url")
1661
1662 remote = _XmlRemote(
1663 name, alias, fetch, pushUrl, manifestUrl, review, revision
1664 )
1665
1666 for n in node.childNodes:
1667 if n.nodeName == "annotation":
1668 self._ParseAnnotation(remote, n)
1669
1670 return remote
1671
1672 def _ParseDefault(self, node):
1673 """
1674 reads a <default> element from the manifest file
1675 """
1676 d = _Default()
1677 d.remote = self._get_remote(node)
1678 d.revisionExpr = node.getAttribute("revision")
1679 if d.revisionExpr == "":
1680 d.revisionExpr = None
1681
1682 d.destBranchExpr = node.getAttribute("dest-branch") or None
1683 d.upstreamExpr = node.getAttribute("upstream") or None
1684
1685 d.sync_j = XmlInt(node, "sync-j", None)
1686 if d.sync_j is not None and d.sync_j <= 0:
1687 raise ManifestParseError(
1688 '%s: sync-j must be greater than 0, not "%s"'
1689 % (self.manifestFile, d.sync_j)
1690 )
1691
1692 d.sync_c = XmlBool(node, "sync-c", False)
1693 d.sync_s = XmlBool(node, "sync-s", False)
1694 d.sync_tags = XmlBool(node, "sync-tags", True)
1695 return d
1696
1697 def _ParseNotice(self, node):
1698 """
1699 reads a <notice> element from the manifest file
1700
1701 The <notice> element is distinct from other tags in the XML in that the
1702 data is conveyed between the start and end tag (it's not an
1703 empty-element tag).
1704
1705 The white space (carriage returns, indentation) for the notice element
1706 is relevant and is parsed in a way that is based on how python
1707 docstrings work. In fact, the code is remarkably similar to here:
1708 http://www.python.org/dev/peps/pep-0257/
1709 """
1710 # Get the data out of the node...
1711 notice = node.childNodes[0].data
1712
1713 # Figure out minimum indentation, skipping the first line (the same line
1714 # as the <notice> tag)...
1715 minIndent = sys.maxsize
1716 lines = notice.splitlines()
1717 for line in lines[1:]:
1718 lstrippedLine = line.lstrip()
1719 if lstrippedLine:
1720 indent = len(line) - len(lstrippedLine)
1721 minIndent = min(indent, minIndent)
1722
1723 # Strip leading / trailing blank lines and also indentation.
1724 cleanLines = [lines[0].strip()]
1725 for line in lines[1:]:
1726 cleanLines.append(line[minIndent:].rstrip())
1727
1728 # Clear completely blank lines from front and back...
1729 while cleanLines and not cleanLines[0]:
1730 del cleanLines[0]
1731 while cleanLines and not cleanLines[-1]:
1732 del cleanLines[-1]
1733
1734 return "\n".join(cleanLines)
1735
1736 def _ParseSubmanifest(self, node):
1737 """Reads a <submanifest> element from the manifest file."""
1738 name = self._reqatt(node, "name")
1739 remote = node.getAttribute("remote")
1740 if remote == "":
1741 remote = None
1742 project = node.getAttribute("project")
1743 if project == "":
1744 project = None
1745 revision = node.getAttribute("revision")
1746 if revision == "":
1747 revision = None
1748 manifestName = node.getAttribute("manifest-name")
1749 if manifestName == "":
1750 manifestName = None
1751 groups = ""
1752 if node.hasAttribute("groups"):
1753 groups = node.getAttribute("groups")
1754 groups = self._ParseList(groups)
1755 default_groups = self._ParseList(node.getAttribute("default-groups"))
1756 path = node.getAttribute("path")
1757 if path == "":
1758 path = None
1759 if revision:
1760 msg = self._CheckLocalPath(revision.split("/")[-1])
1761 if msg:
1762 raise ManifestInvalidPathError(
1763 '<submanifest> invalid "revision": %s: %s'
1764 % (revision, msg)
1765 )
1766 else:
1767 msg = self._CheckLocalPath(name)
1768 if msg:
1769 raise ManifestInvalidPathError(
1770 '<submanifest> invalid "name": %s: %s' % (name, msg)
1771 )
LaMont Jonescc879a92021-11-18 22:40:18 +00001772 else:
Gavin Makea2e3302023-03-11 06:46:20 +00001773 msg = self._CheckLocalPath(path)
1774 if msg:
1775 raise ManifestInvalidPathError(
1776 '<submanifest> invalid "path": %s: %s' % (path, msg)
1777 )
Josh Triplett884a3872014-06-12 14:57:29 -07001778
Gavin Makea2e3302023-03-11 06:46:20 +00001779 submanifest = _XmlSubmanifest(
1780 name,
1781 remote,
1782 project,
1783 revision,
1784 manifestName,
1785 groups,
1786 default_groups,
1787 path,
1788 self,
1789 )
Michael Kelly2f3c3312020-07-21 19:40:38 -07001790
Gavin Makea2e3302023-03-11 06:46:20 +00001791 for n in node.childNodes:
1792 if n.nodeName == "annotation":
1793 self._ParseAnnotation(submanifest, n)
Michael Kelly2f3c3312020-07-21 19:40:38 -07001794
Gavin Makea2e3302023-03-11 06:46:20 +00001795 return submanifest
Michael Kelly37c21c22020-06-13 02:10:40 -07001796
Gavin Makea2e3302023-03-11 06:46:20 +00001797 def _JoinName(self, parent_name, name):
1798 return os.path.join(parent_name, name)
Doug Anderson37282b42011-03-04 11:54:18 -08001799
Gavin Makea2e3302023-03-11 06:46:20 +00001800 def _UnjoinName(self, parent_name, name):
1801 return os.path.relpath(name, parent_name)
1802
1803 def _ParseProject(self, node, parent=None, **extra_proj_attrs):
1804 """
1805 reads a <project> element from the manifest file
1806 """
1807 name = self._reqatt(node, "name")
1808 msg = self._CheckLocalPath(name, dir_ok=True)
1809 if msg:
1810 raise ManifestInvalidPathError(
1811 '<project> invalid "name": %s: %s' % (name, msg)
1812 )
1813 if parent:
1814 name = self._JoinName(parent.name, name)
1815
1816 remote = self._get_remote(node)
Raman Tenneti1bb4fb22021-01-07 16:50:45 -08001817 if remote is None:
Gavin Makea2e3302023-03-11 06:46:20 +00001818 remote = self._default.remote
1819 if remote is None:
1820 raise ManifestParseError(
1821 "no remote for project %s within %s" % (name, self.manifestFile)
1822 )
Raman Tenneti993af5e2021-05-12 12:00:31 -07001823
Gavin Makea2e3302023-03-11 06:46:20 +00001824 revisionExpr = node.getAttribute("revision") or remote.revision
1825 if not revisionExpr:
1826 revisionExpr = self._default.revisionExpr
1827 if not revisionExpr:
1828 raise ManifestParseError(
1829 "no revision for project %s within %s"
1830 % (name, self.manifestFile)
1831 )
David Jamesb8433df2014-01-30 10:11:17 -08001832
Gavin Makea2e3302023-03-11 06:46:20 +00001833 path = node.getAttribute("path")
1834 if not path:
1835 path = name
Julien Camperguedd654222014-01-09 16:21:37 +01001836 else:
Gavin Makea2e3302023-03-11 06:46:20 +00001837 # NB: The "." project is handled specially in
1838 # Project.Sync_LocalHalf.
1839 msg = self._CheckLocalPath(path, dir_ok=True, cwd_dot_ok=True)
1840 if msg:
1841 raise ManifestInvalidPathError(
1842 '<project> invalid "path": %s: %s' % (path, msg)
1843 )
Julien Camperguedd654222014-01-09 16:21:37 +01001844
Gavin Makea2e3302023-03-11 06:46:20 +00001845 rebase = XmlBool(node, "rebase", True)
1846 sync_c = XmlBool(node, "sync-c", False)
1847 sync_s = XmlBool(node, "sync-s", self._default.sync_s)
1848 sync_tags = XmlBool(node, "sync-tags", self._default.sync_tags)
Julien Camperguedd654222014-01-09 16:21:37 +01001849
Gavin Makea2e3302023-03-11 06:46:20 +00001850 clone_depth = XmlInt(node, "clone-depth")
1851 if clone_depth is not None and clone_depth <= 0:
1852 raise ManifestParseError(
1853 '%s: clone-depth must be greater than 0, not "%s"'
1854 % (self.manifestFile, clone_depth)
1855 )
1856
1857 dest_branch = (
1858 node.getAttribute("dest-branch") or self._default.destBranchExpr
1859 )
1860
1861 upstream = node.getAttribute("upstream") or self._default.upstreamExpr
1862
1863 groups = ""
1864 if node.hasAttribute("groups"):
1865 groups = node.getAttribute("groups")
1866 groups = self._ParseList(groups)
1867
1868 if parent is None:
1869 (
1870 relpath,
1871 worktree,
1872 gitdir,
1873 objdir,
1874 use_git_worktrees,
1875 ) = self.GetProjectPaths(name, path, remote.name)
1876 else:
1877 use_git_worktrees = False
1878 relpath, worktree, gitdir, objdir = self.GetSubprojectPaths(
1879 parent, name, path
1880 )
1881
1882 default_groups = ["all", "name:%s" % name, "path:%s" % relpath]
1883 groups.extend(set(default_groups).difference(groups))
1884
1885 if self.IsMirror and node.hasAttribute("force-path"):
1886 if XmlBool(node, "force-path", False):
1887 gitdir = os.path.join(self.topdir, "%s.git" % path)
1888
1889 project = Project(
1890 manifest=self,
1891 name=name,
1892 remote=remote.ToRemoteSpec(name),
1893 gitdir=gitdir,
1894 objdir=objdir,
1895 worktree=worktree,
1896 relpath=relpath,
1897 revisionExpr=revisionExpr,
1898 revisionId=None,
1899 rebase=rebase,
1900 groups=groups,
1901 sync_c=sync_c,
1902 sync_s=sync_s,
1903 sync_tags=sync_tags,
1904 clone_depth=clone_depth,
1905 upstream=upstream,
1906 parent=parent,
1907 dest_branch=dest_branch,
1908 use_git_worktrees=use_git_worktrees,
1909 **extra_proj_attrs,
1910 )
1911
1912 for n in node.childNodes:
1913 if n.nodeName == "copyfile":
1914 self._ParseCopyFile(project, n)
1915 if n.nodeName == "linkfile":
1916 self._ParseLinkFile(project, n)
1917 if n.nodeName == "annotation":
1918 self._ParseAnnotation(project, n)
1919 if n.nodeName == "project":
1920 project.subprojects.append(
1921 self._ParseProject(n, parent=project)
1922 )
1923
1924 return project
1925
1926 def GetProjectPaths(self, name, path, remote):
1927 """Return the paths for a project.
1928
1929 Args:
1930 name: a string, the name of the project.
1931 path: a string, the path of the project.
1932 remote: a string, the remote.name of the project.
1933
1934 Returns:
1935 A tuple of (relpath, worktree, gitdir, objdir, use_git_worktrees)
1936 for the project with |name| and |path|.
1937 """
1938 # The manifest entries might have trailing slashes. Normalize them to
1939 # avoid unexpected filesystem behavior since we do string concatenation
1940 # below.
1941 path = path.rstrip("/")
1942 name = name.rstrip("/")
1943 remote = remote.rstrip("/")
1944 use_git_worktrees = False
1945 use_remote_name = self.is_multimanifest
1946 relpath = path
1947 if self.IsMirror:
1948 worktree = None
1949 gitdir = os.path.join(self.topdir, "%s.git" % name)
1950 objdir = gitdir
1951 else:
1952 if use_remote_name:
1953 namepath = os.path.join(remote, f"{name}.git")
1954 else:
1955 namepath = f"{name}.git"
1956 worktree = os.path.join(self.topdir, path).replace("\\", "/")
1957 gitdir = os.path.join(self.subdir, "projects", "%s.git" % path)
1958 # We allow people to mix git worktrees & non-git worktrees for now.
1959 # This allows for in situ migration of repo clients.
1960 if os.path.exists(gitdir) or not self.UseGitWorktrees:
1961 objdir = os.path.join(self.repodir, "project-objects", namepath)
1962 else:
1963 use_git_worktrees = True
1964 gitdir = os.path.join(self.repodir, "worktrees", namepath)
1965 objdir = gitdir
1966 return relpath, worktree, gitdir, objdir, use_git_worktrees
1967
1968 def GetProjectsWithName(self, name, all_manifests=False):
1969 """All projects with |name|.
1970
1971 Args:
1972 name: a string, the name of the project.
1973 all_manifests: a boolean, if True, then all manifests are searched.
1974 If False, then only this manifest is searched.
1975
1976 Returns:
1977 A list of Project instances with name |name|.
1978 """
1979 if all_manifests:
1980 return list(
1981 itertools.chain.from_iterable(
1982 x._projects.get(name, []) for x in self.all_manifests
1983 )
1984 )
1985 return self._projects.get(name, [])
1986
1987 def GetSubprojectName(self, parent, submodule_path):
1988 return os.path.join(parent.name, submodule_path)
1989
1990 def _JoinRelpath(self, parent_relpath, relpath):
1991 return os.path.join(parent_relpath, relpath)
1992
1993 def _UnjoinRelpath(self, parent_relpath, relpath):
1994 return os.path.relpath(relpath, parent_relpath)
1995
1996 def GetSubprojectPaths(self, parent, name, path):
1997 # The manifest entries might have trailing slashes. Normalize them to
1998 # avoid unexpected filesystem behavior since we do string concatenation
1999 # below.
2000 path = path.rstrip("/")
2001 name = name.rstrip("/")
2002 relpath = self._JoinRelpath(parent.relpath, path)
2003 gitdir = os.path.join(parent.gitdir, "subprojects", "%s.git" % path)
2004 objdir = os.path.join(
2005 parent.gitdir, "subproject-objects", "%s.git" % name
2006 )
2007 if self.IsMirror:
2008 worktree = None
2009 else:
2010 worktree = os.path.join(parent.worktree, path).replace("\\", "/")
2011 return relpath, worktree, gitdir, objdir
2012
2013 @staticmethod
2014 def _CheckLocalPath(path, dir_ok=False, cwd_dot_ok=False):
2015 """Verify |path| is reasonable for use in filesystem paths.
2016
2017 Used with <copyfile> & <linkfile> & <project> elements.
2018
2019 This only validates the |path| in isolation: it does not check against
2020 the current filesystem state. Thus it is suitable as a first-past in a
2021 parser.
2022
2023 It enforces a number of constraints:
2024 * No empty paths.
2025 * No "~" in paths.
2026 * No Unicode codepoints that filesystems might elide when normalizing.
2027 * No relative path components like "." or "..".
2028 * No absolute paths.
2029 * No ".git" or ".repo*" path components.
2030
2031 Args:
2032 path: The path name to validate.
2033 dir_ok: Whether |path| may force a directory (e.g. end in a /).
2034 cwd_dot_ok: Whether |path| may be just ".".
2035
2036 Returns:
2037 None if |path| is OK, a failure message otherwise.
2038 """
2039 if not path:
2040 return "empty paths not allowed"
2041
2042 if "~" in path:
2043 return "~ not allowed (due to 8.3 filenames on Windows filesystems)"
2044
2045 path_codepoints = set(path)
2046
2047 # Some filesystems (like Apple's HFS+) try to normalize Unicode
2048 # codepoints which means there are alternative names for ".git". Reject
2049 # paths with these in it as there shouldn't be any reasonable need for
2050 # them here. The set of codepoints here was cribbed from jgit's
2051 # implementation:
2052 # https://eclipse.googlesource.com/jgit/jgit/+/9110037e3e9461ff4dac22fee84ef3694ed57648/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java#884
2053 BAD_CODEPOINTS = {
2054 "\u200C", # ZERO WIDTH NON-JOINER
2055 "\u200D", # ZERO WIDTH JOINER
2056 "\u200E", # LEFT-TO-RIGHT MARK
2057 "\u200F", # RIGHT-TO-LEFT MARK
2058 "\u202A", # LEFT-TO-RIGHT EMBEDDING
2059 "\u202B", # RIGHT-TO-LEFT EMBEDDING
2060 "\u202C", # POP DIRECTIONAL FORMATTING
2061 "\u202D", # LEFT-TO-RIGHT OVERRIDE
2062 "\u202E", # RIGHT-TO-LEFT OVERRIDE
2063 "\u206A", # INHIBIT SYMMETRIC SWAPPING
2064 "\u206B", # ACTIVATE SYMMETRIC SWAPPING
2065 "\u206C", # INHIBIT ARABIC FORM SHAPING
2066 "\u206D", # ACTIVATE ARABIC FORM SHAPING
2067 "\u206E", # NATIONAL DIGIT SHAPES
2068 "\u206F", # NOMINAL DIGIT SHAPES
2069 "\uFEFF", # ZERO WIDTH NO-BREAK SPACE
2070 }
2071 if BAD_CODEPOINTS & path_codepoints:
2072 # This message is more expansive than reality, but should be fine.
2073 return "Unicode combining characters not allowed"
2074
2075 # Reject newlines as there shouldn't be any legitmate use for them,
2076 # they'll be confusing to users, and they can easily break tools that
2077 # expect to be able to iterate over newline delimited lists. This even
2078 # applies to our own code like .repo/project.list.
2079 if {"\r", "\n"} & path_codepoints:
2080 return "Newlines not allowed"
2081
2082 # Assume paths might be used on case-insensitive filesystems.
2083 path = path.lower()
2084
2085 # Split up the path by its components. We can't use os.path.sep
2086 # exclusively as some platforms (like Windows) will convert / to \ and
2087 # that bypasses all our constructed logic here. Especially since
2088 # manifest authors only use / in their paths.
2089 resep = re.compile(r"[/%s]" % re.escape(os.path.sep))
2090 # Strip off trailing slashes as those only produce '' elements, and we
2091 # use parts to look for individual bad components.
2092 parts = resep.split(path.rstrip("/"))
2093
2094 # Some people use src="." to create stable links to projects. Lets
2095 # allow that but reject all other uses of "." to keep things simple.
2096 if not cwd_dot_ok or parts != ["."]:
2097 for part in set(parts):
2098 if part in {".", "..", ".git"} or part.startswith(".repo"):
2099 return "bad component: %s" % (part,)
2100
2101 if not dir_ok and resep.match(path[-1]):
2102 return "dirs not allowed"
2103
2104 # NB: The two abspath checks here are to handle platforms with multiple
2105 # filesystem path styles (e.g. Windows).
2106 norm = os.path.normpath(path)
2107 if (
2108 norm == ".."
2109 or (
2110 len(norm) >= 3
2111 and norm.startswith("..")
2112 and resep.match(norm[0])
2113 )
2114 or os.path.isabs(norm)
2115 or norm.startswith("/")
2116 ):
2117 return "path cannot be outside"
2118
2119 @classmethod
2120 def _ValidateFilePaths(cls, element, src, dest):
2121 """Verify |src| & |dest| are reasonable for <copyfile> & <linkfile>.
2122
2123 We verify the path independent of any filesystem state as we won't have
2124 a checkout available to compare to. i.e. This is for parsing validation
2125 purposes only.
2126
2127 We'll do full/live sanity checking before we do the actual filesystem
2128 modifications in _CopyFile/_LinkFile/etc...
2129 """
2130 # |dest| is the file we write to or symlink we create.
2131 # It is relative to the top of the repo client checkout.
2132 msg = cls._CheckLocalPath(dest)
2133 if msg:
2134 raise ManifestInvalidPathError(
2135 '<%s> invalid "dest": %s: %s' % (element, dest, msg)
2136 )
2137
2138 # |src| is the file we read from or path we point to for symlinks.
2139 # It is relative to the top of the git project checkout.
2140 is_linkfile = element == "linkfile"
2141 msg = cls._CheckLocalPath(
2142 src, dir_ok=is_linkfile, cwd_dot_ok=is_linkfile
2143 )
2144 if msg:
2145 raise ManifestInvalidPathError(
2146 '<%s> invalid "src": %s: %s' % (element, src, msg)
2147 )
2148
2149 def _ParseCopyFile(self, project, node):
2150 src = self._reqatt(node, "src")
2151 dest = self._reqatt(node, "dest")
2152 if not self.IsMirror:
2153 # src is project relative;
2154 # dest is relative to the top of the tree.
2155 # We only validate paths if we actually plan to process them.
2156 self._ValidateFilePaths("copyfile", src, dest)
2157 project.AddCopyFile(src, dest, self.topdir)
2158
2159 def _ParseLinkFile(self, project, node):
2160 src = self._reqatt(node, "src")
2161 dest = self._reqatt(node, "dest")
2162 if not self.IsMirror:
2163 # src is project relative;
2164 # dest is relative to the top of the tree.
2165 # We only validate paths if we actually plan to process them.
2166 self._ValidateFilePaths("linkfile", src, dest)
2167 project.AddLinkFile(src, dest, self.topdir)
2168
2169 def _ParseAnnotation(self, element, node):
2170 name = self._reqatt(node, "name")
2171 value = self._reqatt(node, "value")
2172 try:
2173 keep = self._reqatt(node, "keep").lower()
2174 except ManifestParseError:
2175 keep = "true"
2176 if keep != "true" and keep != "false":
2177 raise ManifestParseError(
2178 'optional "keep" attribute must be ' '"true" or "false"'
2179 )
2180 element.AddAnnotation(name, value, keep)
2181
2182 def _get_remote(self, node):
2183 name = node.getAttribute("remote")
2184 if not name:
2185 return None
2186
2187 v = self._remotes.get(name)
2188 if not v:
2189 raise ManifestParseError(
2190 "remote %s not defined in %s" % (name, self.manifestFile)
2191 )
2192 return v
2193
2194 def _reqatt(self, node, attname):
2195 """
2196 reads a required attribute from the node.
2197 """
2198 v = node.getAttribute(attname)
2199 if not v:
2200 raise ManifestParseError(
2201 "no %s in <%s> within %s"
2202 % (attname, node.nodeName, self.manifestFile)
2203 )
2204 return v
2205
2206 def projectsDiff(self, manifest):
2207 """return the projects differences between two manifests.
2208
2209 The diff will be from self to given manifest.
2210
2211 """
2212 fromProjects = self.paths
2213 toProjects = manifest.paths
2214
2215 fromKeys = sorted(fromProjects.keys())
2216 toKeys = sorted(toProjects.keys())
2217
2218 diff = {
2219 "added": [],
2220 "removed": [],
2221 "missing": [],
2222 "changed": [],
2223 "unreachable": [],
2224 }
2225
2226 for proj in fromKeys:
2227 if proj not in toKeys:
2228 diff["removed"].append(fromProjects[proj])
2229 elif not fromProjects[proj].Exists:
2230 diff["missing"].append(toProjects[proj])
2231 toKeys.remove(proj)
2232 else:
2233 fromProj = fromProjects[proj]
2234 toProj = toProjects[proj]
2235 try:
2236 fromRevId = fromProj.GetCommitRevisionId()
2237 toRevId = toProj.GetCommitRevisionId()
2238 except ManifestInvalidRevisionError:
2239 diff["unreachable"].append((fromProj, toProj))
2240 else:
2241 if fromRevId != toRevId:
2242 diff["changed"].append((fromProj, toProj))
2243 toKeys.remove(proj)
2244
2245 for proj in toKeys:
2246 diff["added"].append(toProjects[proj])
2247
2248 return diff
Simran Basib9a1b732015-08-20 12:19:28 -07002249
2250
2251class GitcManifest(XmlManifest):
Gavin Makea2e3302023-03-11 06:46:20 +00002252 """Parser for GitC (git-in-the-cloud) manifests."""
Simran Basib9a1b732015-08-20 12:19:28 -07002253
Gavin Makea2e3302023-03-11 06:46:20 +00002254 def _ParseProject(self, node, parent=None):
2255 """Override _ParseProject and add support for GITC specific attributes.""" # noqa: E501
2256 return super()._ParseProject(
2257 node, parent=parent, old_revision=node.getAttribute("old-revision")
2258 )
Simran Basib9a1b732015-08-20 12:19:28 -07002259
Gavin Makea2e3302023-03-11 06:46:20 +00002260 def _output_manifest_project_extras(self, p, e):
2261 """Output GITC Specific Project attributes"""
2262 if p.old_revision:
2263 e.setAttribute("old-revision", str(p.old_revision))
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002264
2265
2266class RepoClient(XmlManifest):
Gavin Makea2e3302023-03-11 06:46:20 +00002267 """Manages a repo client checkout."""
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002268
Gavin Makea2e3302023-03-11 06:46:20 +00002269 def __init__(
2270 self, repodir, manifest_file=None, submanifest_path="", **kwargs
2271 ):
2272 """Initialize.
LaMont Jonesff6b1da2022-06-01 21:03:34 +00002273
Gavin Makea2e3302023-03-11 06:46:20 +00002274 Args:
2275 repodir: Path to the .repo/ dir for holding all internal checkout
2276 state. It must be in the top directory of the repo client
2277 checkout.
2278 manifest_file: Full path to the manifest file to parse. This will
2279 usually be |repodir|/|MANIFEST_FILE_NAME|.
2280 submanifest_path: The submanifest root relative to the repo root.
2281 **kwargs: Additional keyword arguments, passed to XmlManifest.
2282 """
2283 self.isGitcClient = False
2284 submanifest_path = submanifest_path or ""
2285 if submanifest_path:
2286 self._CheckLocalPath(submanifest_path)
2287 prefix = os.path.join(repodir, SUBMANIFEST_DIR, submanifest_path)
2288 else:
2289 prefix = repodir
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002290
Gavin Makea2e3302023-03-11 06:46:20 +00002291 if os.path.exists(os.path.join(prefix, LOCAL_MANIFEST_NAME)):
2292 print(
2293 "error: %s is not supported; put local manifests in `%s` "
2294 "instead"
2295 % (
2296 LOCAL_MANIFEST_NAME,
2297 os.path.join(prefix, LOCAL_MANIFESTS_DIR_NAME),
2298 ),
2299 file=sys.stderr,
2300 )
2301 sys.exit(1)
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002302
Gavin Makea2e3302023-03-11 06:46:20 +00002303 if manifest_file is None:
2304 manifest_file = os.path.join(prefix, MANIFEST_FILE_NAME)
2305 local_manifests = os.path.abspath(
2306 os.path.join(prefix, LOCAL_MANIFESTS_DIR_NAME)
2307 )
2308 super().__init__(
2309 repodir,
2310 manifest_file,
2311 local_manifests,
2312 submanifest_path=submanifest_path,
2313 **kwargs,
2314 )
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002315
Gavin Makea2e3302023-03-11 06:46:20 +00002316 # TODO: Completely separate manifest logic out of the client.
2317 self.manifest = self
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002318
2319
2320class GitcClient(RepoClient, GitcManifest):
Gavin Makea2e3302023-03-11 06:46:20 +00002321 """Manages a GitC client checkout."""
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002322
Gavin Makea2e3302023-03-11 06:46:20 +00002323 def __init__(self, repodir, gitc_client_name):
2324 """Initialize the GitcManifest object."""
2325 self.gitc_client_name = gitc_client_name
2326 self.gitc_client_dir = os.path.join(
2327 gitc_utils.get_gitc_manifest_dir(), gitc_client_name
2328 )
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04002329
Gavin Makea2e3302023-03-11 06:46:20 +00002330 super().__init__(
2331 repodir, os.path.join(self.gitc_client_dir, ".manifest")
2332 )
2333 self.isGitcClient = True