blob: ad0017ccdc64a9a82ee562586ecbf0c11edd8f53 [file] [log] [blame]
Mike Frysingerf6013762019-06-13 02:30:51 -04001# -*- coding:utf-8 -*-
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07002#
3# Copyright (C) 2008 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Sarah Owenscecd1d82012-11-01 22:59:27 -070017from __future__ import print_function
Colin Cross23acdd32012-04-21 00:33:54 -070018import itertools
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070019import os
Conley Owensdb728cd2011-09-26 16:34:01 -070020import re
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070021import sys
David Pursehouse59bbb582013-05-17 10:49:33 +090022import xml.dom.minidom
23
24from pyversion import is_python3
25if is_python3():
Chirayu Desai217ea7d2013-03-01 19:14:38 +053026 import urllib.parse
David Pursehouse59bbb582013-05-17 10:49:33 +090027else:
Chirayu Desai217ea7d2013-03-01 19:14:38 +053028 import imp
29 import urlparse
30 urllib = imp.new_module('urllib')
Chirayu Desaidb2ad9d2013-06-11 13:42:25 +053031 urllib.parse = urlparse
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070032
Simran Basib9a1b732015-08-20 12:19:28 -070033import gitc_utils
Miguel Gaio1f207762020-07-17 14:09:13 +020034from git_config import GitConfig, IsId
David Pursehousee00aa6b2012-09-11 14:33:51 +090035from git_refs import R_HEADS, HEAD
Renaud Paquayd5cec5e2016-11-01 11:24:03 -070036import platform_utils
David Pursehousee00aa6b2012-09-11 14:33:51 +090037from project import RemoteSpec, Project, MetaProject
Mike Frysinger04122b72019-07-31 23:32:58 -040038from error import (ManifestParseError, ManifestInvalidPathError,
39 ManifestInvalidRevisionError)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070040
41MANIFEST_FILE_NAME = 'manifest.xml'
Shawn O. Pearce5cc66792008-10-23 16:19:27 -070042LOCAL_MANIFEST_NAME = 'local_manifest.xml'
David Pursehouse2d5a0df2012-11-13 02:50:36 +090043LOCAL_MANIFESTS_DIR_NAME = 'local_manifests'
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070044
Anthony Kingcb07ba72015-03-28 23:26:04 +000045# urljoin gets confused if the scheme is not known.
Joe Kilner6e310792016-10-27 15:53:53 -070046urllib.parse.uses_relative.extend([
47 'ssh',
48 'git',
49 'persistent-https',
50 'sso',
51 'rpc'])
52urllib.parse.uses_netloc.extend([
53 'ssh',
54 'git',
55 'persistent-https',
56 'sso',
57 'rpc'])
Conley Owensdb728cd2011-09-26 16:34:01 -070058
David Pursehouse819827a2020-02-12 15:20:19 +090059
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -050060def XmlBool(node, attr, default=None):
61 """Determine boolean value of |node|'s |attr|.
62
63 Invalid values will issue a non-fatal warning.
64
65 Args:
66 node: XML node whose attributes we access.
67 attr: The attribute to access.
68 default: If the attribute is not set (value is empty), then use this.
69
70 Returns:
71 True if the attribute is a valid string representing true.
72 False if the attribute is a valid string representing false.
73 |default| otherwise.
74 """
75 value = node.getAttribute(attr)
76 s = value.lower()
77 if s == '':
78 return default
79 elif s in {'yes', 'true', '1'}:
80 return True
81 elif s in {'no', 'false', '0'}:
82 return False
83 else:
84 print('warning: manifest: %s="%s": ignoring invalid XML boolean' %
85 (attr, value), file=sys.stderr)
86 return default
87
88
89def XmlInt(node, attr, default=None):
90 """Determine integer value of |node|'s |attr|.
91
92 Args:
93 node: XML node whose attributes we access.
94 attr: The attribute to access.
95 default: If the attribute is not set (value is empty), then use this.
96
97 Returns:
98 The number if the attribute is a valid number.
99
100 Raises:
101 ManifestParseError: The number is invalid.
102 """
103 value = node.getAttribute(attr)
104 if not value:
105 return default
106
107 try:
108 return int(value)
109 except ValueError:
110 raise ManifestParseError('manifest: invalid %s="%s" integer' %
111 (attr, value))
112
113
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700114class _Default(object):
115 """Project defaults within the manifest."""
116
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700117 revisionExpr = None
Conley Owensb6a16e62013-09-25 15:06:09 -0700118 destBranchExpr = None
Nasser Grainawida403412018-05-04 12:53:29 -0600119 upstreamExpr = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700120 remote = None
Shawn O. Pearce6392c872011-09-22 17:44:31 -0700121 sync_j = 1
Anatol Pomazau79770d22012-04-20 14:41:59 -0700122 sync_c = False
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800123 sync_s = False
YOUNG HO CHAa32c92c2018-02-14 16:57:31 +0900124 sync_tags = True
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700125
Julien Campergue74879922013-10-09 14:38:46 +0200126 def __eq__(self, other):
127 return self.__dict__ == other.__dict__
128
129 def __ne__(self, other):
130 return self.__dict__ != other.__dict__
131
David Pursehouse819827a2020-02-12 15:20:19 +0900132
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700133class _XmlRemote(object):
134 def __init__(self,
135 name,
Yestin Sunb292b982012-07-02 07:32:50 -0700136 alias=None,
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700137 fetch=None,
Steve Raed6480452016-08-10 15:00:00 -0700138 pushUrl=None,
Conley Owensdb728cd2011-09-26 16:34:01 -0700139 manifestUrl=None,
Anthony King36ea2fb2014-05-06 11:54:01 +0100140 review=None,
Jonathan Nieder93719792015-03-17 11:29:58 -0700141 revision=None):
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700142 self.name = name
143 self.fetchUrl = fetch
Steve Raed6480452016-08-10 15:00:00 -0700144 self.pushUrl = pushUrl
Conley Owensdb728cd2011-09-26 16:34:01 -0700145 self.manifestUrl = manifestUrl
Yestin Sunb292b982012-07-02 07:32:50 -0700146 self.remoteAlias = alias
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700147 self.reviewUrl = review
Anthony King36ea2fb2014-05-06 11:54:01 +0100148 self.revision = revision
Conley Owensceea3682011-10-20 10:45:47 -0700149 self.resolvedFetchUrl = self._resolveFetchUrl()
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700150
David Pursehouse717ece92012-11-13 08:49:16 +0900151 def __eq__(self, other):
152 return self.__dict__ == other.__dict__
153
154 def __ne__(self, other):
155 return self.__dict__ != other.__dict__
156
Conley Owensceea3682011-10-20 10:45:47 -0700157 def _resolveFetchUrl(self):
158 url = self.fetchUrl.rstrip('/')
Conley Owensdb728cd2011-09-26 16:34:01 -0700159 manifestUrl = self.manifestUrl.rstrip('/')
Conley Owens2d0f5082014-01-31 15:03:51 -0800160 # urljoin will gets confused over quite a few things. The ones we care
161 # about here are:
162 # * no scheme in the base url, like <hostname:port>
Anthony Kingcb07ba72015-03-28 23:26:04 +0000163 # We handle no scheme by replacing it with an obscure protocol, gopher
164 # and then replacing it with the original when we are done.
165
Conley Owensdb728cd2011-09-26 16:34:01 -0700166 if manifestUrl.find(':') != manifestUrl.find('/') - 1:
Conley Owens4ccad752015-04-29 10:45:37 -0700167 url = urllib.parse.urljoin('gopher://' + manifestUrl, url)
168 url = re.sub(r'^gopher://', '', url)
Anthony Kingcb07ba72015-03-28 23:26:04 +0000169 else:
170 url = urllib.parse.urljoin(manifestUrl, url)
Shawn Pearcea9f11b32013-01-02 15:40:48 -0800171 return url
Conley Owensceea3682011-10-20 10:45:47 -0700172
173 def ToRemoteSpec(self, projectName):
David Rileye0684ad2017-04-05 00:02:59 -0700174 fetchUrl = self.resolvedFetchUrl.rstrip('/')
175 url = fetchUrl + '/' + projectName
Yestin Sunb292b982012-07-02 07:32:50 -0700176 remoteName = self.name
Conley Owens1e7ab2a2013-10-08 17:26:57 -0700177 if self.remoteAlias:
David Pursehouse37128b62013-10-15 10:48:40 +0900178 remoteName = self.remoteAlias
Dan Willemsen96c2d652016-04-06 16:03:54 -0700179 return RemoteSpec(remoteName,
180 url=url,
Steve Raed6480452016-08-10 15:00:00 -0700181 pushUrl=self.pushUrl,
Dan Willemsen96c2d652016-04-06 16:03:54 -0700182 review=self.reviewUrl,
David Rileye0684ad2017-04-05 00:02:59 -0700183 orig_name=self.name,
184 fetchUrl=self.fetchUrl)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700185
David Pursehouse819827a2020-02-12 15:20:19 +0900186
Shawn O. Pearcec8a300f2009-05-18 13:19:57 -0700187class XmlManifest(object):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700188 """manages the repo configuration file"""
189
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400190 def __init__(self, repodir, manifest_file, local_manifests=None):
191 """Initialize.
192
193 Args:
194 repodir: Path to the .repo/ dir for holding all internal checkout state.
195 It must be in the top directory of the repo client checkout.
196 manifest_file: Full path to the manifest file to parse. This will usually
197 be |repodir|/|MANIFEST_FILE_NAME|.
198 local_manifests: Full path to the directory of local override manifests.
199 This will usually be |repodir|/|LOCAL_MANIFESTS_DIR_NAME|.
200 """
201 # TODO(vapier): Move this out of this class.
202 self.globalConfig = GitConfig.ForUser()
203
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700204 self.repodir = os.path.abspath(repodir)
205 self.topdir = os.path.dirname(self.repodir)
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400206 self.manifestFile = manifest_file
207 self.local_manifests = local_manifests
Basil Gelloc7453502018-05-25 20:23:52 +0300208 self._load_local_manifests = True
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700209
210 self.repoProject = MetaProject(self, 'repo',
David Pursehouseabdf7502020-02-12 14:58:39 +0900211 gitdir=os.path.join(repodir, 'repo/.git'),
212 worktree=os.path.join(repodir, 'repo'))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700213
Mike Frysinger979d5bd2020-02-09 02:28:34 -0500214 mp = MetaProject(self, 'manifests',
215 gitdir=os.path.join(repodir, 'manifests.git'),
216 worktree=os.path.join(repodir, 'manifests'))
217 self.manifestProject = mp
218
219 # This is a bit hacky, but we're in a chicken & egg situation: all the
220 # normal repo settings live in the manifestProject which we just setup
221 # above, so we couldn't easily query before that. We assume Project()
222 # init doesn't care if this changes afterwards.
Mike Frysingerd957ec62020-02-24 14:40:25 -0500223 if os.path.exists(mp.gitdir) and mp.config.GetBoolean('repo.worktree'):
Mike Frysinger979d5bd2020-02-09 02:28:34 -0500224 mp.use_git_worktrees = True
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700225
226 self._Unload()
227
Basil Gelloc7453502018-05-25 20:23:52 +0300228 def Override(self, name, load_local_manifests=True):
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700229 """Use a different manifest, just for the current instantiation.
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700230 """
Basil Gelloc7453502018-05-25 20:23:52 +0300231 path = None
232
233 # Look for a manifest by path in the filesystem (including the cwd).
234 if not load_local_manifests:
235 local_path = os.path.abspath(name)
236 if os.path.isfile(local_path):
237 path = local_path
238
239 # Look for manifests by name from the manifests repo.
240 if path is None:
241 path = os.path.join(self.manifestProject.worktree, name)
242 if not os.path.isfile(path):
243 raise ManifestParseError('manifest %s not found' % name)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700244
245 old = self.manifestFile
246 try:
Basil Gelloc7453502018-05-25 20:23:52 +0300247 self._load_local_manifests = load_local_manifests
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700248 self.manifestFile = path
249 self._Unload()
250 self._Load()
251 finally:
252 self.manifestFile = old
253
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700254 def Link(self, name):
255 """Update the repo metadata to use a different manifest.
256 """
257 self.Override(name)
258
Mike Frysingera269b1c2020-02-21 00:49:41 -0500259 # Old versions of repo would generate symlinks we need to clean up.
260 if os.path.lexists(self.manifestFile):
261 platform_utils.remove(self.manifestFile)
262 # This file is interpreted as if it existed inside the manifest repo.
263 # That allows us to use <include> with the relative file name.
264 with open(self.manifestFile, 'w') as fp:
265 fp.write("""<?xml version="1.0" encoding="UTF-8"?>
266<!--
267DO NOT EDIT THIS FILE! It is generated by repo and changes will be discarded.
268If you want to use a different manifest, use `repo init -m <file>` instead.
269
270If you want to customize your checkout by overriding manifest settings, use
271the local_manifests/ directory instead.
272
273For more information on repo manifests, check out:
274https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
275-->
276<manifest>
277 <include name="%s" />
278</manifest>
279""" % (name,))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700280
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800281 def _RemoteToXml(self, r, doc, root):
282 e = doc.createElement('remote')
283 root.appendChild(e)
284 e.setAttribute('name', r.name)
285 e.setAttribute('fetch', r.fetchUrl)
Steve Raed6480452016-08-10 15:00:00 -0700286 if r.pushUrl is not None:
287 e.setAttribute('pushurl', r.pushUrl)
Conley Owens1e7ab2a2013-10-08 17:26:57 -0700288 if r.remoteAlias is not None:
289 e.setAttribute('alias', r.remoteAlias)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800290 if r.reviewUrl is not None:
291 e.setAttribute('review', r.reviewUrl)
Anthony King36ea2fb2014-05-06 11:54:01 +0100292 if r.revision is not None:
293 e.setAttribute('revision', r.revision)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800294
Josh Triplett884a3872014-06-12 14:57:29 -0700295 def _ParseGroups(self, groups):
296 return [x for x in re.split(r'[,\s]+', groups) if x]
297
Mike Frysinger23411d32020-09-02 04:31:10 -0400298 def ToXml(self, peg_rev=False, peg_rev_upstream=True, peg_rev_dest_branch=True, groups=None):
299 """Return the current manifest XML."""
Colin Cross5acde752012-03-28 20:15:45 -0700300 mp = self.manifestProject
301
Dan Willemsen5ea32d12015-09-08 13:27:20 -0700302 if groups is None:
303 groups = mp.config.GetString('manifest.groups')
Matt Gumbel0c635bb2012-12-21 10:14:53 -0800304 if groups:
Josh Triplett884a3872014-06-12 14:57:29 -0700305 groups = self._ParseGroups(groups)
Colin Cross5acde752012-03-28 20:15:45 -0700306
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800307 doc = xml.dom.minidom.Document()
308 root = doc.createElement('manifest')
309 doc.appendChild(root)
310
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700311 # Save out the notice. There's a little bit of work here to give it the
312 # right whitespace, which assumes that the notice is automatically indented
313 # by 4 by minidom.
314 if self.notice:
315 notice_element = root.appendChild(doc.createElement('notice'))
316 notice_lines = self.notice.splitlines()
David Pursehouse54a4e602020-02-12 14:31:05 +0900317 indented_notice = ('\n'.join(" " * 4 + line for line in notice_lines))[4:]
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700318 notice_element.appendChild(doc.createTextNode(indented_notice))
319
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800320 d = self.default
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800321
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530322 for r in sorted(self.remotes):
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800323 self._RemoteToXml(self.remotes[r], doc, root)
324 if self.remotes:
325 root.appendChild(doc.createTextNode(''))
326
327 have_default = False
328 e = doc.createElement('default')
329 if d.remote:
330 have_default = True
331 e.setAttribute('remote', d.remote.name)
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700332 if d.revisionExpr:
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800333 have_default = True
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700334 e.setAttribute('revision', d.revisionExpr)
Simon Ruggier7e59de22015-07-24 12:50:06 +0200335 if d.destBranchExpr:
336 have_default = True
337 e.setAttribute('dest-branch', d.destBranchExpr)
Nasser Grainawida403412018-05-04 12:53:29 -0600338 if d.upstreamExpr:
339 have_default = True
340 e.setAttribute('upstream', d.upstreamExpr)
Shawn O. Pearce6392c872011-09-22 17:44:31 -0700341 if d.sync_j > 1:
342 have_default = True
343 e.setAttribute('sync-j', '%d' % d.sync_j)
Anatol Pomazau79770d22012-04-20 14:41:59 -0700344 if d.sync_c:
345 have_default = True
346 e.setAttribute('sync-c', 'true')
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800347 if d.sync_s:
348 have_default = True
349 e.setAttribute('sync-s', 'true')
YOUNG HO CHAa32c92c2018-02-14 16:57:31 +0900350 if not d.sync_tags:
351 have_default = True
352 e.setAttribute('sync-tags', 'false')
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800353 if have_default:
354 root.appendChild(e)
355 root.appendChild(doc.createTextNode(''))
356
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700357 if self._manifest_server:
358 e = doc.createElement('manifest-server')
359 e.setAttribute('url', self._manifest_server)
360 root.appendChild(e)
361 root.appendChild(doc.createTextNode(''))
362
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800363 def output_projects(parent, parent_node, projects):
David James8d201162013-10-11 17:03:19 -0700364 for project_name in projects:
365 for project in self._projects[project_name]:
366 output_project(parent, parent_node, project)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800367
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800368 def output_project(parent, parent_node, p):
Colin Cross5acde752012-03-28 20:15:45 -0700369 if not p.MatchesGroups(groups):
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800370 return
371
372 name = p.name
373 relpath = p.relpath
374 if parent:
375 name = self._UnjoinName(parent.name, name)
376 relpath = self._UnjoinRelpath(parent.relpath, relpath)
Colin Cross5acde752012-03-28 20:15:45 -0700377
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800378 e = doc.createElement('project')
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800379 parent_node.appendChild(e)
380 e.setAttribute('name', name)
381 if relpath != name:
382 e.setAttribute('path', relpath)
Conley Owensa17d7af2013-10-16 14:38:09 -0700383 remoteName = None
384 if d.remote:
Dan Willemsen96c2d652016-04-06 16:03:54 -0700385 remoteName = d.remote.name
386 if not d.remote or p.remote.orig_name != remoteName:
387 remoteName = p.remote.orig_name
Anthony King36ea2fb2014-05-06 11:54:01 +0100388 e.setAttribute('remote', remoteName)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800389 if peg_rev:
390 if self.IsMirror:
Brian Harring14a66742012-09-28 20:21:57 -0700391 value = p.bare_git.rev_parse(p.revisionExpr + '^0')
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800392 else:
Brian Harring14a66742012-09-28 20:21:57 -0700393 value = p.work_git.rev_parse(HEAD + '^0')
394 e.setAttribute('revision', value)
Conley Owens551dfec2015-07-10 14:54:54 -0700395 if peg_rev_upstream:
396 if p.upstream:
397 e.setAttribute('upstream', p.upstream)
398 elif value != p.revisionExpr:
399 # Only save the origin if the origin is not a sha1, and the default
400 # isn't our value
401 e.setAttribute('upstream', p.revisionExpr)
Sean McAllisteraf908cb2020-04-20 08:41:58 -0600402
403 if peg_rev_dest_branch:
404 if p.dest_branch:
405 e.setAttribute('dest-branch', p.dest_branch)
406 elif value != p.revisionExpr:
407 e.setAttribute('dest-branch', p.revisionExpr)
408
Anthony King36ea2fb2014-05-06 11:54:01 +0100409 else:
Dan Willemsen96c2d652016-04-06 16:03:54 -0700410 revision = self.remotes[p.remote.orig_name].revision or d.revisionExpr
Anthony King36ea2fb2014-05-06 11:54:01 +0100411 if not revision or revision != p.revisionExpr:
412 e.setAttribute('revision', p.revisionExpr)
Nasser Grainawida403412018-05-04 12:53:29 -0600413 if (p.upstream and (p.upstream != p.revisionExpr or
414 p.upstream != d.upstreamExpr)):
Mani Chandel7a91d512014-07-24 16:27:08 +0530415 e.setAttribute('upstream', p.upstream)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800416
Simon Ruggier7e59de22015-07-24 12:50:06 +0200417 if p.dest_branch and p.dest_branch != d.destBranchExpr:
418 e.setAttribute('dest-branch', p.dest_branch)
419
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800420 for c in p.copyfiles:
421 ce = doc.createElement('copyfile')
422 ce.setAttribute('src', c.src)
423 ce.setAttribute('dest', c.dest)
424 e.appendChild(ce)
425
Jeff Hamiltone0df2322014-04-21 17:10:59 -0500426 for l in p.linkfiles:
427 le = doc.createElement('linkfile')
428 le.setAttribute('src', l.src)
429 le.setAttribute('dest', l.dest)
430 e.appendChild(le)
431
Conley Owensbb1b5f52012-08-13 13:11:18 -0700432 default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath]
Dmitry Fink17f85ea2012-08-06 14:52:29 -0700433 egroups = [g for g in p.groups if g not in default_groups]
Conley Owens971de8e2012-04-16 10:36:08 -0700434 if egroups:
435 e.setAttribute('groups', ','.join(egroups))
Colin Cross5acde752012-03-28 20:15:45 -0700436
James W. Mills24c13082012-04-12 15:04:13 -0500437 for a in p.annotations:
438 if a.keep == "true":
439 ae = doc.createElement('annotation')
440 ae.setAttribute('name', a.name)
441 ae.setAttribute('value', a.value)
442 e.appendChild(ae)
443
Anatol Pomazau79770d22012-04-20 14:41:59 -0700444 if p.sync_c:
445 e.setAttribute('sync-c', 'true')
446
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800447 if p.sync_s:
448 e.setAttribute('sync-s', 'true')
449
YOUNG HO CHAa32c92c2018-02-14 16:57:31 +0900450 if not p.sync_tags:
451 e.setAttribute('sync-tags', 'false')
452
Dan Willemsen88409222015-08-17 15:29:10 -0700453 if p.clone_depth:
454 e.setAttribute('clone-depth', str(p.clone_depth))
455
Simran Basib9a1b732015-08-20 12:19:28 -0700456 self._output_manifest_project_extras(p, e)
457
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800458 if p.subprojects:
David James8d201162013-10-11 17:03:19 -0700459 subprojects = set(subp.name for subp in p.subprojects)
460 output_projects(p, e, list(sorted(subprojects)))
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800461
David James8d201162013-10-11 17:03:19 -0700462 projects = set(p.name for p in self._paths.values() if not p.parent)
463 output_projects(None, root, list(sorted(projects)))
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800464
Doug Anderson37282b42011-03-04 11:54:18 -0800465 if self._repo_hooks_project:
466 root.appendChild(doc.createTextNode(''))
467 e = doc.createElement('repo-hooks')
468 e.setAttribute('in-project', self._repo_hooks_project.name)
469 e.setAttribute('enabled-list',
470 ' '.join(self._repo_hooks_project.enabled_repo_hooks))
471 root.appendChild(e)
472
Mike Frysinger23411d32020-09-02 04:31:10 -0400473 return doc
474
475 def ToDict(self, **kwargs):
476 """Return the current manifest as a dictionary."""
477 # Elements that may only appear once.
478 SINGLE_ELEMENTS = {
479 'notice',
480 'default',
481 'manifest-server',
482 'repo-hooks',
483 }
484 # Elements that may be repeated.
485 MULTI_ELEMENTS = {
486 'remote',
487 'remove-project',
488 'project',
489 'extend-project',
490 'include',
491 # These are children of 'project' nodes.
492 'annotation',
493 'project',
494 'copyfile',
495 'linkfile',
496 }
497
498 doc = self.ToXml(**kwargs)
499 ret = {}
500
501 def append_children(ret, node):
502 for child in node.childNodes:
503 if child.nodeType == xml.dom.Node.ELEMENT_NODE:
504 attrs = child.attributes
505 element = dict((attrs.item(i).localName, attrs.item(i).value)
506 for i in range(attrs.length))
507 if child.nodeName in SINGLE_ELEMENTS:
508 ret[child.nodeName] = element
509 elif child.nodeName in MULTI_ELEMENTS:
510 ret.setdefault(child.nodeName, []).append(element)
511 else:
512 raise ManifestParseError('Unhandled element "%s"' % (child.nodeName,))
513
514 append_children(element, child)
515
516 append_children(ret, doc.firstChild)
517
518 return ret
519
520 def Save(self, fd, **kwargs):
521 """Write the current manifest out to the given file descriptor."""
522 doc = self.ToXml(**kwargs)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800523 doc.writexml(fd, '', ' ', '\n', 'UTF-8')
524
Simran Basib9a1b732015-08-20 12:19:28 -0700525 def _output_manifest_project_extras(self, p, e):
526 """Manifests can modify e if they support extra project attributes."""
527 pass
528
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700529 @property
David James8d201162013-10-11 17:03:19 -0700530 def paths(self):
531 self._Load()
532 return self._paths
533
534 @property
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700535 def projects(self):
536 self._Load()
Anthony Kingd58bfe52014-05-05 23:30:49 +0100537 return list(self._paths.values())
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700538
539 @property
540 def remotes(self):
541 self._Load()
542 return self._remotes
543
544 @property
545 def default(self):
546 self._Load()
547 return self._default
548
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800549 @property
Doug Anderson37282b42011-03-04 11:54:18 -0800550 def repo_hooks_project(self):
551 self._Load()
552 return self._repo_hooks_project
553
554 @property
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700555 def notice(self):
556 self._Load()
557 return self._notice
558
559 @property
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700560 def manifest_server(self):
561 self._Load()
Shawn O. Pearce34fb20f2011-11-30 13:41:02 -0800562 return self._manifest_server
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700563
564 @property
Xin Lid79a4bc2020-05-20 16:03:45 -0700565 def CloneBundle(self):
566 clone_bundle = self.manifestProject.config.GetBoolean('repo.clonebundle')
567 if clone_bundle is None:
568 return False if self.manifestProject.config.GetBoolean('repo.partialclone') else True
569 else:
570 return clone_bundle
571
572 @property
Xin Li745be2e2019-06-03 11:24:30 -0700573 def CloneFilter(self):
574 if self.manifestProject.config.GetBoolean('repo.partialclone'):
575 return self.manifestProject.config.GetString('repo.clonefilter')
576 return None
577
578 @property
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800579 def IsMirror(self):
580 return self.manifestProject.config.GetBoolean('repo.mirror')
581
Julien Campergue335f5ef2013-10-16 11:02:35 +0200582 @property
Mike Frysinger979d5bd2020-02-09 02:28:34 -0500583 def UseGitWorktrees(self):
584 return self.manifestProject.config.GetBoolean('repo.worktree')
585
586 @property
Julien Campergue335f5ef2013-10-16 11:02:35 +0200587 def IsArchive(self):
588 return self.manifestProject.config.GetBoolean('repo.archive')
589
Martin Kellye4e94d22017-03-21 16:05:12 -0700590 @property
591 def HasSubmodules(self):
592 return self.manifestProject.config.GetBoolean('repo.submodules')
593
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700594 def _Unload(self):
595 self._loaded = False
596 self._projects = {}
David James8d201162013-10-11 17:03:19 -0700597 self._paths = {}
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700598 self._remotes = {}
599 self._default = None
Doug Anderson37282b42011-03-04 11:54:18 -0800600 self._repo_hooks_project = None
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700601 self._notice = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700602 self.branch = None
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700603 self._manifest_server = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700604
605 def _Load(self):
606 if not self._loaded:
Shawn O. Pearce2450a292008-11-04 08:22:07 -0800607 m = self.manifestProject
608 b = m.GetBranch(m.CurrentBranch).merge
Shawn O. Pearce21c5c342009-06-25 16:47:30 -0700609 if b is not None and b.startswith(R_HEADS):
Shawn O. Pearce2450a292008-11-04 08:22:07 -0800610 b = b[len(R_HEADS):]
611 self.branch = b
612
Colin Cross23acdd32012-04-21 00:33:54 -0700613 nodes = []
Brian Harring475a47d2012-06-07 20:05:35 -0700614 nodes.append(self._ParseManifestXml(self.manifestFile,
615 self.manifestProject.worktree))
Shawn O. Pearce5cc66792008-10-23 16:19:27 -0700616
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400617 if self._load_local_manifests and self.local_manifests:
Basil Gelloc7453502018-05-25 20:23:52 +0300618 try:
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400619 for local_file in sorted(platform_utils.listdir(self.local_manifests)):
Basil Gelloc7453502018-05-25 20:23:52 +0300620 if local_file.endswith('.xml'):
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -0400621 local = os.path.join(self.local_manifests, local_file)
Basil Gelloc7453502018-05-25 20:23:52 +0300622 nodes.append(self._ParseManifestXml(local, self.repodir))
623 except OSError:
624 pass
David Pursehouse2d5a0df2012-11-13 02:50:36 +0900625
Joe Onorato26e24752013-01-11 12:35:53 -0800626 try:
627 self._ParseManifest(nodes)
628 except ManifestParseError as e:
629 # There was a problem parsing, unload ourselves in case they catch
630 # this error and try again later, we will show the correct error
631 self._Unload()
632 raise e
Shawn O. Pearce5cc66792008-10-23 16:19:27 -0700633
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800634 if self.IsMirror:
635 self._AddMetaProjectMirror(self.repoProject)
636 self._AddMetaProjectMirror(self.manifestProject)
637
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700638 self._loaded = True
639
Fredrik de Groot352c93b2020-10-06 12:55:14 +0200640 def _ParseManifestXml(self, path, include_root, parent_groups=''):
David Pursehousef7fc8a92012-11-13 04:00:28 +0900641 try:
642 root = xml.dom.minidom.parse(path)
David Pursehouse2d5a0df2012-11-13 02:50:36 +0900643 except (OSError, xml.parsers.expat.ExpatError) as e:
David Pursehousef7fc8a92012-11-13 04:00:28 +0900644 raise ManifestParseError("error parsing manifest %s: %s" % (path, e))
645
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700646 if not root or not root.childNodes:
Brian Harring26448742011-04-28 05:04:41 -0700647 raise ManifestParseError("no root node in %s" % (path,))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700648
Jooncheol Park34acdd22012-08-27 02:25:59 +0900649 for manifest in root.childNodes:
650 if manifest.nodeName == 'manifest':
651 break
652 else:
Brian Harring26448742011-04-28 05:04:41 -0700653 raise ManifestParseError("no <manifest> in %s" % (path,))
654
Colin Cross23acdd32012-04-21 00:33:54 -0700655 nodes = []
David Pursehouse65b0ba52018-06-24 16:21:51 +0900656 for node in manifest.childNodes:
David Pursehousec1b86a22012-11-14 11:36:51 +0900657 if node.nodeName == 'include':
658 name = self._reqatt(node, 'name')
Fredrik de Groot352c93b2020-10-06 12:55:14 +0200659 include_groups = ''
660 if parent_groups:
661 include_groups = parent_groups
662 if node.hasAttribute('groups'):
663 include_groups = node.getAttribute('groups') + ',' + include_groups
David Pursehousec1b86a22012-11-14 11:36:51 +0900664 fp = os.path.join(include_root, name)
665 if not os.path.isfile(fp):
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530666 raise ManifestParseError("include %s doesn't exist or isn't a file"
David Pursehouseabdf7502020-02-12 14:58:39 +0900667 % (name,))
David Pursehousec1b86a22012-11-14 11:36:51 +0900668 try:
Fredrik de Groot352c93b2020-10-06 12:55:14 +0200669 nodes.extend(self._ParseManifestXml(fp, include_root, include_groups))
David Pursehousec1b86a22012-11-14 11:36:51 +0900670 # should isolate this to the exact exception, but that's
671 # tricky. actual parsing implementation may vary.
672 except (KeyboardInterrupt, RuntimeError, SystemExit):
673 raise
674 except Exception as e:
675 raise ManifestParseError(
Mike Frysingerec558df2019-07-05 01:38:05 -0400676 "failed parsing included manifest %s: %s" % (name, e))
David Pursehousec1b86a22012-11-14 11:36:51 +0900677 else:
Fredrik de Groot352c93b2020-10-06 12:55:14 +0200678 if parent_groups and node.nodeName == 'project':
679 nodeGroups = parent_groups
680 if node.hasAttribute('groups'):
681 nodeGroups = node.getAttribute('groups') + ',' + nodeGroups
682 node.setAttribute('groups', nodeGroups)
David Pursehousec1b86a22012-11-14 11:36:51 +0900683 nodes.append(node)
Colin Cross23acdd32012-04-21 00:33:54 -0700684 return nodes
Brian Harring26448742011-04-28 05:04:41 -0700685
Colin Cross23acdd32012-04-21 00:33:54 -0700686 def _ParseManifest(self, node_list):
687 for node in itertools.chain(*node_list):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700688 if node.nodeName == 'remote':
689 remote = self._ParseRemote(node)
David Pursehouse717ece92012-11-13 08:49:16 +0900690 if remote:
691 if remote.name in self._remotes:
692 if remote != self._remotes[remote.name]:
693 raise ManifestParseError(
694 'remote %s already exists with different attributes' %
695 (remote.name))
696 else:
697 self._remotes[remote.name] = remote
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700698
Colin Cross23acdd32012-04-21 00:33:54 -0700699 for node in itertools.chain(*node_list):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700700 if node.nodeName == 'default':
Julien Campergue74879922013-10-09 14:38:46 +0200701 new_default = self._ParseDefault(node)
702 if self._default is None:
703 self._default = new_default
704 elif new_default != self._default:
David Pursehouse37128b62013-10-15 10:48:40 +0900705 raise ManifestParseError('duplicate default in %s' %
706 (self.manifestFile))
Julien Campergue74879922013-10-09 14:38:46 +0200707
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700708 if self._default is None:
709 self._default = _Default()
710
Colin Cross23acdd32012-04-21 00:33:54 -0700711 for node in itertools.chain(*node_list):
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700712 if node.nodeName == 'notice':
713 if self._notice is not None:
Doug Anderson37282b42011-03-04 11:54:18 -0800714 raise ManifestParseError(
715 'duplicate notice in %s' %
716 (self.manifestFile))
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700717 self._notice = self._ParseNotice(node)
718
Colin Cross23acdd32012-04-21 00:33:54 -0700719 for node in itertools.chain(*node_list):
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700720 if node.nodeName == 'manifest-server':
721 url = self._reqatt(node, 'url')
722 if self._manifest_server is not None:
David Pursehousec1b86a22012-11-14 11:36:51 +0900723 raise ManifestParseError(
724 'duplicate manifest-server in %s' %
725 (self.manifestFile))
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700726 self._manifest_server = url
727
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800728 def recursively_add_projects(project):
David James8d201162013-10-11 17:03:19 -0700729 projects = self._projects.setdefault(project.name, [])
730 if project.relpath is None:
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800731 raise ManifestParseError(
David James8d201162013-10-11 17:03:19 -0700732 'missing path for %s in %s' %
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800733 (project.name, self.manifestFile))
David James8d201162013-10-11 17:03:19 -0700734 if project.relpath in self._paths:
735 raise ManifestParseError(
736 'duplicate path %s in %s' %
737 (project.relpath, self.manifestFile))
738 self._paths[project.relpath] = project
739 projects.append(project)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800740 for subproject in project.subprojects:
741 recursively_add_projects(subproject)
742
Colin Cross23acdd32012-04-21 00:33:54 -0700743 for node in itertools.chain(*node_list):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700744 if node.nodeName == 'project':
745 project = self._ParseProject(node)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800746 recursively_add_projects(project)
Josh Triplett884a3872014-06-12 14:57:29 -0700747 if node.nodeName == 'extend-project':
748 name = self._reqatt(node, 'name')
749
750 if name not in self._projects:
751 raise ManifestParseError('extend-project element specifies non-existent '
752 'project: %s' % name)
753
754 path = node.getAttribute('path')
755 groups = node.getAttribute('groups')
756 if groups:
757 groups = self._ParseGroups(groups)
Luis Hector Chavez7d525852018-03-15 09:54:08 -0700758 revision = node.getAttribute('revision')
Kyunam Jobd0aae92020-02-04 11:38:53 +0900759 remote = node.getAttribute('remote')
760 if remote:
761 remote = self._get_remote(node)
Josh Triplett884a3872014-06-12 14:57:29 -0700762
763 for p in self._projects[name]:
764 if path and p.relpath != path:
765 continue
766 if groups:
767 p.groups.extend(groups)
Luis Hector Chavez7d525852018-03-15 09:54:08 -0700768 if revision:
769 p.revisionExpr = revision
Miguel Gaio1f207762020-07-17 14:09:13 +0200770 if IsId(revision):
771 p.revisionId = revision
772 else:
773 p.revisionId = None
Kyunam Jobd0aae92020-02-04 11:38:53 +0900774 if remote:
775 p.remote = remote.ToRemoteSpec(name)
Doug Anderson37282b42011-03-04 11:54:18 -0800776 if node.nodeName == 'repo-hooks':
777 # Get the name of the project and the (space-separated) list of enabled.
778 repo_hooks_project = self._reqatt(node, 'in-project')
779 enabled_repo_hooks = self._reqatt(node, 'enabled-list').split()
780
781 # Only one project can be the hooks project
782 if self._repo_hooks_project is not None:
783 raise ManifestParseError(
784 'duplicate repo-hooks in %s' %
785 (self.manifestFile))
786
787 # Store a reference to the Project.
788 try:
David James8d201162013-10-11 17:03:19 -0700789 repo_hooks_projects = self._projects[repo_hooks_project]
Doug Anderson37282b42011-03-04 11:54:18 -0800790 except KeyError:
791 raise ManifestParseError(
792 'project %s not found for repo-hooks' %
793 (repo_hooks_project))
794
David James8d201162013-10-11 17:03:19 -0700795 if len(repo_hooks_projects) != 1:
796 raise ManifestParseError(
797 'internal error parsing repo-hooks in %s' %
798 (self.manifestFile))
799 self._repo_hooks_project = repo_hooks_projects[0]
800
Doug Anderson37282b42011-03-04 11:54:18 -0800801 # Store the enabled hooks in the Project object.
802 self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks
Colin Cross23acdd32012-04-21 00:33:54 -0700803 if node.nodeName == 'remove-project':
804 name = self._reqatt(node, 'name')
David Jamesb8433df2014-01-30 10:11:17 -0800805
806 if name not in self._projects:
David Pursehousef9107482012-11-16 19:12:32 +0900807 raise ManifestParseError('remove-project element specifies non-existent '
808 'project: %s' % name)
Colin Cross23acdd32012-04-21 00:33:54 -0700809
David Jamesb8433df2014-01-30 10:11:17 -0800810 for p in self._projects[name]:
811 del self._paths[p.relpath]
812 del self._projects[name]
813
Colin Cross23acdd32012-04-21 00:33:54 -0700814 # If the manifest removes the hooks project, treat it as if it deleted
815 # the repo-hooks element too.
816 if self._repo_hooks_project and (self._repo_hooks_project.name == name):
817 self._repo_hooks_project = None
818
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800819 def _AddMetaProjectMirror(self, m):
820 name = None
821 m_url = m.GetRemote(m.remote.name).url
822 if m_url.endswith('/.git'):
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530823 raise ManifestParseError('refusing to mirror %s' % m_url)
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800824
825 if self._default and self._default.remote:
Conley Owensceea3682011-10-20 10:45:47 -0700826 url = self._default.remote.resolvedFetchUrl
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800827 if not url.endswith('/'):
828 url += '/'
829 if m_url.startswith(url):
830 remote = self._default.remote
831 name = m_url[len(url):]
832
833 if name is None:
834 s = m_url.rindex('/') + 1
Conley Owensdb728cd2011-09-26 16:34:01 -0700835 manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
Shawn O. Pearcef35b2d92012-08-02 11:46:22 -0700836 remote = _XmlRemote('origin', fetch=m_url[:s], manifestUrl=manifestUrl)
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800837 name = m_url[s:]
838
839 if name.endswith('.git'):
840 name = name[:-4]
841
842 if name not in self._projects:
843 m.PreSync()
844 gitdir = os.path.join(self.topdir, '%s.git' % name)
David Pursehousee5913ae2020-02-12 13:56:59 +0900845 project = Project(manifest=self,
846 name=name,
847 remote=remote.ToRemoteSpec(name),
848 gitdir=gitdir,
849 objdir=gitdir,
850 worktree=None,
851 relpath=name or None,
852 revisionExpr=m.revisionExpr,
853 revisionId=None)
David James8d201162013-10-11 17:03:19 -0700854 self._projects[project.name] = [project]
Kwanhong Leeccd218c2014-02-17 13:07:32 +0900855 self._paths[project.relpath] = project
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800856
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700857 def _ParseRemote(self, node):
858 """
859 reads a <remote> element from the manifest file
860 """
861 name = self._reqatt(node, 'name')
Yestin Sunb292b982012-07-02 07:32:50 -0700862 alias = node.getAttribute('alias')
863 if alias == '':
864 alias = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700865 fetch = self._reqatt(node, 'fetch')
Steve Raed6480452016-08-10 15:00:00 -0700866 pushUrl = node.getAttribute('pushurl')
867 if pushUrl == '':
868 pushUrl = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700869 review = node.getAttribute('review')
Shawn O. Pearceae6e0942008-11-06 10:25:35 -0800870 if review == '':
871 review = None
Anthony King36ea2fb2014-05-06 11:54:01 +0100872 revision = node.getAttribute('revision')
873 if revision == '':
874 revision = None
Conley Owensdb728cd2011-09-26 16:34:01 -0700875 manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
Steve Raed6480452016-08-10 15:00:00 -0700876 return _XmlRemote(name, alias, fetch, pushUrl, manifestUrl, review, revision)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700877
878 def _ParseDefault(self, node):
879 """
880 reads a <default> element from the manifest file
881 """
882 d = _Default()
883 d.remote = self._get_remote(node)
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700884 d.revisionExpr = node.getAttribute('revision')
885 if d.revisionExpr == '':
886 d.revisionExpr = None
Anatol Pomazau79770d22012-04-20 14:41:59 -0700887
Bryan Jacobsf609f912013-05-06 13:36:24 -0400888 d.destBranchExpr = node.getAttribute('dest-branch') or None
Nasser Grainawida403412018-05-04 12:53:29 -0600889 d.upstreamExpr = node.getAttribute('upstream') or None
Bryan Jacobsf609f912013-05-06 13:36:24 -0400890
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500891 d.sync_j = XmlInt(node, 'sync-j', 1)
892 if d.sync_j <= 0:
893 raise ManifestParseError('%s: sync-j must be greater than 0, not "%s"' %
894 (self.manifestFile, d.sync_j))
Anatol Pomazau79770d22012-04-20 14:41:59 -0700895
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500896 d.sync_c = XmlBool(node, 'sync-c', False)
897 d.sync_s = XmlBool(node, 'sync-s', False)
898 d.sync_tags = XmlBool(node, 'sync-tags', True)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700899 return d
900
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700901 def _ParseNotice(self, node):
902 """
903 reads a <notice> element from the manifest file
904
905 The <notice> element is distinct from other tags in the XML in that the
906 data is conveyed between the start and end tag (it's not an empty-element
907 tag).
908
909 The white space (carriage returns, indentation) for the notice element is
910 relevant and is parsed in a way that is based on how python docstrings work.
911 In fact, the code is remarkably similar to here:
912 http://www.python.org/dev/peps/pep-0257/
913 """
914 # Get the data out of the node...
915 notice = node.childNodes[0].data
916
917 # Figure out minimum indentation, skipping the first line (the same line
918 # as the <notice> tag)...
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530919 minIndent = sys.maxsize
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700920 lines = notice.splitlines()
921 for line in lines[1:]:
922 lstrippedLine = line.lstrip()
923 if lstrippedLine:
924 indent = len(line) - len(lstrippedLine)
925 minIndent = min(indent, minIndent)
926
927 # Strip leading / trailing blank lines and also indentation.
928 cleanLines = [lines[0].strip()]
929 for line in lines[1:]:
930 cleanLines.append(line[minIndent:].rstrip())
931
932 # Clear completely blank lines from front and back...
933 while cleanLines and not cleanLines[0]:
934 del cleanLines[0]
935 while cleanLines and not cleanLines[-1]:
936 del cleanLines[-1]
937
938 return '\n'.join(cleanLines)
939
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800940 def _JoinName(self, parent_name, name):
941 return os.path.join(parent_name, name)
942
943 def _UnjoinName(self, parent_name, name):
944 return os.path.relpath(name, parent_name)
945
David Pursehousee5913ae2020-02-12 13:56:59 +0900946 def _ParseProject(self, node, parent=None, **extra_proj_attrs):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700947 """
948 reads a <project> element from the manifest file
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700949 """
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700950 name = self._reqatt(node, 'name')
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800951 if parent:
952 name = self._JoinName(parent.name, name)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700953
954 remote = self._get_remote(node)
955 if remote is None:
956 remote = self._default.remote
957 if remote is None:
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530958 raise ManifestParseError("no remote for project %s within %s" %
David Pursehouseabdf7502020-02-12 14:58:39 +0900959 (name, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700960
Anthony King36ea2fb2014-05-06 11:54:01 +0100961 revisionExpr = node.getAttribute('revision') or remote.revision
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700962 if not revisionExpr:
963 revisionExpr = self._default.revisionExpr
964 if not revisionExpr:
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530965 raise ManifestParseError("no revision for project %s within %s" %
David Pursehouseabdf7502020-02-12 14:58:39 +0900966 (name, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700967
968 path = node.getAttribute('path')
969 if not path:
970 path = name
971 if path.startswith('/'):
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530972 raise ManifestParseError("project %s path cannot be absolute in %s" %
David Pursehouseabdf7502020-02-12 14:58:39 +0900973 (name, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700974
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500975 rebase = XmlBool(node, 'rebase', True)
976 sync_c = XmlBool(node, 'sync-c', False)
977 sync_s = XmlBool(node, 'sync-s', self._default.sync_s)
978 sync_tags = XmlBool(node, 'sync-tags', self._default.sync_tags)
Mike Pontillod3153822012-02-28 11:53:24 -0800979
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -0500980 clone_depth = XmlInt(node, 'clone-depth')
981 if clone_depth is not None and clone_depth <= 0:
982 raise ManifestParseError('%s: clone-depth must be greater than 0, not "%s"' %
983 (self.manifestFile, clone_depth))
David Pursehouseede7f122012-11-27 22:25:30 +0900984
Bryan Jacobsf609f912013-05-06 13:36:24 -0400985 dest_branch = node.getAttribute('dest-branch') or self._default.destBranchExpr
986
Nasser Grainawida403412018-05-04 12:53:29 -0600987 upstream = node.getAttribute('upstream') or self._default.upstreamExpr
Brian Harring14a66742012-09-28 20:21:57 -0700988
Conley Owens971de8e2012-04-16 10:36:08 -0700989 groups = ''
990 if node.hasAttribute('groups'):
991 groups = node.getAttribute('groups')
Josh Triplett884a3872014-06-12 14:57:29 -0700992 groups = self._ParseGroups(groups)
Brian Harring7da13142012-06-15 02:24:20 -0700993
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800994 if parent is None:
Mike Frysinger979d5bd2020-02-09 02:28:34 -0500995 relpath, worktree, gitdir, objdir, use_git_worktrees = \
996 self.GetProjectPaths(name, path)
Shawn O. Pearcecd81dd62012-10-26 12:18:00 -0700997 else:
Mike Frysinger979d5bd2020-02-09 02:28:34 -0500998 use_git_worktrees = False
David James8d201162013-10-11 17:03:19 -0700999 relpath, worktree, gitdir, objdir = \
1000 self.GetSubprojectPaths(parent, name, path)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001001
1002 default_groups = ['all', 'name:%s' % name, 'path:%s' % relpath]
1003 groups.extend(set(default_groups).difference(groups))
Shawn O. Pearcecd81dd62012-10-26 12:18:00 -07001004
Scott Fandb83b1b2013-02-28 09:34:14 +08001005 if self.IsMirror and node.hasAttribute('force-path'):
Mike Frysingerbb8ee7f2020-02-22 05:30:12 -05001006 if XmlBool(node, 'force-path', False):
Scott Fandb83b1b2013-02-28 09:34:14 +08001007 gitdir = os.path.join(self.topdir, '%s.git' % path)
1008
David Pursehousee5913ae2020-02-12 13:56:59 +09001009 project = Project(manifest=self,
1010 name=name,
1011 remote=remote.ToRemoteSpec(name),
1012 gitdir=gitdir,
1013 objdir=objdir,
1014 worktree=worktree,
1015 relpath=relpath,
1016 revisionExpr=revisionExpr,
1017 revisionId=None,
1018 rebase=rebase,
1019 groups=groups,
1020 sync_c=sync_c,
1021 sync_s=sync_s,
1022 sync_tags=sync_tags,
1023 clone_depth=clone_depth,
1024 upstream=upstream,
1025 parent=parent,
1026 dest_branch=dest_branch,
Mike Frysinger979d5bd2020-02-09 02:28:34 -05001027 use_git_worktrees=use_git_worktrees,
Simran Basib9a1b732015-08-20 12:19:28 -07001028 **extra_proj_attrs)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001029
1030 for n in node.childNodes:
Shawn O. Pearce242b5262009-05-19 13:00:29 -07001031 if n.nodeName == 'copyfile':
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001032 self._ParseCopyFile(project, n)
Jeff Hamiltone0df2322014-04-21 17:10:59 -05001033 if n.nodeName == 'linkfile':
1034 self._ParseLinkFile(project, n)
James W. Mills24c13082012-04-12 15:04:13 -05001035 if n.nodeName == 'annotation':
1036 self._ParseAnnotation(project, n)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001037 if n.nodeName == 'project':
David Pursehousee5913ae2020-02-12 13:56:59 +09001038 project.subprojects.append(self._ParseProject(n, parent=project))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001039
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001040 return project
1041
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001042 def GetProjectPaths(self, name, path):
Mike Frysingercebf2272020-05-26 01:02:29 -04001043 # The manifest entries might have trailing slashes. Normalize them to avoid
1044 # unexpected filesystem behavior since we do string concatenation below.
1045 path = path.rstrip('/')
1046 name = name.rstrip('/')
Mike Frysinger979d5bd2020-02-09 02:28:34 -05001047 use_git_worktrees = False
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001048 relpath = path
1049 if self.IsMirror:
1050 worktree = None
1051 gitdir = os.path.join(self.topdir, '%s.git' % name)
David James8d201162013-10-11 17:03:19 -07001052 objdir = gitdir
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001053 else:
1054 worktree = os.path.join(self.topdir, path).replace('\\', '/')
1055 gitdir = os.path.join(self.repodir, 'projects', '%s.git' % path)
Mike Frysinger979d5bd2020-02-09 02:28:34 -05001056 # We allow people to mix git worktrees & non-git worktrees for now.
1057 # This allows for in situ migration of repo clients.
1058 if os.path.exists(gitdir) or not self.UseGitWorktrees:
1059 objdir = os.path.join(self.repodir, 'project-objects', '%s.git' % name)
1060 else:
1061 use_git_worktrees = True
1062 gitdir = os.path.join(self.repodir, 'worktrees', '%s.git' % name)
1063 objdir = gitdir
1064 return relpath, worktree, gitdir, objdir, use_git_worktrees
David James8d201162013-10-11 17:03:19 -07001065
1066 def GetProjectsWithName(self, name):
1067 return self._projects.get(name, [])
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001068
1069 def GetSubprojectName(self, parent, submodule_path):
1070 return os.path.join(parent.name, submodule_path)
1071
1072 def _JoinRelpath(self, parent_relpath, relpath):
1073 return os.path.join(parent_relpath, relpath)
1074
1075 def _UnjoinRelpath(self, parent_relpath, relpath):
1076 return os.path.relpath(relpath, parent_relpath)
1077
David James8d201162013-10-11 17:03:19 -07001078 def GetSubprojectPaths(self, parent, name, path):
Mike Frysingercebf2272020-05-26 01:02:29 -04001079 # The manifest entries might have trailing slashes. Normalize them to avoid
1080 # unexpected filesystem behavior since we do string concatenation below.
1081 path = path.rstrip('/')
1082 name = name.rstrip('/')
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001083 relpath = self._JoinRelpath(parent.relpath, path)
1084 gitdir = os.path.join(parent.gitdir, 'subprojects', '%s.git' % path)
David James8d201162013-10-11 17:03:19 -07001085 objdir = os.path.join(parent.gitdir, 'subproject-objects', '%s.git' % name)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001086 if self.IsMirror:
1087 worktree = None
1088 else:
1089 worktree = os.path.join(parent.worktree, path).replace('\\', '/')
David James8d201162013-10-11 17:03:19 -07001090 return relpath, worktree, gitdir, objdir
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +08001091
Mike Frysinger04122b72019-07-31 23:32:58 -04001092 @staticmethod
1093 def _CheckLocalPath(path, symlink=False):
1094 """Verify |path| is reasonable for use in <copyfile> & <linkfile>."""
1095 if '~' in path:
1096 return '~ not allowed (due to 8.3 filenames on Windows filesystems)'
1097
1098 # Some filesystems (like Apple's HFS+) try to normalize Unicode codepoints
1099 # which means there are alternative names for ".git". Reject paths with
1100 # these in it as there shouldn't be any reasonable need for them here.
1101 # The set of codepoints here was cribbed from jgit's implementation:
1102 # https://eclipse.googlesource.com/jgit/jgit/+/9110037e3e9461ff4dac22fee84ef3694ed57648/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java#884
1103 BAD_CODEPOINTS = {
1104 u'\u200C', # ZERO WIDTH NON-JOINER
1105 u'\u200D', # ZERO WIDTH JOINER
1106 u'\u200E', # LEFT-TO-RIGHT MARK
1107 u'\u200F', # RIGHT-TO-LEFT MARK
1108 u'\u202A', # LEFT-TO-RIGHT EMBEDDING
1109 u'\u202B', # RIGHT-TO-LEFT EMBEDDING
1110 u'\u202C', # POP DIRECTIONAL FORMATTING
1111 u'\u202D', # LEFT-TO-RIGHT OVERRIDE
1112 u'\u202E', # RIGHT-TO-LEFT OVERRIDE
1113 u'\u206A', # INHIBIT SYMMETRIC SWAPPING
1114 u'\u206B', # ACTIVATE SYMMETRIC SWAPPING
1115 u'\u206C', # INHIBIT ARABIC FORM SHAPING
1116 u'\u206D', # ACTIVATE ARABIC FORM SHAPING
1117 u'\u206E', # NATIONAL DIGIT SHAPES
1118 u'\u206F', # NOMINAL DIGIT SHAPES
1119 u'\uFEFF', # ZERO WIDTH NO-BREAK SPACE
1120 }
1121 if BAD_CODEPOINTS & set(path):
1122 # This message is more expansive than reality, but should be fine.
1123 return 'Unicode combining characters not allowed'
1124
1125 # Assume paths might be used on case-insensitive filesystems.
1126 path = path.lower()
1127
Mike Frysingerd9254592020-02-19 22:36:26 -05001128 # Split up the path by its components. We can't use os.path.sep exclusively
1129 # as some platforms (like Windows) will convert / to \ and that bypasses all
1130 # our constructed logic here. Especially since manifest authors only use
1131 # / in their paths.
1132 resep = re.compile(r'[/%s]' % re.escape(os.path.sep))
1133 parts = resep.split(path)
1134
Mike Frysingerae625412020-02-10 17:10:03 -05001135 # Some people use src="." to create stable links to projects. Lets allow
1136 # that but reject all other uses of "." to keep things simple.
Mike Frysingerae625412020-02-10 17:10:03 -05001137 if parts != ['.']:
1138 for part in set(parts):
1139 if part in {'.', '..', '.git'} or part.startswith('.repo'):
1140 return 'bad component: %s' % (part,)
Mike Frysinger04122b72019-07-31 23:32:58 -04001141
Mike Frysingerd9254592020-02-19 22:36:26 -05001142 if not symlink and resep.match(path[-1]):
Mike Frysinger04122b72019-07-31 23:32:58 -04001143 return 'dirs not allowed'
1144
Mike Frysingerd9254592020-02-19 22:36:26 -05001145 # NB: The two abspath checks here are to handle platforms with multiple
1146 # filesystem path styles (e.g. Windows).
Mike Frysinger04122b72019-07-31 23:32:58 -04001147 norm = os.path.normpath(path)
Mike Frysingerd9254592020-02-19 22:36:26 -05001148 if (norm == '..' or
1149 (len(norm) >= 3 and norm.startswith('..') and resep.match(norm[0])) or
1150 os.path.isabs(norm) or
1151 norm.startswith('/')):
Mike Frysinger04122b72019-07-31 23:32:58 -04001152 return 'path cannot be outside'
1153
1154 @classmethod
1155 def _ValidateFilePaths(cls, element, src, dest):
1156 """Verify |src| & |dest| are reasonable for <copyfile> & <linkfile>.
1157
1158 We verify the path independent of any filesystem state as we won't have a
1159 checkout available to compare to. i.e. This is for parsing validation
1160 purposes only.
1161
1162 We'll do full/live sanity checking before we do the actual filesystem
1163 modifications in _CopyFile/_LinkFile/etc...
1164 """
1165 # |dest| is the file we write to or symlink we create.
1166 # It is relative to the top of the repo client checkout.
1167 msg = cls._CheckLocalPath(dest)
1168 if msg:
1169 raise ManifestInvalidPathError(
1170 '<%s> invalid "dest": %s: %s' % (element, dest, msg))
1171
1172 # |src| is the file we read from or path we point to for symlinks.
1173 # It is relative to the top of the git project checkout.
1174 msg = cls._CheckLocalPath(src, symlink=element == 'linkfile')
1175 if msg:
1176 raise ManifestInvalidPathError(
1177 '<%s> invalid "src": %s: %s' % (element, src, msg))
1178
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001179 def _ParseCopyFile(self, project, node):
1180 src = self._reqatt(node, 'src')
1181 dest = self._reqatt(node, 'dest')
Shawn O. Pearcee284ad12008-11-04 07:37:10 -08001182 if not self.IsMirror:
1183 # src is project relative;
Mike Frysinger04122b72019-07-31 23:32:58 -04001184 # dest is relative to the top of the tree.
1185 # We only validate paths if we actually plan to process them.
1186 self._ValidateFilePaths('copyfile', src, dest)
Mike Frysingere6a202f2019-08-02 15:57:57 -04001187 project.AddCopyFile(src, dest, self.topdir)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001188
Jeff Hamiltone0df2322014-04-21 17:10:59 -05001189 def _ParseLinkFile(self, project, node):
1190 src = self._reqatt(node, 'src')
1191 dest = self._reqatt(node, 'dest')
1192 if not self.IsMirror:
1193 # src is project relative;
Mike Frysinger04122b72019-07-31 23:32:58 -04001194 # dest is relative to the top of the tree.
1195 # We only validate paths if we actually plan to process them.
1196 self._ValidateFilePaths('linkfile', src, dest)
Mike Frysingere6a202f2019-08-02 15:57:57 -04001197 project.AddLinkFile(src, dest, self.topdir)
Jeff Hamiltone0df2322014-04-21 17:10:59 -05001198
James W. Mills24c13082012-04-12 15:04:13 -05001199 def _ParseAnnotation(self, project, node):
1200 name = self._reqatt(node, 'name')
1201 value = self._reqatt(node, 'value')
1202 try:
1203 keep = self._reqatt(node, 'keep').lower()
1204 except ManifestParseError:
1205 keep = "true"
1206 if keep != "true" and keep != "false":
Chirayu Desai217ea7d2013-03-01 19:14:38 +05301207 raise ManifestParseError('optional "keep" attribute must be '
David Pursehouseabdf7502020-02-12 14:58:39 +09001208 '"true" or "false"')
James W. Mills24c13082012-04-12 15:04:13 -05001209 project.AddAnnotation(name, value, keep)
1210
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001211 def _get_remote(self, node):
1212 name = node.getAttribute('remote')
1213 if not name:
1214 return None
1215
1216 v = self._remotes.get(name)
1217 if not v:
Chirayu Desai217ea7d2013-03-01 19:14:38 +05301218 raise ManifestParseError("remote %s not defined in %s" %
David Pursehouseabdf7502020-02-12 14:58:39 +09001219 (name, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001220 return v
1221
1222 def _reqatt(self, node, attname):
1223 """
1224 reads a required attribute from the node.
1225 """
1226 v = node.getAttribute(attname)
1227 if not v:
Chirayu Desai217ea7d2013-03-01 19:14:38 +05301228 raise ManifestParseError("no %s in <%s> within %s" %
David Pursehouseabdf7502020-02-12 14:58:39 +09001229 (attname, node.nodeName, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001230 return v
Julien Camperguedd654222014-01-09 16:21:37 +01001231
1232 def projectsDiff(self, manifest):
1233 """return the projects differences between two manifests.
1234
1235 The diff will be from self to given manifest.
1236
1237 """
1238 fromProjects = self.paths
1239 toProjects = manifest.paths
1240
Anthony King7446c592014-05-06 09:19:39 +01001241 fromKeys = sorted(fromProjects.keys())
1242 toKeys = sorted(toProjects.keys())
Julien Camperguedd654222014-01-09 16:21:37 +01001243
1244 diff = {'added': [], 'removed': [], 'changed': [], 'unreachable': []}
1245
1246 for proj in fromKeys:
David Pursehouseeeff3532020-02-12 11:24:10 +09001247 if proj not in toKeys:
Julien Camperguedd654222014-01-09 16:21:37 +01001248 diff['removed'].append(fromProjects[proj])
1249 else:
1250 fromProj = fromProjects[proj]
1251 toProj = toProjects[proj]
1252 try:
1253 fromRevId = fromProj.GetCommitRevisionId()
1254 toRevId = toProj.GetCommitRevisionId()
1255 except ManifestInvalidRevisionError:
1256 diff['unreachable'].append((fromProj, toProj))
1257 else:
1258 if fromRevId != toRevId:
1259 diff['changed'].append((fromProj, toProj))
1260 toKeys.remove(proj)
1261
1262 for proj in toKeys:
1263 diff['added'].append(toProjects[proj])
1264
1265 return diff
Simran Basib9a1b732015-08-20 12:19:28 -07001266
1267
1268class GitcManifest(XmlManifest):
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04001269 """Parser for GitC (git-in-the-cloud) manifests."""
Simran Basib9a1b732015-08-20 12:19:28 -07001270
David Pursehousee5913ae2020-02-12 13:56:59 +09001271 def _ParseProject(self, node, parent=None):
Simran Basib9a1b732015-08-20 12:19:28 -07001272 """Override _ParseProject and add support for GITC specific attributes."""
1273 return super(GitcManifest, self)._ParseProject(
1274 node, parent=parent, old_revision=node.getAttribute('old-revision'))
1275
1276 def _output_manifest_project_extras(self, p, e):
1277 """Output GITC Specific Project attributes"""
1278 if p.old_revision:
Stefan Beller66851062016-06-17 16:40:08 -07001279 e.setAttribute('old-revision', str(p.old_revision))
Mike Frysinger8c1e9cb2020-09-06 14:53:18 -04001280
1281
1282class RepoClient(XmlManifest):
1283 """Manages a repo client checkout."""
1284
1285 def __init__(self, repodir, manifest_file=None):
1286 self.isGitcClient = False
1287
1288 if os.path.exists(os.path.join(repodir, LOCAL_MANIFEST_NAME)):
1289 print('error: %s is not supported; put local manifests in `%s` instead' %
1290 (LOCAL_MANIFEST_NAME, os.path.join(repodir, LOCAL_MANIFESTS_DIR_NAME)),
1291 file=sys.stderr)
1292 sys.exit(1)
1293
1294 if manifest_file is None:
1295 manifest_file = os.path.join(repodir, MANIFEST_FILE_NAME)
1296 local_manifests = os.path.abspath(os.path.join(repodir, LOCAL_MANIFESTS_DIR_NAME))
1297 super(RepoClient, self).__init__(repodir, manifest_file, local_manifests)
1298
1299 # TODO: Completely separate manifest logic out of the client.
1300 self.manifest = self
1301
1302
1303class GitcClient(RepoClient, GitcManifest):
1304 """Manages a GitC client checkout."""
1305
1306 def __init__(self, repodir, gitc_client_name):
1307 """Initialize the GitcManifest object."""
1308 self.gitc_client_name = gitc_client_name
1309 self.gitc_client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(),
1310 gitc_client_name)
1311
1312 super(GitcManifest, self).__init__(
1313 repodir, os.path.join(self.gitc_client_dir, '.manifest'))
1314 self.isGitcClient = True