blob: bbecb934d649e213a7ce40d24a2bec116c6fe29b [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
Colin Cross23acdd32012-04-21 00:33:54 -070015import itertools
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070016import os
Conley Owensdb728cd2011-09-26 16:34:01 -070017import re
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070018import sys
David Pursehouse59bbb582013-05-17 10:49:33 +090019import xml.dom.minidom
20
21from pyversion import is_python3
22if is_python3():
Chirayu Desai217ea7d2013-03-01 19:14:38 +053023 import urllib.parse
David Pursehouse59bbb582013-05-17 10:49:33 +090024else:
Chirayu Desai217ea7d2013-03-01 19:14:38 +053025 import imp
26 import urlparse
27 urllib = imp.new_module('urllib')
Chirayu Desaidb2ad9d2013-06-11 13:42:25 +053028 urllib.parse = urlparse
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070029
Simran Basib9a1b732015-08-20 12:19:28 -070030import gitc_utils
Miguel Gaio1f207762020-07-17 14:09:13 +020031from git_config import GitConfig, IsId
David Pursehousee00aa6b2012-09-11 14:33:51 +090032from git_refs import R_HEADS, HEAD
Renaud Paquayd5cec5e2016-11-01 11:24:03 -070033import platform_utils
David Pursehousee00aa6b2012-09-11 14:33:51 +090034from project import RemoteSpec, Project, MetaProject
Mike Frysinger04122b72019-07-31 23:32:58 -040035from error import (ManifestParseError, ManifestInvalidPathError,
36 ManifestInvalidRevisionError)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070037
38MANIFEST_FILE_NAME = 'manifest.xml'
Shawn O. Pearce5cc66792008-10-23 16:19:27 -070039LOCAL_MANIFEST_NAME = 'local_manifest.xml'
David Pursehouse2d5a0df2012-11-13 02:50:36 +090040LOCAL_MANIFESTS_DIR_NAME = 'local_manifests'
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070041
Anthony Kingcb07ba72015-03-28 23:26:04 +000042# urljoin gets confused if the scheme is not known.
Joe Kilner6e310792016-10-27 15:53:53 -070043urllib.parse.uses_relative.extend([
44 'ssh',
45 'git',
46 'persistent-https',
47 'sso',
48 'rpc'])
49urllib.parse.uses_netloc.extend([
50 'ssh',
51 'git',
52 'persistent-https',
53 'sso',
54 'rpc'])
Conley Owensdb728cd2011-09-26 16:34:01 -070055
David Pursehouse819827a2020-02-12 15:20:19 +090056
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050057def XmlBool(node, attr, default=None):
58 """Determine boolean value of |node|'s |attr|.
59
60 Invalid values will issue a non-fatal warning.
61
62 Args:
63 node: XML node whose attributes we access.
64 attr: The attribute to access.
65 default: If the attribute is not set (value is empty), then use this.
66
67 Returns:
68 True if the attribute is a valid string representing true.
69 False if the attribute is a valid string representing false.
70 |default| otherwise.
71 """
72 value = node.getAttribute(attr)
73 s = value.lower()
74 if s == '':
75 return default
76 elif s in {'yes', 'true', '1'}:
77 return True
78 elif s in {'no', 'false', '0'}:
79 return False
80 else:
81 print('warning: manifest: %s="%s": ignoring invalid XML boolean' %
82 (attr, value), file=sys.stderr)
83 return default
84
85
86def XmlInt(node, attr, default=None):
87 """Determine integer value of |node|'s |attr|.
88
89 Args:
90 node: XML node whose attributes we access.
91 attr: The attribute to access.
92 default: If the attribute is not set (value is empty), then use this.
93
94 Returns:
95 The number if the attribute is a valid number.
96
97 Raises:
98 ManifestParseError: The number is invalid.
99 """
100 value = node.getAttribute(attr)
101 if not value:
102 return default
103
104 try:
105 return int(value)
106 except ValueError:
107 raise ManifestParseError('manifest: invalid %s="%s" integer' %
108 (attr, value))
109
110
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700111class _Default(object):
112 """Project defaults within the manifest."""
113
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700114 revisionExpr = None
Conley Owensb6a16e62013-09-25 15:06:09 -0700115 destBranchExpr = None
Nasser Grainawida403412018-05-04 12:53:29 -0600116 upstreamExpr = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700117 remote = None
Shawn O. Pearce6392c872011-09-22 17:44:31 -0700118 sync_j = 1
Anatol Pomazau79770d22012-04-20 14:41:59 -0700119 sync_c = False
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800120 sync_s = False
YOUNG HO CHAa32c92c2018-02-14 16:57:31 +0900121 sync_tags = True
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700122
Julien Campergue74879922013-10-09 14:38:46 +0200123 def __eq__(self, other):
124 return self.__dict__ == other.__dict__
125
126 def __ne__(self, other):
127 return self.__dict__ != other.__dict__
128
David Pursehouse819827a2020-02-12 15:20:19 +0900129
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700130class _XmlRemote(object):
131 def __init__(self,
132 name,
Yestin Sunb292b982012-07-02 07:32:50 -0700133 alias=None,
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700134 fetch=None,
Steve Raed6480452016-08-10 15:00:00 -0700135 pushUrl=None,
Conley Owensdb728cd2011-09-26 16:34:01 -0700136 manifestUrl=None,
Anthony King36ea2fb2014-05-06 11:54:01 +0100137 review=None,
Jonathan Nieder93719792015-03-17 11:29:58 -0700138 revision=None):
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700139 self.name = name
140 self.fetchUrl = fetch
Steve Raed6480452016-08-10 15:00:00 -0700141 self.pushUrl = pushUrl
Conley Owensdb728cd2011-09-26 16:34:01 -0700142 self.manifestUrl = manifestUrl
Yestin Sunb292b982012-07-02 07:32:50 -0700143 self.remoteAlias = alias
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700144 self.reviewUrl = review
Anthony King36ea2fb2014-05-06 11:54:01 +0100145 self.revision = revision
Conley Owensceea3682011-10-20 10:45:47 -0700146 self.resolvedFetchUrl = self._resolveFetchUrl()
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700147
David Pursehouse717ece92012-11-13 08:49:16 +0900148 def __eq__(self, other):
149 return self.__dict__ == other.__dict__
150
151 def __ne__(self, other):
152 return self.__dict__ != other.__dict__
153
Conley Owensceea3682011-10-20 10:45:47 -0700154 def _resolveFetchUrl(self):
155 url = self.fetchUrl.rstrip('/')
Conley Owensdb728cd2011-09-26 16:34:01 -0700156 manifestUrl = self.manifestUrl.rstrip('/')
Conley Owens2d0f5082014-01-31 15:03:51 -0800157 # urljoin will gets confused over quite a few things. The ones we care
158 # about here are:
159 # * no scheme in the base url, like <hostname:port>
Anthony Kingcb07ba72015-03-28 23:26:04 +0000160 # We handle no scheme by replacing it with an obscure protocol, gopher
161 # and then replacing it with the original when we are done.
162
Conley Owensdb728cd2011-09-26 16:34:01 -0700163 if manifestUrl.find(':') != manifestUrl.find('/') - 1:
Conley Owens4ccad752015-04-29 10:45:37 -0700164 url = urllib.parse.urljoin('gopher://' + manifestUrl, url)
165 url = re.sub(r'^gopher://', '', url)
Anthony Kingcb07ba72015-03-28 23:26:04 +0000166 else:
167 url = urllib.parse.urljoin(manifestUrl, url)
Shawn Pearcea9f11b32013-01-02 15:40:48 -0800168 return url
Conley Owensceea3682011-10-20 10:45:47 -0700169
170 def ToRemoteSpec(self, projectName):
David Rileye0684ad2017-04-05 00:02:59 -0700171 fetchUrl = self.resolvedFetchUrl.rstrip('/')
172 url = fetchUrl + '/' + projectName
Yestin Sunb292b982012-07-02 07:32:50 -0700173 remoteName = self.name
Conley Owens1e7ab2a2013-10-08 17:26:57 -0700174 if self.remoteAlias:
David Pursehouse37128b62013-10-15 10:48:40 +0900175 remoteName = self.remoteAlias
Dan Willemsen96c2d652016-04-06 16:03:54 -0700176 return RemoteSpec(remoteName,
177 url=url,
Steve Raed6480452016-08-10 15:00:00 -0700178 pushUrl=self.pushUrl,
Dan Willemsen96c2d652016-04-06 16:03:54 -0700179 review=self.reviewUrl,
David Rileye0684ad2017-04-05 00:02:59 -0700180 orig_name=self.name,
181 fetchUrl=self.fetchUrl)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700182
David Pursehouse819827a2020-02-12 15:20:19 +0900183
Shawn O. Pearcec8a300f2009-05-18 13:19:57 -0700184class XmlManifest(object):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700185 """manages the repo configuration file"""
186
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400187 def __init__(self, repodir, manifest_file, local_manifests=None):
188 """Initialize.
189
190 Args:
191 repodir: Path to the .repo/ dir for holding all internal checkout state.
192 It must be in the top directory of the repo client checkout.
193 manifest_file: Full path to the manifest file to parse. This will usually
194 be |repodir|/|MANIFEST_FILE_NAME|.
195 local_manifests: Full path to the directory of local override manifests.
196 This will usually be |repodir|/|LOCAL_MANIFESTS_DIR_NAME|.
197 """
198 # TODO(vapier): Move this out of this class.
199 self.globalConfig = GitConfig.ForUser()
200
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700201 self.repodir = os.path.abspath(repodir)
202 self.topdir = os.path.dirname(self.repodir)
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400203 self.manifestFile = manifest_file
204 self.local_manifests = local_manifests
Basil Gelloc7453502018-05-25 20:23:52 +0300205 self._load_local_manifests = True
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700206
207 self.repoProject = MetaProject(self, 'repo',
David Pursehouseabdf7502020-02-12 14:58:39 +0900208 gitdir=os.path.join(repodir, 'repo/.git'),
209 worktree=os.path.join(repodir, 'repo'))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700210
Mike Frysinger979d5bd2020-02-09 02:28:34 -0500211 mp = MetaProject(self, 'manifests',
212 gitdir=os.path.join(repodir, 'manifests.git'),
213 worktree=os.path.join(repodir, 'manifests'))
214 self.manifestProject = mp
215
216 # This is a bit hacky, but we're in a chicken & egg situation: all the
217 # normal repo settings live in the manifestProject which we just setup
218 # above, so we couldn't easily query before that. We assume Project()
219 # init doesn't care if this changes afterwards.
Mike Frysingerd957ec62020-02-24 14:40:25 -0500220 if os.path.exists(mp.gitdir) and mp.config.GetBoolean('repo.worktree'):
Mike Frysinger979d5bd2020-02-09 02:28:34 -0500221 mp.use_git_worktrees = True
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700222
223 self._Unload()
224
Basil Gelloc7453502018-05-25 20:23:52 +0300225 def Override(self, name, load_local_manifests=True):
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700226 """Use a different manifest, just for the current instantiation.
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700227 """
Basil Gelloc7453502018-05-25 20:23:52 +0300228 path = None
229
230 # Look for a manifest by path in the filesystem (including the cwd).
231 if not load_local_manifests:
232 local_path = os.path.abspath(name)
233 if os.path.isfile(local_path):
234 path = local_path
235
236 # Look for manifests by name from the manifests repo.
237 if path is None:
238 path = os.path.join(self.manifestProject.worktree, name)
239 if not os.path.isfile(path):
240 raise ManifestParseError('manifest %s not found' % name)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700241
242 old = self.manifestFile
243 try:
Basil Gelloc7453502018-05-25 20:23:52 +0300244 self._load_local_manifests = load_local_manifests
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700245 self.manifestFile = path
246 self._Unload()
247 self._Load()
248 finally:
249 self.manifestFile = old
250
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700251 def Link(self, name):
252 """Update the repo metadata to use a different manifest.
253 """
254 self.Override(name)
255
Mike Frysingera269b1c2020-02-21 00:49:41 -0500256 # Old versions of repo would generate symlinks we need to clean up.
257 if os.path.lexists(self.manifestFile):
258 platform_utils.remove(self.manifestFile)
259 # This file is interpreted as if it existed inside the manifest repo.
260 # That allows us to use <include> with the relative file name.
261 with open(self.manifestFile, 'w') as fp:
262 fp.write("""<?xml version="1.0" encoding="UTF-8"?>
263<!--
264DO NOT EDIT THIS FILE! It is generated by repo and changes will be discarded.
265If you want to use a different manifest, use `repo init -m <file>` instead.
266
267If you want to customize your checkout by overriding manifest settings, use
268the local_manifests/ directory instead.
269
270For more information on repo manifests, check out:
271https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
272-->
273<manifest>
274 <include name="%s" />
275</manifest>
276""" % (name,))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700277
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800278 def _RemoteToXml(self, r, doc, root):
279 e = doc.createElement('remote')
280 root.appendChild(e)
281 e.setAttribute('name', r.name)
282 e.setAttribute('fetch', r.fetchUrl)
Steve Raed6480452016-08-10 15:00:00 -0700283 if r.pushUrl is not None:
284 e.setAttribute('pushurl', r.pushUrl)
Conley Owens1e7ab2a2013-10-08 17:26:57 -0700285 if r.remoteAlias is not None:
286 e.setAttribute('alias', r.remoteAlias)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800287 if r.reviewUrl is not None:
288 e.setAttribute('review', r.reviewUrl)
Anthony King36ea2fb2014-05-06 11:54:01 +0100289 if r.revision is not None:
290 e.setAttribute('revision', r.revision)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800291
Mike Frysinger51e39d52020-12-04 05:32:06 -0500292 def _ParseList(self, field):
293 """Parse fields that contain flattened lists.
294
295 These are whitespace & comma separated. Empty elements will be discarded.
296 """
297 return [x for x in re.split(r'[,\s]+', field) if x]
Josh Triplett884a3872014-06-12 14:57:29 -0700298
Mike Frysinger23411d32020-09-02 04:31:10 -0400299 def ToXml(self, peg_rev=False, peg_rev_upstream=True, peg_rev_dest_branch=True, groups=None):
300 """Return the current manifest XML."""
Colin Cross5acde752012-03-28 20:15:45 -0700301 mp = self.manifestProject
302
Dan Willemsen5ea32d12015-09-08 13:27:20 -0700303 if groups is None:
304 groups = mp.config.GetString('manifest.groups')
Matt Gumbel0c635bb2012-12-21 10:14:53 -0800305 if groups:
Mike Frysinger51e39d52020-12-04 05:32:06 -0500306 groups = self._ParseList(groups)
Colin Cross5acde752012-03-28 20:15:45 -0700307
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800308 doc = xml.dom.minidom.Document()
309 root = doc.createElement('manifest')
310 doc.appendChild(root)
311
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700312 # Save out the notice. There's a little bit of work here to give it the
313 # right whitespace, which assumes that the notice is automatically indented
314 # by 4 by minidom.
315 if self.notice:
316 notice_element = root.appendChild(doc.createElement('notice'))
317 notice_lines = self.notice.splitlines()
David Pursehouse54a4e602020-02-12 14:31:05 +0900318 indented_notice = ('\n'.join(" " * 4 + line for line in notice_lines))[4:]
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700319 notice_element.appendChild(doc.createTextNode(indented_notice))
320
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800321 d = self.default
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800322
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530323 for r in sorted(self.remotes):
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800324 self._RemoteToXml(self.remotes[r], doc, root)
325 if self.remotes:
326 root.appendChild(doc.createTextNode(''))
327
328 have_default = False
329 e = doc.createElement('default')
330 if d.remote:
331 have_default = True
332 e.setAttribute('remote', d.remote.name)
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700333 if d.revisionExpr:
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800334 have_default = True
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700335 e.setAttribute('revision', d.revisionExpr)
Simon Ruggier7e59de22015-07-24 12:50:06 +0200336 if d.destBranchExpr:
337 have_default = True
338 e.setAttribute('dest-branch', d.destBranchExpr)
Nasser Grainawida403412018-05-04 12:53:29 -0600339 if d.upstreamExpr:
340 have_default = True
341 e.setAttribute('upstream', d.upstreamExpr)
Shawn O. Pearce6392c872011-09-22 17:44:31 -0700342 if d.sync_j > 1:
343 have_default = True
344 e.setAttribute('sync-j', '%d' % d.sync_j)
Anatol Pomazau79770d22012-04-20 14:41:59 -0700345 if d.sync_c:
346 have_default = True
347 e.setAttribute('sync-c', 'true')
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800348 if d.sync_s:
349 have_default = True
350 e.setAttribute('sync-s', 'true')
YOUNG HO CHAa32c92c2018-02-14 16:57:31 +0900351 if not d.sync_tags:
352 have_default = True
353 e.setAttribute('sync-tags', 'false')
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800354 if have_default:
355 root.appendChild(e)
356 root.appendChild(doc.createTextNode(''))
357
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700358 if self._manifest_server:
359 e = doc.createElement('manifest-server')
360 e.setAttribute('url', self._manifest_server)
361 root.appendChild(e)
362 root.appendChild(doc.createTextNode(''))
363
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800364 def output_projects(parent, parent_node, projects):
David James8d201162013-10-11 17:03:19 -0700365 for project_name in projects:
366 for project in self._projects[project_name]:
367 output_project(parent, parent_node, project)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800368
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800369 def output_project(parent, parent_node, p):
Colin Cross5acde752012-03-28 20:15:45 -0700370 if not p.MatchesGroups(groups):
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800371 return
372
373 name = p.name
374 relpath = p.relpath
375 if parent:
376 name = self._UnjoinName(parent.name, name)
377 relpath = self._UnjoinRelpath(parent.relpath, relpath)
Colin Cross5acde752012-03-28 20:15:45 -0700378
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800379 e = doc.createElement('project')
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800380 parent_node.appendChild(e)
381 e.setAttribute('name', name)
382 if relpath != name:
383 e.setAttribute('path', relpath)
Conley Owensa17d7af2013-10-16 14:38:09 -0700384 remoteName = None
385 if d.remote:
Dan Willemsen96c2d652016-04-06 16:03:54 -0700386 remoteName = d.remote.name
387 if not d.remote or p.remote.orig_name != remoteName:
388 remoteName = p.remote.orig_name
Anthony King36ea2fb2014-05-06 11:54:01 +0100389 e.setAttribute('remote', remoteName)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800390 if peg_rev:
391 if self.IsMirror:
Brian Harring14a66742012-09-28 20:21:57 -0700392 value = p.bare_git.rev_parse(p.revisionExpr + '^0')
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800393 else:
Brian Harring14a66742012-09-28 20:21:57 -0700394 value = p.work_git.rev_parse(HEAD + '^0')
395 e.setAttribute('revision', value)
Conley Owens551dfec2015-07-10 14:54:54 -0700396 if peg_rev_upstream:
397 if p.upstream:
398 e.setAttribute('upstream', p.upstream)
399 elif value != p.revisionExpr:
400 # Only save the origin if the origin is not a sha1, and the default
401 # isn't our value
402 e.setAttribute('upstream', p.revisionExpr)
Sean McAllisteraf908cb2020-04-20 08:41:58 -0600403
404 if peg_rev_dest_branch:
405 if p.dest_branch:
406 e.setAttribute('dest-branch', p.dest_branch)
407 elif value != p.revisionExpr:
408 e.setAttribute('dest-branch', p.revisionExpr)
409
Anthony King36ea2fb2014-05-06 11:54:01 +0100410 else:
Dan Willemsen96c2d652016-04-06 16:03:54 -0700411 revision = self.remotes[p.remote.orig_name].revision or d.revisionExpr
Anthony King36ea2fb2014-05-06 11:54:01 +0100412 if not revision or revision != p.revisionExpr:
413 e.setAttribute('revision', p.revisionExpr)
Nasser Grainawida403412018-05-04 12:53:29 -0600414 if (p.upstream and (p.upstream != p.revisionExpr or
415 p.upstream != d.upstreamExpr)):
Mani Chandel7a91d512014-07-24 16:27:08 +0530416 e.setAttribute('upstream', p.upstream)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800417
Simon Ruggier7e59de22015-07-24 12:50:06 +0200418 if p.dest_branch and p.dest_branch != d.destBranchExpr:
419 e.setAttribute('dest-branch', p.dest_branch)
420
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800421 for c in p.copyfiles:
422 ce = doc.createElement('copyfile')
423 ce.setAttribute('src', c.src)
424 ce.setAttribute('dest', c.dest)
425 e.appendChild(ce)
426
Jeff Hamiltone0df2322014-04-21 17:10:59 -0500427 for l in p.linkfiles:
428 le = doc.createElement('linkfile')
429 le.setAttribute('src', l.src)
430 le.setAttribute('dest', l.dest)
431 e.appendChild(le)
432
Conley Owensbb1b5f52012-08-13 13:11:18 -0700433 default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath]
Dmitry Fink17f85ea2012-08-06 14:52:29 -0700434 egroups = [g for g in p.groups if g not in default_groups]
Conley Owens971de8e2012-04-16 10:36:08 -0700435 if egroups:
436 e.setAttribute('groups', ','.join(egroups))
Colin Cross5acde752012-03-28 20:15:45 -0700437
James W. Mills24c13082012-04-12 15:04:13 -0500438 for a in p.annotations:
439 if a.keep == "true":
440 ae = doc.createElement('annotation')
441 ae.setAttribute('name', a.name)
442 ae.setAttribute('value', a.value)
443 e.appendChild(ae)
444
Anatol Pomazau79770d22012-04-20 14:41:59 -0700445 if p.sync_c:
446 e.setAttribute('sync-c', 'true')
447
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800448 if p.sync_s:
449 e.setAttribute('sync-s', 'true')
450
YOUNG HO CHAa32c92c2018-02-14 16:57:31 +0900451 if not p.sync_tags:
452 e.setAttribute('sync-tags', 'false')
453
Dan Willemsen88409222015-08-17 15:29:10 -0700454 if p.clone_depth:
455 e.setAttribute('clone-depth', str(p.clone_depth))
456
Simran Basib9a1b732015-08-20 12:19:28 -0700457 self._output_manifest_project_extras(p, e)
458
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800459 if p.subprojects:
David James8d201162013-10-11 17:03:19 -0700460 subprojects = set(subp.name for subp in p.subprojects)
461 output_projects(p, e, list(sorted(subprojects)))
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800462
David James8d201162013-10-11 17:03:19 -0700463 projects = set(p.name for p in self._paths.values() if not p.parent)
464 output_projects(None, root, list(sorted(projects)))
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800465
Doug Anderson37282b42011-03-04 11:54:18 -0800466 if self._repo_hooks_project:
467 root.appendChild(doc.createTextNode(''))
468 e = doc.createElement('repo-hooks')
469 e.setAttribute('in-project', self._repo_hooks_project.name)
470 e.setAttribute('enabled-list',
471 ' '.join(self._repo_hooks_project.enabled_repo_hooks))
472 root.appendChild(e)
473
Mike Frysinger23411d32020-09-02 04:31:10 -0400474 return doc
475
476 def ToDict(self, **kwargs):
477 """Return the current manifest as a dictionary."""
478 # Elements that may only appear once.
479 SINGLE_ELEMENTS = {
480 'notice',
481 'default',
482 'manifest-server',
483 'repo-hooks',
484 }
485 # Elements that may be repeated.
486 MULTI_ELEMENTS = {
487 'remote',
488 'remove-project',
489 'project',
490 'extend-project',
491 'include',
492 # These are children of 'project' nodes.
493 'annotation',
494 'project',
495 'copyfile',
496 'linkfile',
497 }
498
499 doc = self.ToXml(**kwargs)
500 ret = {}
501
502 def append_children(ret, node):
503 for child in node.childNodes:
504 if child.nodeType == xml.dom.Node.ELEMENT_NODE:
505 attrs = child.attributes
506 element = dict((attrs.item(i).localName, attrs.item(i).value)
507 for i in range(attrs.length))
508 if child.nodeName in SINGLE_ELEMENTS:
509 ret[child.nodeName] = element
510 elif child.nodeName in MULTI_ELEMENTS:
511 ret.setdefault(child.nodeName, []).append(element)
512 else:
513 raise ManifestParseError('Unhandled element "%s"' % (child.nodeName,))
514
515 append_children(element, child)
516
517 append_children(ret, doc.firstChild)
518
519 return ret
520
521 def Save(self, fd, **kwargs):
522 """Write the current manifest out to the given file descriptor."""
523 doc = self.ToXml(**kwargs)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800524 doc.writexml(fd, '', ' ', '\n', 'UTF-8')
525
Simran Basib9a1b732015-08-20 12:19:28 -0700526 def _output_manifest_project_extras(self, p, e):
527 """Manifests can modify e if they support extra project attributes."""
528 pass
529
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700530 @property
David James8d201162013-10-11 17:03:19 -0700531 def paths(self):
532 self._Load()
533 return self._paths
534
535 @property
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700536 def projects(self):
537 self._Load()
Anthony Kingd58bfe52014-05-05 23:30:49 +0100538 return list(self._paths.values())
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700539
540 @property
541 def remotes(self):
542 self._Load()
543 return self._remotes
544
545 @property
546 def default(self):
547 self._Load()
548 return self._default
549
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800550 @property
Doug Anderson37282b42011-03-04 11:54:18 -0800551 def repo_hooks_project(self):
552 self._Load()
553 return self._repo_hooks_project
554
555 @property
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700556 def notice(self):
557 self._Load()
558 return self._notice
559
560 @property
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700561 def manifest_server(self):
562 self._Load()
Shawn O. Pearce34fb20f2011-11-30 13:41:02 -0800563 return self._manifest_server
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700564
565 @property
Xin Lid79a4bc2020-05-20 16:03:45 -0700566 def CloneBundle(self):
567 clone_bundle = self.manifestProject.config.GetBoolean('repo.clonebundle')
568 if clone_bundle is None:
569 return False if self.manifestProject.config.GetBoolean('repo.partialclone') else True
570 else:
571 return clone_bundle
572
573 @property
Xin Li745be2e2019-06-03 11:24:30 -0700574 def CloneFilter(self):
575 if self.manifestProject.config.GetBoolean('repo.partialclone'):
576 return self.manifestProject.config.GetString('repo.clonefilter')
577 return None
578
579 @property
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800580 def IsMirror(self):
581 return self.manifestProject.config.GetBoolean('repo.mirror')
582
Julien Campergue335f5ef2013-10-16 11:02:35 +0200583 @property
Mike Frysinger979d5bd2020-02-09 02:28:34 -0500584 def UseGitWorktrees(self):
585 return self.manifestProject.config.GetBoolean('repo.worktree')
586
587 @property
Julien Campergue335f5ef2013-10-16 11:02:35 +0200588 def IsArchive(self):
589 return self.manifestProject.config.GetBoolean('repo.archive')
590
Martin Kellye4e94d22017-03-21 16:05:12 -0700591 @property
592 def HasSubmodules(self):
593 return self.manifestProject.config.GetBoolean('repo.submodules')
594
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700595 def _Unload(self):
596 self._loaded = False
597 self._projects = {}
David James8d201162013-10-11 17:03:19 -0700598 self._paths = {}
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700599 self._remotes = {}
600 self._default = None
Doug Anderson37282b42011-03-04 11:54:18 -0800601 self._repo_hooks_project = None
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700602 self._notice = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700603 self.branch = None
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700604 self._manifest_server = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700605
606 def _Load(self):
607 if not self._loaded:
Shawn O. Pearce2450a292008-11-04 08:22:07 -0800608 m = self.manifestProject
609 b = m.GetBranch(m.CurrentBranch).merge
Shawn O. Pearce21c5c342009-06-25 16:47:30 -0700610 if b is not None and b.startswith(R_HEADS):
Shawn O. Pearce2450a292008-11-04 08:22:07 -0800611 b = b[len(R_HEADS):]
612 self.branch = b
613
Colin Cross23acdd32012-04-21 00:33:54 -0700614 nodes = []
Brian Harring475a47d2012-06-07 20:05:35 -0700615 nodes.append(self._ParseManifestXml(self.manifestFile,
616 self.manifestProject.worktree))
Shawn O. Pearce5cc66792008-10-23 16:19:27 -0700617
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400618 if self._load_local_manifests and self.local_manifests:
Basil Gelloc7453502018-05-25 20:23:52 +0300619 try:
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400620 for local_file in sorted(platform_utils.listdir(self.local_manifests)):
Basil Gelloc7453502018-05-25 20:23:52 +0300621 if local_file.endswith('.xml'):
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400622 local = os.path.join(self.local_manifests, local_file)
Basil Gelloc7453502018-05-25 20:23:52 +0300623 nodes.append(self._ParseManifestXml(local, self.repodir))
624 except OSError:
625 pass
David Pursehouse2d5a0df2012-11-13 02:50:36 +0900626
Joe Onorato26e24752013-01-11 12:35:53 -0800627 try:
628 self._ParseManifest(nodes)
629 except ManifestParseError as e:
630 # There was a problem parsing, unload ourselves in case they catch
631 # this error and try again later, we will show the correct error
632 self._Unload()
633 raise e
Shawn O. Pearce5cc66792008-10-23 16:19:27 -0700634
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800635 if self.IsMirror:
636 self._AddMetaProjectMirror(self.repoProject)
637 self._AddMetaProjectMirror(self.manifestProject)
638
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700639 self._loaded = True
640
Fredrik de Groot352c93b2020-10-06 12:55:14 +0200641 def _ParseManifestXml(self, path, include_root, parent_groups=''):
David Pursehousef7fc8a92012-11-13 04:00:28 +0900642 try:
643 root = xml.dom.minidom.parse(path)
David Pursehouse2d5a0df2012-11-13 02:50:36 +0900644 except (OSError, xml.parsers.expat.ExpatError) as e:
David Pursehousef7fc8a92012-11-13 04:00:28 +0900645 raise ManifestParseError("error parsing manifest %s: %s" % (path, e))
646
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700647 if not root or not root.childNodes:
Brian Harring26448742011-04-28 05:04:41 -0700648 raise ManifestParseError("no root node in %s" % (path,))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700649
Jooncheol Park34acdd22012-08-27 02:25:59 +0900650 for manifest in root.childNodes:
651 if manifest.nodeName == 'manifest':
652 break
653 else:
Brian Harring26448742011-04-28 05:04:41 -0700654 raise ManifestParseError("no <manifest> in %s" % (path,))
655
Colin Cross23acdd32012-04-21 00:33:54 -0700656 nodes = []
David Pursehouse65b0ba52018-06-24 16:21:51 +0900657 for node in manifest.childNodes:
David Pursehousec1b86a22012-11-14 11:36:51 +0900658 if node.nodeName == 'include':
659 name = self._reqatt(node, 'name')
Fredrik de Groot352c93b2020-10-06 12:55:14 +0200660 include_groups = ''
661 if parent_groups:
662 include_groups = parent_groups
663 if node.hasAttribute('groups'):
664 include_groups = node.getAttribute('groups') + ',' + include_groups
David Pursehousec1b86a22012-11-14 11:36:51 +0900665 fp = os.path.join(include_root, name)
666 if not os.path.isfile(fp):
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530667 raise ManifestParseError("include %s doesn't exist or isn't a file"
David Pursehouseabdf7502020-02-12 14:58:39 +0900668 % (name,))
David Pursehousec1b86a22012-11-14 11:36:51 +0900669 try:
Fredrik de Groot352c93b2020-10-06 12:55:14 +0200670 nodes.extend(self._ParseManifestXml(fp, include_root, include_groups))
David Pursehousec1b86a22012-11-14 11:36:51 +0900671 # should isolate this to the exact exception, but that's
672 # tricky. actual parsing implementation may vary.
673 except (KeyboardInterrupt, RuntimeError, SystemExit):
674 raise
675 except Exception as e:
676 raise ManifestParseError(
Mike Frysingerec558df2019-07-05 01:38:05 -0400677 "failed parsing included manifest %s: %s" % (name, e))
David Pursehousec1b86a22012-11-14 11:36:51 +0900678 else:
Fredrik de Groot352c93b2020-10-06 12:55:14 +0200679 if parent_groups and node.nodeName == 'project':
680 nodeGroups = parent_groups
681 if node.hasAttribute('groups'):
682 nodeGroups = node.getAttribute('groups') + ',' + nodeGroups
683 node.setAttribute('groups', nodeGroups)
David Pursehousec1b86a22012-11-14 11:36:51 +0900684 nodes.append(node)
Colin Cross23acdd32012-04-21 00:33:54 -0700685 return nodes
Brian Harring26448742011-04-28 05:04:41 -0700686
Colin Cross23acdd32012-04-21 00:33:54 -0700687 def _ParseManifest(self, node_list):
688 for node in itertools.chain(*node_list):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700689 if node.nodeName == 'remote':
690 remote = self._ParseRemote(node)
David Pursehouse717ece92012-11-13 08:49:16 +0900691 if remote:
692 if remote.name in self._remotes:
693 if remote != self._remotes[remote.name]:
694 raise ManifestParseError(
695 'remote %s already exists with different attributes' %
696 (remote.name))
697 else:
698 self._remotes[remote.name] = remote
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700699
Colin Cross23acdd32012-04-21 00:33:54 -0700700 for node in itertools.chain(*node_list):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700701 if node.nodeName == 'default':
Julien Campergue74879922013-10-09 14:38:46 +0200702 new_default = self._ParseDefault(node)
703 if self._default is None:
704 self._default = new_default
705 elif new_default != self._default:
David Pursehouse37128b62013-10-15 10:48:40 +0900706 raise ManifestParseError('duplicate default in %s' %
707 (self.manifestFile))
Julien Campergue74879922013-10-09 14:38:46 +0200708
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700709 if self._default is None:
710 self._default = _Default()
711
Colin Cross23acdd32012-04-21 00:33:54 -0700712 for node in itertools.chain(*node_list):
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700713 if node.nodeName == 'notice':
714 if self._notice is not None:
Doug Anderson37282b42011-03-04 11:54:18 -0800715 raise ManifestParseError(
716 'duplicate notice in %s' %
717 (self.manifestFile))
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700718 self._notice = self._ParseNotice(node)
719
Colin Cross23acdd32012-04-21 00:33:54 -0700720 for node in itertools.chain(*node_list):
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700721 if node.nodeName == 'manifest-server':
722 url = self._reqatt(node, 'url')
723 if self._manifest_server is not None:
David Pursehousec1b86a22012-11-14 11:36:51 +0900724 raise ManifestParseError(
725 'duplicate manifest-server in %s' %
726 (self.manifestFile))
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700727 self._manifest_server = url
728
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800729 def recursively_add_projects(project):
David James8d201162013-10-11 17:03:19 -0700730 projects = self._projects.setdefault(project.name, [])
731 if project.relpath is None:
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800732 raise ManifestParseError(
David James8d201162013-10-11 17:03:19 -0700733 'missing path for %s in %s' %
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800734 (project.name, self.manifestFile))
David James8d201162013-10-11 17:03:19 -0700735 if project.relpath in self._paths:
736 raise ManifestParseError(
737 'duplicate path %s in %s' %
738 (project.relpath, self.manifestFile))
739 self._paths[project.relpath] = project
740 projects.append(project)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800741 for subproject in project.subprojects:
742 recursively_add_projects(subproject)
743
Colin Cross23acdd32012-04-21 00:33:54 -0700744 for node in itertools.chain(*node_list):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700745 if node.nodeName == 'project':
746 project = self._ParseProject(node)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800747 recursively_add_projects(project)
Josh Triplett884a3872014-06-12 14:57:29 -0700748 if node.nodeName == 'extend-project':
749 name = self._reqatt(node, 'name')
750
751 if name not in self._projects:
752 raise ManifestParseError('extend-project element specifies non-existent '
753 'project: %s' % name)
754
755 path = node.getAttribute('path')
756 groups = node.getAttribute('groups')
757 if groups:
Mike Frysinger51e39d52020-12-04 05:32:06 -0500758 groups = self._ParseList(groups)
Luis Hector Chavez7d525852018-03-15 09:54:08 -0700759 revision = node.getAttribute('revision')
Kyunam Jobd0aae92020-02-04 11:38:53 +0900760 remote = node.getAttribute('remote')
761 if remote:
762 remote = self._get_remote(node)
Josh Triplett884a3872014-06-12 14:57:29 -0700763
764 for p in self._projects[name]:
765 if path and p.relpath != path:
766 continue
767 if groups:
768 p.groups.extend(groups)
Luis Hector Chavez7d525852018-03-15 09:54:08 -0700769 if revision:
770 p.revisionExpr = revision
Miguel Gaio1f207762020-07-17 14:09:13 +0200771 if IsId(revision):
772 p.revisionId = revision
773 else:
774 p.revisionId = None
Kyunam Jobd0aae92020-02-04 11:38:53 +0900775 if remote:
776 p.remote = remote.ToRemoteSpec(name)
Doug Anderson37282b42011-03-04 11:54:18 -0800777 if node.nodeName == 'repo-hooks':
778 # Get the name of the project and the (space-separated) list of enabled.
779 repo_hooks_project = self._reqatt(node, 'in-project')
Mike Frysinger51e39d52020-12-04 05:32:06 -0500780 enabled_repo_hooks = self._ParseList(self._reqatt(node, 'enabled-list'))
Doug Anderson37282b42011-03-04 11:54:18 -0800781
782 # Only one project can be the hooks project
783 if self._repo_hooks_project is not None:
784 raise ManifestParseError(
785 'duplicate repo-hooks in %s' %
786 (self.manifestFile))
787
788 # Store a reference to the Project.
789 try:
David James8d201162013-10-11 17:03:19 -0700790 repo_hooks_projects = self._projects[repo_hooks_project]
Doug Anderson37282b42011-03-04 11:54:18 -0800791 except KeyError:
792 raise ManifestParseError(
793 'project %s not found for repo-hooks' %
794 (repo_hooks_project))
795
David James8d201162013-10-11 17:03:19 -0700796 if len(repo_hooks_projects) != 1:
797 raise ManifestParseError(
798 'internal error parsing repo-hooks in %s' %
799 (self.manifestFile))
800 self._repo_hooks_project = repo_hooks_projects[0]
801
Doug Anderson37282b42011-03-04 11:54:18 -0800802 # Store the enabled hooks in the Project object.
803 self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks
Colin Cross23acdd32012-04-21 00:33:54 -0700804 if node.nodeName == 'remove-project':
805 name = self._reqatt(node, 'name')
David Jamesb8433df2014-01-30 10:11:17 -0800806
807 if name not in self._projects:
David Pursehousef9107482012-11-16 19:12:32 +0900808 raise ManifestParseError('remove-project element specifies non-existent '
809 'project: %s' % name)
Colin Cross23acdd32012-04-21 00:33:54 -0700810
David Jamesb8433df2014-01-30 10:11:17 -0800811 for p in self._projects[name]:
812 del self._paths[p.relpath]
813 del self._projects[name]
814
Colin Cross23acdd32012-04-21 00:33:54 -0700815 # If the manifest removes the hooks project, treat it as if it deleted
816 # the repo-hooks element too.
817 if self._repo_hooks_project and (self._repo_hooks_project.name == name):
818 self._repo_hooks_project = None
819
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800820 def _AddMetaProjectMirror(self, m):
821 name = None
822 m_url = m.GetRemote(m.remote.name).url
823 if m_url.endswith('/.git'):
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530824 raise ManifestParseError('refusing to mirror %s' % m_url)
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800825
826 if self._default and self._default.remote:
Conley Owensceea3682011-10-20 10:45:47 -0700827 url = self._default.remote.resolvedFetchUrl
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800828 if not url.endswith('/'):
829 url += '/'
830 if m_url.startswith(url):
831 remote = self._default.remote
832 name = m_url[len(url):]
833
834 if name is None:
835 s = m_url.rindex('/') + 1
Conley Owensdb728cd2011-09-26 16:34:01 -0700836 manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
Shawn O. Pearcef35b2d92012-08-02 11:46:22 -0700837 remote = _XmlRemote('origin', fetch=m_url[:s], manifestUrl=manifestUrl)
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800838 name = m_url[s:]
839
840 if name.endswith('.git'):
841 name = name[:-4]
842
843 if name not in self._projects:
844 m.PreSync()
845 gitdir = os.path.join(self.topdir, '%s.git' % name)
David Pursehousee5913ae2020-02-12 13:56:59 +0900846 project = Project(manifest=self,
847 name=name,
848 remote=remote.ToRemoteSpec(name),
849 gitdir=gitdir,
850 objdir=gitdir,
851 worktree=None,
852 relpath=name or None,
853 revisionExpr=m.revisionExpr,
854 revisionId=None)
David James8d201162013-10-11 17:03:19 -0700855 self._projects[project.name] = [project]
Kwanhong Leeccd218c2014-02-17 13:07:32 +0900856 self._paths[project.relpath] = project
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800857
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700858 def _ParseRemote(self, node):
859 """
860 reads a <remote> element from the manifest file
861 """
862 name = self._reqatt(node, 'name')
Yestin Sunb292b982012-07-02 07:32:50 -0700863 alias = node.getAttribute('alias')
864 if alias == '':
865 alias = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700866 fetch = self._reqatt(node, 'fetch')
Steve Raed6480452016-08-10 15:00:00 -0700867 pushUrl = node.getAttribute('pushurl')
868 if pushUrl == '':
869 pushUrl = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700870 review = node.getAttribute('review')
Shawn O. Pearceae6e0942008-11-06 10:25:35 -0800871 if review == '':
872 review = None
Anthony King36ea2fb2014-05-06 11:54:01 +0100873 revision = node.getAttribute('revision')
874 if revision == '':
875 revision = None
Conley Owensdb728cd2011-09-26 16:34:01 -0700876 manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
Steve Raed6480452016-08-10 15:00:00 -0700877 return _XmlRemote(name, alias, fetch, pushUrl, manifestUrl, review, revision)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700878
879 def _ParseDefault(self, node):
880 """
881 reads a <default> element from the manifest file
882 """
883 d = _Default()
884 d.remote = self._get_remote(node)
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700885 d.revisionExpr = node.getAttribute('revision')
886 if d.revisionExpr == '':
887 d.revisionExpr = None
Anatol Pomazau79770d22012-04-20 14:41:59 -0700888
Bryan Jacobsf609f912013-05-06 13:36:24 -0400889 d.destBranchExpr = node.getAttribute('dest-branch') or None
Nasser Grainawida403412018-05-04 12:53:29 -0600890 d.upstreamExpr = node.getAttribute('upstream') or None
Bryan Jacobsf609f912013-05-06 13:36:24 -0400891
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500892 d.sync_j = XmlInt(node, 'sync-j', 1)
893 if d.sync_j <= 0:
894 raise ManifestParseError('%s: sync-j must be greater than 0, not "%s"' %
895 (self.manifestFile, d.sync_j))
Anatol Pomazau79770d22012-04-20 14:41:59 -0700896
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500897 d.sync_c = XmlBool(node, 'sync-c', False)
898 d.sync_s = XmlBool(node, 'sync-s', False)
899 d.sync_tags = XmlBool(node, 'sync-tags', True)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700900 return d
901
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700902 def _ParseNotice(self, node):
903 """
904 reads a <notice> element from the manifest file
905
906 The <notice> element is distinct from other tags in the XML in that the
907 data is conveyed between the start and end tag (it's not an empty-element
908 tag).
909
910 The white space (carriage returns, indentation) for the notice element is
911 relevant and is parsed in a way that is based on how python docstrings work.
912 In fact, the code is remarkably similar to here:
913 http://www.python.org/dev/peps/pep-0257/
914 """
915 # Get the data out of the node...
916 notice = node.childNodes[0].data
917
918 # Figure out minimum indentation, skipping the first line (the same line
919 # as the <notice> tag)...
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530920 minIndent = sys.maxsize
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700921 lines = notice.splitlines()
922 for line in lines[1:]:
923 lstrippedLine = line.lstrip()
924 if lstrippedLine:
925 indent = len(line) - len(lstrippedLine)
926 minIndent = min(indent, minIndent)
927
928 # Strip leading / trailing blank lines and also indentation.
929 cleanLines = [lines[0].strip()]
930 for line in lines[1:]:
931 cleanLines.append(line[minIndent:].rstrip())
932
933 # Clear completely blank lines from front and back...
934 while cleanLines and not cleanLines[0]:
935 del cleanLines[0]
936 while cleanLines and not cleanLines[-1]:
937 del cleanLines[-1]
938
939 return '\n'.join(cleanLines)
940
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800941 def _JoinName(self, parent_name, name):
942 return os.path.join(parent_name, name)
943
944 def _UnjoinName(self, parent_name, name):
945 return os.path.relpath(name, parent_name)
946
David Pursehousee5913ae2020-02-12 13:56:59 +0900947 def _ParseProject(self, node, parent=None, **extra_proj_attrs):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700948 """
949 reads a <project> element from the manifest file
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700950 """
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700951 name = self._reqatt(node, 'name')
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800952 if parent:
953 name = self._JoinName(parent.name, name)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700954
955 remote = self._get_remote(node)
956 if remote is None:
957 remote = self._default.remote
958 if remote is None:
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530959 raise ManifestParseError("no remote for project %s within %s" %
David Pursehouseabdf7502020-02-12 14:58:39 +0900960 (name, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700961
Anthony King36ea2fb2014-05-06 11:54:01 +0100962 revisionExpr = node.getAttribute('revision') or remote.revision
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700963 if not revisionExpr:
964 revisionExpr = self._default.revisionExpr
965 if not revisionExpr:
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530966 raise ManifestParseError("no revision for project %s within %s" %
David Pursehouseabdf7502020-02-12 14:58:39 +0900967 (name, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700968
969 path = node.getAttribute('path')
970 if not path:
971 path = name
972 if path.startswith('/'):
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530973 raise ManifestParseError("project %s path cannot be absolute in %s" %
David Pursehouseabdf7502020-02-12 14:58:39 +0900974 (name, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700975
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500976 rebase = XmlBool(node, 'rebase', True)
977 sync_c = XmlBool(node, 'sync-c', False)
978 sync_s = XmlBool(node, 'sync-s', self._default.sync_s)
979 sync_tags = XmlBool(node, 'sync-tags', self._default.sync_tags)
Mike Pontillod3153822012-02-28 11:53:24 -0800980
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500981 clone_depth = XmlInt(node, 'clone-depth')
982 if clone_depth is not None and clone_depth <= 0:
983 raise ManifestParseError('%s: clone-depth must be greater than 0, not "%s"' %
984 (self.manifestFile, clone_depth))
David Pursehouseede7f122012-11-27 22:25:30 +0900985
Bryan Jacobsf609f912013-05-06 13:36:24 -0400986 dest_branch = node.getAttribute('dest-branch') or self._default.destBranchExpr
987
Nasser Grainawida403412018-05-04 12:53:29 -0600988 upstream = node.getAttribute('upstream') or self._default.upstreamExpr
Brian Harring14a66742012-09-28 20:21:57 -0700989
Conley Owens971de8e2012-04-16 10:36:08 -0700990 groups = ''
991 if node.hasAttribute('groups'):
992 groups = node.getAttribute('groups')
Mike Frysinger51e39d52020-12-04 05:32:06 -0500993 groups = self._ParseList(groups)
Brian Harring7da13142012-06-15 02:24:20 -0700994
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800995 if parent is None:
Mike Frysinger979d5bd2020-02-09 02:28:34 -0500996 relpath, worktree, gitdir, objdir, use_git_worktrees = \
997 self.GetProjectPaths(name, path)
Shawn O. Pearcecd81dd62012-10-26 12:18:00 -0700998 else:
Mike Frysinger979d5bd2020-02-09 02:28:34 -0500999 use_git_worktrees = False
David James8d201162013-10-11 17:03:19 -07001000 relpath, worktree, gitdir, objdir = \
1001 self.GetSubprojectPaths(parent, name, path)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001002
1003 default_groups = ['all', 'name:%s' % name, 'path:%s' % relpath]
1004 groups.extend(set(default_groups).difference(groups))
Shawn O. Pearcecd81dd62012-10-26 12:18:00 -07001005
Scott Fandb83b1b2013-02-28 09:34:14 +08001006 if self.IsMirror and node.hasAttribute('force-path'):
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -05001007 if XmlBool(node, 'force-path', False):
Scott Fandb83b1b2013-02-28 09:34:14 +08001008 gitdir = os.path.join(self.topdir, '%s.git' % path)
1009
David Pursehousee5913ae2020-02-12 13:56:59 +09001010 project = Project(manifest=self,
1011 name=name,
1012 remote=remote.ToRemoteSpec(name),
1013 gitdir=gitdir,
1014 objdir=objdir,
1015 worktree=worktree,
1016 relpath=relpath,
1017 revisionExpr=revisionExpr,
1018 revisionId=None,
1019 rebase=rebase,
1020 groups=groups,
1021 sync_c=sync_c,
1022 sync_s=sync_s,
1023 sync_tags=sync_tags,
1024 clone_depth=clone_depth,
1025 upstream=upstream,
1026 parent=parent,
1027 dest_branch=dest_branch,
Mike Frysinger979d5bd2020-02-09 02:28:34 -05001028 use_git_worktrees=use_git_worktrees,
Simran Basib9a1b732015-08-20 12:19:28 -07001029 **extra_proj_attrs)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001030
1031 for n in node.childNodes:
Shawn O. Pearce242b5262009-05-19 13:00:29 -07001032 if n.nodeName == 'copyfile':
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001033 self._ParseCopyFile(project, n)
Jeff Hamiltone0df2322014-04-21 17:10:59 -05001034 if n.nodeName == 'linkfile':
1035 self._ParseLinkFile(project, n)
James W. Mills24c13082012-04-12 15:04:13 -05001036 if n.nodeName == 'annotation':
1037 self._ParseAnnotation(project, n)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001038 if n.nodeName == 'project':
David Pursehousee5913ae2020-02-12 13:56:59 +09001039 project.subprojects.append(self._ParseProject(n, parent=project))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001040
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001041 return project
1042
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001043 def GetProjectPaths(self, name, path):
Mike Frysingercebf2272020-05-26 01:02:29 -04001044 # The manifest entries might have trailing slashes. Normalize them to avoid
1045 # unexpected filesystem behavior since we do string concatenation below.
1046 path = path.rstrip('/')
1047 name = name.rstrip('/')
Mike Frysinger979d5bd2020-02-09 02:28:34 -05001048 use_git_worktrees = False
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001049 relpath = path
1050 if self.IsMirror:
1051 worktree = None
1052 gitdir = os.path.join(self.topdir, '%s.git' % name)
David James8d201162013-10-11 17:03:19 -07001053 objdir = gitdir
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001054 else:
1055 worktree = os.path.join(self.topdir, path).replace('\\', '/')
1056 gitdir = os.path.join(self.repodir, 'projects', '%s.git' % path)
Mike Frysinger979d5bd2020-02-09 02:28:34 -05001057 # We allow people to mix git worktrees & non-git worktrees for now.
1058 # This allows for in situ migration of repo clients.
1059 if os.path.exists(gitdir) or not self.UseGitWorktrees:
1060 objdir = os.path.join(self.repodir, 'project-objects', '%s.git' % name)
1061 else:
1062 use_git_worktrees = True
1063 gitdir = os.path.join(self.repodir, 'worktrees', '%s.git' % name)
1064 objdir = gitdir
1065 return relpath, worktree, gitdir, objdir, use_git_worktrees
David James8d201162013-10-11 17:03:19 -07001066
1067 def GetProjectsWithName(self, name):
1068 return self._projects.get(name, [])
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001069
1070 def GetSubprojectName(self, parent, submodule_path):
1071 return os.path.join(parent.name, submodule_path)
1072
1073 def _JoinRelpath(self, parent_relpath, relpath):
1074 return os.path.join(parent_relpath, relpath)
1075
1076 def _UnjoinRelpath(self, parent_relpath, relpath):
1077 return os.path.relpath(relpath, parent_relpath)
1078
David James8d201162013-10-11 17:03:19 -07001079 def GetSubprojectPaths(self, parent, name, path):
Mike Frysingercebf2272020-05-26 01:02:29 -04001080 # The manifest entries might have trailing slashes. Normalize them to avoid
1081 # unexpected filesystem behavior since we do string concatenation below.
1082 path = path.rstrip('/')
1083 name = name.rstrip('/')
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001084 relpath = self._JoinRelpath(parent.relpath, path)
1085 gitdir = os.path.join(parent.gitdir, 'subprojects', '%s.git' % path)
David James8d201162013-10-11 17:03:19 -07001086 objdir = os.path.join(parent.gitdir, 'subproject-objects', '%s.git' % name)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001087 if self.IsMirror:
1088 worktree = None
1089 else:
1090 worktree = os.path.join(parent.worktree, path).replace('\\', '/')
David James8d201162013-10-11 17:03:19 -07001091 return relpath, worktree, gitdir, objdir
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001092
Mike Frysinger04122b72019-07-31 23:32:58 -04001093 @staticmethod
1094 def _CheckLocalPath(path, symlink=False):
1095 """Verify |path| is reasonable for use in <copyfile> & <linkfile>."""
1096 if '~' in path:
1097 return '~ not allowed (due to 8.3 filenames on Windows filesystems)'
1098
1099 # Some filesystems (like Apple's HFS+) try to normalize Unicode codepoints
1100 # which means there are alternative names for ".git". Reject paths with
1101 # these in it as there shouldn't be any reasonable need for them here.
1102 # The set of codepoints here was cribbed from jgit's implementation:
1103 # https://eclipse.googlesource.com/jgit/jgit/+/9110037e3e9461ff4dac22fee84ef3694ed57648/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java#884
1104 BAD_CODEPOINTS = {
1105 u'\u200C', # ZERO WIDTH NON-JOINER
1106 u'\u200D', # ZERO WIDTH JOINER
1107 u'\u200E', # LEFT-TO-RIGHT MARK
1108 u'\u200F', # RIGHT-TO-LEFT MARK
1109 u'\u202A', # LEFT-TO-RIGHT EMBEDDING
1110 u'\u202B', # RIGHT-TO-LEFT EMBEDDING
1111 u'\u202C', # POP DIRECTIONAL FORMATTING
1112 u'\u202D', # LEFT-TO-RIGHT OVERRIDE
1113 u'\u202E', # RIGHT-TO-LEFT OVERRIDE
1114 u'\u206A', # INHIBIT SYMMETRIC SWAPPING
1115 u'\u206B', # ACTIVATE SYMMETRIC SWAPPING
1116 u'\u206C', # INHIBIT ARABIC FORM SHAPING
1117 u'\u206D', # ACTIVATE ARABIC FORM SHAPING
1118 u'\u206E', # NATIONAL DIGIT SHAPES
1119 u'\u206F', # NOMINAL DIGIT SHAPES
1120 u'\uFEFF', # ZERO WIDTH NO-BREAK SPACE
1121 }
1122 if BAD_CODEPOINTS & set(path):
1123 # This message is more expansive than reality, but should be fine.
1124 return 'Unicode combining characters not allowed'
1125
1126 # Assume paths might be used on case-insensitive filesystems.
1127 path = path.lower()
1128
Mike Frysingerd9254592020-02-19 22:36:26 -05001129 # Split up the path by its components. We can't use os.path.sep exclusively
1130 # as some platforms (like Windows) will convert / to \ and that bypasses all
1131 # our constructed logic here. Especially since manifest authors only use
1132 # / in their paths.
1133 resep = re.compile(r'[/%s]' % re.escape(os.path.sep))
1134 parts = resep.split(path)
1135
Mike Frysingerae625412020-02-10 17:10:03 -05001136 # Some people use src="." to create stable links to projects. Lets allow
1137 # that but reject all other uses of "." to keep things simple.
Mike Frysingerae625412020-02-10 17:10:03 -05001138 if parts != ['.']:
1139 for part in set(parts):
1140 if part in {'.', '..', '.git'} or part.startswith('.repo'):
1141 return 'bad component: %s' % (part,)
Mike Frysinger04122b72019-07-31 23:32:58 -04001142
Mike Frysingerd9254592020-02-19 22:36:26 -05001143 if not symlink and resep.match(path[-1]):
Mike Frysinger04122b72019-07-31 23:32:58 -04001144 return 'dirs not allowed'
1145
Mike Frysingerd9254592020-02-19 22:36:26 -05001146 # NB: The two abspath checks here are to handle platforms with multiple
1147 # filesystem path styles (e.g. Windows).
Mike Frysinger04122b72019-07-31 23:32:58 -04001148 norm = os.path.normpath(path)
Mike Frysingerd9254592020-02-19 22:36:26 -05001149 if (norm == '..' or
1150 (len(norm) >= 3 and norm.startswith('..') and resep.match(norm[0])) or
1151 os.path.isabs(norm) or
1152 norm.startswith('/')):
Mike Frysinger04122b72019-07-31 23:32:58 -04001153 return 'path cannot be outside'
1154
1155 @classmethod
1156 def _ValidateFilePaths(cls, element, src, dest):
1157 """Verify |src| & |dest| are reasonable for <copyfile> & <linkfile>.
1158
1159 We verify the path independent of any filesystem state as we won't have a
1160 checkout available to compare to. i.e. This is for parsing validation
1161 purposes only.
1162
1163 We'll do full/live sanity checking before we do the actual filesystem
1164 modifications in _CopyFile/_LinkFile/etc...
1165 """
1166 # |dest| is the file we write to or symlink we create.
1167 # It is relative to the top of the repo client checkout.
1168 msg = cls._CheckLocalPath(dest)
1169 if msg:
1170 raise ManifestInvalidPathError(
1171 '<%s> invalid "dest": %s: %s' % (element, dest, msg))
1172
1173 # |src| is the file we read from or path we point to for symlinks.
1174 # It is relative to the top of the git project checkout.
1175 msg = cls._CheckLocalPath(src, symlink=element == 'linkfile')
1176 if msg:
1177 raise ManifestInvalidPathError(
1178 '<%s> invalid "src": %s: %s' % (element, src, msg))
1179
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001180 def _ParseCopyFile(self, project, node):
1181 src = self._reqatt(node, 'src')
1182 dest = self._reqatt(node, 'dest')
Shawn O. Pearcee284ad12008-11-04 07:37:10 -08001183 if not self.IsMirror:
1184 # src is project relative;
Mike Frysinger04122b72019-07-31 23:32:58 -04001185 # dest is relative to the top of the tree.
1186 # We only validate paths if we actually plan to process them.
1187 self._ValidateFilePaths('copyfile', src, dest)
Mike Frysingere6a202f2019-08-02 15:57:57 -04001188 project.AddCopyFile(src, dest, self.topdir)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001189
Jeff Hamiltone0df2322014-04-21 17:10:59 -05001190 def _ParseLinkFile(self, project, node):
1191 src = self._reqatt(node, 'src')
1192 dest = self._reqatt(node, 'dest')
1193 if not self.IsMirror:
1194 # src is project relative;
Mike Frysinger04122b72019-07-31 23:32:58 -04001195 # dest is relative to the top of the tree.
1196 # We only validate paths if we actually plan to process them.
1197 self._ValidateFilePaths('linkfile', src, dest)
Mike Frysingere6a202f2019-08-02 15:57:57 -04001198 project.AddLinkFile(src, dest, self.topdir)
Jeff Hamiltone0df2322014-04-21 17:10:59 -05001199
James W. Mills24c13082012-04-12 15:04:13 -05001200 def _ParseAnnotation(self, project, node):
1201 name = self._reqatt(node, 'name')
1202 value = self._reqatt(node, 'value')
1203 try:
1204 keep = self._reqatt(node, 'keep').lower()
1205 except ManifestParseError:
1206 keep = "true"
1207 if keep != "true" and keep != "false":
Chirayu Desai217ea7d2013-03-01 19:14:38 +05301208 raise ManifestParseError('optional "keep" attribute must be '
David Pursehouseabdf7502020-02-12 14:58:39 +09001209 '"true" or "false"')
James W. Mills24c13082012-04-12 15:04:13 -05001210 project.AddAnnotation(name, value, keep)
1211
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001212 def _get_remote(self, node):
1213 name = node.getAttribute('remote')
1214 if not name:
1215 return None
1216
1217 v = self._remotes.get(name)
1218 if not v:
Chirayu Desai217ea7d2013-03-01 19:14:38 +05301219 raise ManifestParseError("remote %s not defined in %s" %
David Pursehouseabdf7502020-02-12 14:58:39 +09001220 (name, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001221 return v
1222
1223 def _reqatt(self, node, attname):
1224 """
1225 reads a required attribute from the node.
1226 """
1227 v = node.getAttribute(attname)
1228 if not v:
Chirayu Desai217ea7d2013-03-01 19:14:38 +05301229 raise ManifestParseError("no %s in <%s> within %s" %
David Pursehouseabdf7502020-02-12 14:58:39 +09001230 (attname, node.nodeName, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001231 return v
Julien Camperguedd654222014-01-09 16:21:37 +01001232
1233 def projectsDiff(self, manifest):
1234 """return the projects differences between two manifests.
1235
1236 The diff will be from self to given manifest.
1237
1238 """
1239 fromProjects = self.paths
1240 toProjects = manifest.paths
1241
Anthony King7446c592014-05-06 09:19:39 +01001242 fromKeys = sorted(fromProjects.keys())
1243 toKeys = sorted(toProjects.keys())
Julien Camperguedd654222014-01-09 16:21:37 +01001244
1245 diff = {'added': [], 'removed': [], 'changed': [], 'unreachable': []}
1246
1247 for proj in fromKeys:
David Pursehouseeeff3532020-02-12 11:24:10 +09001248 if proj not in toKeys:
Julien Camperguedd654222014-01-09 16:21:37 +01001249 diff['removed'].append(fromProjects[proj])
1250 else:
1251 fromProj = fromProjects[proj]
1252 toProj = toProjects[proj]
1253 try:
1254 fromRevId = fromProj.GetCommitRevisionId()
1255 toRevId = toProj.GetCommitRevisionId()
1256 except ManifestInvalidRevisionError:
1257 diff['unreachable'].append((fromProj, toProj))
1258 else:
1259 if fromRevId != toRevId:
1260 diff['changed'].append((fromProj, toProj))
1261 toKeys.remove(proj)
1262
1263 for proj in toKeys:
1264 diff['added'].append(toProjects[proj])
1265
1266 return diff
Simran Basib9a1b732015-08-20 12:19:28 -07001267
1268
1269class GitcManifest(XmlManifest):
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04001270 """Parser for GitC (git-in-the-cloud) manifests."""
Simran Basib9a1b732015-08-20 12:19:28 -07001271
David Pursehousee5913ae2020-02-12 13:56:59 +09001272 def _ParseProject(self, node, parent=None):
Simran Basib9a1b732015-08-20 12:19:28 -07001273 """Override _ParseProject and add support for GITC specific attributes."""
1274 return super(GitcManifest, self)._ParseProject(
1275 node, parent=parent, old_revision=node.getAttribute('old-revision'))
1276
1277 def _output_manifest_project_extras(self, p, e):
1278 """Output GITC Specific Project attributes"""
1279 if p.old_revision:
Stefan Beller66851062016-06-17 16:40:08 -07001280 e.setAttribute('old-revision', str(p.old_revision))
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04001281
1282
1283class RepoClient(XmlManifest):
1284 """Manages a repo client checkout."""
1285
1286 def __init__(self, repodir, manifest_file=None):
1287 self.isGitcClient = False
1288
1289 if os.path.exists(os.path.join(repodir, LOCAL_MANIFEST_NAME)):
1290 print('error: %s is not supported; put local manifests in `%s` instead' %
1291 (LOCAL_MANIFEST_NAME, os.path.join(repodir, LOCAL_MANIFESTS_DIR_NAME)),
1292 file=sys.stderr)
1293 sys.exit(1)
1294
1295 if manifest_file is None:
1296 manifest_file = os.path.join(repodir, MANIFEST_FILE_NAME)
1297 local_manifests = os.path.abspath(os.path.join(repodir, LOCAL_MANIFESTS_DIR_NAME))
1298 super(RepoClient, self).__init__(repodir, manifest_file, local_manifests)
1299
1300 # TODO: Completely separate manifest logic out of the client.
1301 self.manifest = self
1302
1303
1304class GitcClient(RepoClient, GitcManifest):
1305 """Manages a GitC client checkout."""
1306
1307 def __init__(self, repodir, gitc_client_name):
1308 """Initialize the GitcManifest object."""
1309 self.gitc_client_name = gitc_client_name
1310 self.gitc_client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(),
1311 gitc_client_name)
1312
1313 super(GitcManifest, self).__init__(
1314 repodir, os.path.join(self.gitc_client_dir, '.manifest'))
1315 self.isGitcClient = True