blob: 647e89f9b1a864d16e700520502cd75baa44704f [file] [log] [blame]
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001#
2# Copyright (C) 2008 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
Sarah Owenscecd1d82012-11-01 22:59:27 -070016from __future__ import print_function
Colin Cross23acdd32012-04-21 00:33:54 -070017import itertools
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070018import os
Conley Owensdb728cd2011-09-26 16:34:01 -070019import re
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070020import sys
David Pursehouse59bbb582013-05-17 10:49:33 +090021import xml.dom.minidom
22
23from pyversion import is_python3
24if is_python3():
Chirayu Desai217ea7d2013-03-01 19:14:38 +053025 import urllib.parse
David Pursehouse59bbb582013-05-17 10:49:33 +090026else:
Chirayu Desai217ea7d2013-03-01 19:14:38 +053027 import imp
28 import urlparse
29 urllib = imp.new_module('urllib')
Chirayu Desaidb2ad9d2013-06-11 13:42:25 +053030 urllib.parse = urlparse
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070031
David Pursehousee15c65a2012-08-22 10:46:11 +090032from git_config import GitConfig
David Pursehousee00aa6b2012-09-11 14:33:51 +090033from git_refs import R_HEADS, HEAD
34from project import RemoteSpec, Project, MetaProject
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070035from error import ManifestParseError
36
37MANIFEST_FILE_NAME = 'manifest.xml'
Shawn O. Pearce5cc66792008-10-23 16:19:27 -070038LOCAL_MANIFEST_NAME = 'local_manifest.xml'
David Pursehouse2d5a0df2012-11-13 02:50:36 +090039LOCAL_MANIFESTS_DIR_NAME = 'local_manifests'
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070040
Chirayu Desai217ea7d2013-03-01 19:14:38 +053041urllib.parse.uses_relative.extend(['ssh', 'git'])
42urllib.parse.uses_netloc.extend(['ssh', 'git'])
Conley Owensdb728cd2011-09-26 16:34:01 -070043
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070044class _Default(object):
45 """Project defaults within the manifest."""
46
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -070047 revisionExpr = None
Conley Owensb6a16e62013-09-25 15:06:09 -070048 destBranchExpr = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070049 remote = None
Shawn O. Pearce6392c872011-09-22 17:44:31 -070050 sync_j = 1
Anatol Pomazau79770d22012-04-20 14:41:59 -070051 sync_c = False
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +080052 sync_s = False
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070053
Shawn O. Pearced1f70d92009-05-19 14:58:02 -070054class _XmlRemote(object):
55 def __init__(self,
56 name,
Yestin Sunb292b982012-07-02 07:32:50 -070057 alias=None,
Shawn O. Pearced1f70d92009-05-19 14:58:02 -070058 fetch=None,
Conley Owensdb728cd2011-09-26 16:34:01 -070059 manifestUrl=None,
Shawn O. Pearced1f70d92009-05-19 14:58:02 -070060 review=None):
61 self.name = name
62 self.fetchUrl = fetch
Conley Owensdb728cd2011-09-26 16:34:01 -070063 self.manifestUrl = manifestUrl
Yestin Sunb292b982012-07-02 07:32:50 -070064 self.remoteAlias = alias
Shawn O. Pearced1f70d92009-05-19 14:58:02 -070065 self.reviewUrl = review
Conley Owensceea3682011-10-20 10:45:47 -070066 self.resolvedFetchUrl = self._resolveFetchUrl()
Shawn O. Pearced1f70d92009-05-19 14:58:02 -070067
David Pursehouse717ece92012-11-13 08:49:16 +090068 def __eq__(self, other):
69 return self.__dict__ == other.__dict__
70
71 def __ne__(self, other):
72 return self.__dict__ != other.__dict__
73
Conley Owensceea3682011-10-20 10:45:47 -070074 def _resolveFetchUrl(self):
75 url = self.fetchUrl.rstrip('/')
Conley Owensdb728cd2011-09-26 16:34:01 -070076 manifestUrl = self.manifestUrl.rstrip('/')
Shawn Pearcea9f11b32013-01-02 15:40:48 -080077 p = manifestUrl.startswith('persistent-http')
78 if p:
79 manifestUrl = manifestUrl[len('persistent-'):]
80
Conley Owensdb728cd2011-09-26 16:34:01 -070081 # urljoin will get confused if there is no scheme in the base url
82 # ie, if manifestUrl is of the form <hostname:port>
83 if manifestUrl.find(':') != manifestUrl.find('/') - 1:
David Pursehousec1b86a22012-11-14 11:36:51 +090084 manifestUrl = 'gopher://' + manifestUrl
Chirayu Desai217ea7d2013-03-01 19:14:38 +053085 url = urllib.parse.urljoin(manifestUrl, url)
Shawn Pearcea9f11b32013-01-02 15:40:48 -080086 url = re.sub(r'^gopher://', '', url)
87 if p:
88 url = 'persistent-' + url
89 return url
Conley Owensceea3682011-10-20 10:45:47 -070090
91 def ToRemoteSpec(self, projectName):
Conley Owens9d8f9142011-10-20 14:36:35 -070092 url = self.resolvedFetchUrl.rstrip('/') + '/' + projectName
Yestin Sunb292b982012-07-02 07:32:50 -070093 remoteName = self.name
Conley Owens1e7ab2a2013-10-08 17:26:57 -070094 if self.remoteAlias:
95 remoteName = self.remoteAlias
Yestin Sunb292b982012-07-02 07:32:50 -070096 return RemoteSpec(remoteName, url, self.reviewUrl)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070097
Shawn O. Pearcec8a300f2009-05-18 13:19:57 -070098class XmlManifest(object):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070099 """manages the repo configuration file"""
100
101 def __init__(self, repodir):
102 self.repodir = os.path.abspath(repodir)
103 self.topdir = os.path.dirname(self.repodir)
104 self.manifestFile = os.path.join(self.repodir, MANIFEST_FILE_NAME)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700105 self.globalConfig = GitConfig.ForUser()
David Pursehouse4eb285c2013-02-14 16:28:44 +0900106 self.localManifestWarning = False
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700107
108 self.repoProject = MetaProject(self, 'repo',
109 gitdir = os.path.join(repodir, 'repo/.git'),
110 worktree = os.path.join(repodir, 'repo'))
111
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700112 self.manifestProject = MetaProject(self, 'manifests',
Shawn O. Pearcef5c25a62008-11-04 08:11:53 -0800113 gitdir = os.path.join(repodir, 'manifests.git'),
114 worktree = os.path.join(repodir, 'manifests'))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700115
116 self._Unload()
117
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700118 def Override(self, name):
119 """Use a different manifest, just for the current instantiation.
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700120 """
121 path = os.path.join(self.manifestProject.worktree, name)
122 if not os.path.isfile(path):
123 raise ManifestParseError('manifest %s not found' % name)
124
125 old = self.manifestFile
126 try:
127 self.manifestFile = path
128 self._Unload()
129 self._Load()
130 finally:
131 self.manifestFile = old
132
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700133 def Link(self, name):
134 """Update the repo metadata to use a different manifest.
135 """
136 self.Override(name)
137
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700138 try:
Sebastian Frias223bf962012-11-21 19:09:25 +0100139 if os.path.lexists(self.manifestFile):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700140 os.remove(self.manifestFile)
141 os.symlink('manifests/%s' % name, self.manifestFile)
Sebastian Frias223bf962012-11-21 19:09:25 +0100142 except OSError as e:
143 raise ManifestParseError('cannot link manifest %s: %s' % (name, str(e)))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700144
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800145 def _RemoteToXml(self, r, doc, root):
146 e = doc.createElement('remote')
147 root.appendChild(e)
148 e.setAttribute('name', r.name)
149 e.setAttribute('fetch', r.fetchUrl)
Conley Owens1e7ab2a2013-10-08 17:26:57 -0700150 if r.remoteAlias is not None:
151 e.setAttribute('alias', r.remoteAlias)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800152 if r.reviewUrl is not None:
153 e.setAttribute('review', r.reviewUrl)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800154
Brian Harring14a66742012-09-28 20:21:57 -0700155 def Save(self, fd, peg_rev=False, peg_rev_upstream=True):
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800156 """Write the current manifest out to the given file descriptor.
157 """
Colin Cross5acde752012-03-28 20:15:45 -0700158 mp = self.manifestProject
159
160 groups = mp.config.GetString('manifest.groups')
Matt Gumbel0c635bb2012-12-21 10:14:53 -0800161 if groups:
162 groups = [x for x in re.split(r'[,\s]+', groups) if x]
Colin Cross5acde752012-03-28 20:15:45 -0700163
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800164 doc = xml.dom.minidom.Document()
165 root = doc.createElement('manifest')
166 doc.appendChild(root)
167
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700168 # Save out the notice. There's a little bit of work here to give it the
169 # right whitespace, which assumes that the notice is automatically indented
170 # by 4 by minidom.
171 if self.notice:
172 notice_element = root.appendChild(doc.createElement('notice'))
173 notice_lines = self.notice.splitlines()
174 indented_notice = ('\n'.join(" "*4 + line for line in notice_lines))[4:]
175 notice_element.appendChild(doc.createTextNode(indented_notice))
176
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800177 d = self.default
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800178
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530179 for r in sorted(self.remotes):
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800180 self._RemoteToXml(self.remotes[r], doc, root)
181 if self.remotes:
182 root.appendChild(doc.createTextNode(''))
183
184 have_default = False
185 e = doc.createElement('default')
186 if d.remote:
187 have_default = True
188 e.setAttribute('remote', d.remote.name)
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700189 if d.revisionExpr:
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800190 have_default = True
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700191 e.setAttribute('revision', d.revisionExpr)
Shawn O. Pearce6392c872011-09-22 17:44:31 -0700192 if d.sync_j > 1:
193 have_default = True
194 e.setAttribute('sync-j', '%d' % d.sync_j)
Anatol Pomazau79770d22012-04-20 14:41:59 -0700195 if d.sync_c:
196 have_default = True
197 e.setAttribute('sync-c', 'true')
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800198 if d.sync_s:
199 have_default = True
200 e.setAttribute('sync-s', 'true')
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800201 if have_default:
202 root.appendChild(e)
203 root.appendChild(doc.createTextNode(''))
204
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700205 if self._manifest_server:
206 e = doc.createElement('manifest-server')
207 e.setAttribute('url', self._manifest_server)
208 root.appendChild(e)
209 root.appendChild(doc.createTextNode(''))
210
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800211 def output_projects(parent, parent_node, projects):
David James8d201162013-10-11 17:03:19 -0700212 for project_name in projects:
213 for project in self._projects[project_name]:
214 output_project(parent, parent_node, project)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800215
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800216 def output_project(parent, parent_node, p):
Colin Cross5acde752012-03-28 20:15:45 -0700217 if not p.MatchesGroups(groups):
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800218 return
219
220 name = p.name
221 relpath = p.relpath
222 if parent:
223 name = self._UnjoinName(parent.name, name)
224 relpath = self._UnjoinRelpath(parent.relpath, relpath)
Colin Cross5acde752012-03-28 20:15:45 -0700225
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800226 e = doc.createElement('project')
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800227 parent_node.appendChild(e)
228 e.setAttribute('name', name)
229 if relpath != name:
230 e.setAttribute('path', relpath)
Conley Owens1e7ab2a2013-10-08 17:26:57 -0700231 remoteName = d.remote.remoteAlias or d.remote.name
232 if not d.remote or p.remote.name != remoteName:
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800233 e.setAttribute('remote', p.remote.name)
234 if peg_rev:
235 if self.IsMirror:
Brian Harring14a66742012-09-28 20:21:57 -0700236 value = p.bare_git.rev_parse(p.revisionExpr + '^0')
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800237 else:
Brian Harring14a66742012-09-28 20:21:57 -0700238 value = p.work_git.rev_parse(HEAD + '^0')
239 e.setAttribute('revision', value)
240 if peg_rev_upstream and value != p.revisionExpr:
241 # Only save the origin if the origin is not a sha1, and the default
242 # isn't our value, and the if the default doesn't already have that
243 # covered.
244 e.setAttribute('upstream', p.revisionExpr)
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700245 elif not d.revisionExpr or p.revisionExpr != d.revisionExpr:
246 e.setAttribute('revision', p.revisionExpr)
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800247
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800248 for c in p.copyfiles:
249 ce = doc.createElement('copyfile')
250 ce.setAttribute('src', c.src)
251 ce.setAttribute('dest', c.dest)
252 e.appendChild(ce)
253
Conley Owensbb1b5f52012-08-13 13:11:18 -0700254 default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath]
Dmitry Fink17f85ea2012-08-06 14:52:29 -0700255 egroups = [g for g in p.groups if g not in default_groups]
Conley Owens971de8e2012-04-16 10:36:08 -0700256 if egroups:
257 e.setAttribute('groups', ','.join(egroups))
Colin Cross5acde752012-03-28 20:15:45 -0700258
James W. Mills24c13082012-04-12 15:04:13 -0500259 for a in p.annotations:
260 if a.keep == "true":
261 ae = doc.createElement('annotation')
262 ae.setAttribute('name', a.name)
263 ae.setAttribute('value', a.value)
264 e.appendChild(ae)
265
Anatol Pomazau79770d22012-04-20 14:41:59 -0700266 if p.sync_c:
267 e.setAttribute('sync-c', 'true')
268
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800269 if p.sync_s:
270 e.setAttribute('sync-s', 'true')
271
272 if p.subprojects:
David James8d201162013-10-11 17:03:19 -0700273 subprojects = set(subp.name for subp in p.subprojects)
274 output_projects(p, e, list(sorted(subprojects)))
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800275
David James8d201162013-10-11 17:03:19 -0700276 projects = set(p.name for p in self._paths.values() if not p.parent)
277 output_projects(None, root, list(sorted(projects)))
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800278
Doug Anderson37282b42011-03-04 11:54:18 -0800279 if self._repo_hooks_project:
280 root.appendChild(doc.createTextNode(''))
281 e = doc.createElement('repo-hooks')
282 e.setAttribute('in-project', self._repo_hooks_project.name)
283 e.setAttribute('enabled-list',
284 ' '.join(self._repo_hooks_project.enabled_repo_hooks))
285 root.appendChild(e)
286
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800287 doc.writexml(fd, '', ' ', '\n', 'UTF-8')
288
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700289 @property
David James8d201162013-10-11 17:03:19 -0700290 def paths(self):
291 self._Load()
292 return self._paths
293
294 @property
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700295 def projects(self):
296 self._Load()
David James8d201162013-10-11 17:03:19 -0700297 return self._paths.values()
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700298
299 @property
300 def remotes(self):
301 self._Load()
302 return self._remotes
303
304 @property
305 def default(self):
306 self._Load()
307 return self._default
308
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800309 @property
Doug Anderson37282b42011-03-04 11:54:18 -0800310 def repo_hooks_project(self):
311 self._Load()
312 return self._repo_hooks_project
313
314 @property
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700315 def notice(self):
316 self._Load()
317 return self._notice
318
319 @property
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700320 def manifest_server(self):
321 self._Load()
Shawn O. Pearce34fb20f2011-11-30 13:41:02 -0800322 return self._manifest_server
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700323
324 @property
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800325 def IsMirror(self):
326 return self.manifestProject.config.GetBoolean('repo.mirror')
327
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700328 def _Unload(self):
329 self._loaded = False
330 self._projects = {}
David James8d201162013-10-11 17:03:19 -0700331 self._paths = {}
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700332 self._remotes = {}
333 self._default = None
Doug Anderson37282b42011-03-04 11:54:18 -0800334 self._repo_hooks_project = None
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700335 self._notice = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700336 self.branch = None
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700337 self._manifest_server = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700338
339 def _Load(self):
340 if not self._loaded:
Shawn O. Pearce2450a292008-11-04 08:22:07 -0800341 m = self.manifestProject
342 b = m.GetBranch(m.CurrentBranch).merge
Shawn O. Pearce21c5c342009-06-25 16:47:30 -0700343 if b is not None and b.startswith(R_HEADS):
Shawn O. Pearce2450a292008-11-04 08:22:07 -0800344 b = b[len(R_HEADS):]
345 self.branch = b
346
Colin Cross23acdd32012-04-21 00:33:54 -0700347 nodes = []
Brian Harring475a47d2012-06-07 20:05:35 -0700348 nodes.append(self._ParseManifestXml(self.manifestFile,
349 self.manifestProject.worktree))
Shawn O. Pearce5cc66792008-10-23 16:19:27 -0700350
351 local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME)
352 if os.path.exists(local):
David Pursehouse4eb285c2013-02-14 16:28:44 +0900353 if not self.localManifestWarning:
354 self.localManifestWarning = True
355 print('warning: %s is deprecated; put local manifests in `%s` instead'
356 % (LOCAL_MANIFEST_NAME, os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME)),
357 file=sys.stderr)
Brian Harring475a47d2012-06-07 20:05:35 -0700358 nodes.append(self._ParseManifestXml(local, self.repodir))
Colin Cross23acdd32012-04-21 00:33:54 -0700359
David Pursehouse2d5a0df2012-11-13 02:50:36 +0900360 local_dir = os.path.abspath(os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME))
361 try:
David Pursehouse52f1e5d2012-11-14 04:53:24 +0900362 for local_file in sorted(os.listdir(local_dir)):
David Pursehouse2d5a0df2012-11-13 02:50:36 +0900363 if local_file.endswith('.xml'):
David Pursehouse5f434ed2012-11-22 13:48:10 +0900364 local = os.path.join(local_dir, local_file)
365 nodes.append(self._ParseManifestXml(local, self.repodir))
David Pursehouse2d5a0df2012-11-13 02:50:36 +0900366 except OSError:
367 pass
368
Joe Onorato26e24752013-01-11 12:35:53 -0800369 try:
370 self._ParseManifest(nodes)
371 except ManifestParseError as e:
372 # There was a problem parsing, unload ourselves in case they catch
373 # this error and try again later, we will show the correct error
374 self._Unload()
375 raise e
Shawn O. Pearce5cc66792008-10-23 16:19:27 -0700376
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800377 if self.IsMirror:
378 self._AddMetaProjectMirror(self.repoProject)
379 self._AddMetaProjectMirror(self.manifestProject)
380
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700381 self._loaded = True
382
Brian Harring475a47d2012-06-07 20:05:35 -0700383 def _ParseManifestXml(self, path, include_root):
David Pursehousef7fc8a92012-11-13 04:00:28 +0900384 try:
385 root = xml.dom.minidom.parse(path)
David Pursehouse2d5a0df2012-11-13 02:50:36 +0900386 except (OSError, xml.parsers.expat.ExpatError) as e:
David Pursehousef7fc8a92012-11-13 04:00:28 +0900387 raise ManifestParseError("error parsing manifest %s: %s" % (path, e))
388
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700389 if not root or not root.childNodes:
Brian Harring26448742011-04-28 05:04:41 -0700390 raise ManifestParseError("no root node in %s" % (path,))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700391
Jooncheol Park34acdd22012-08-27 02:25:59 +0900392 for manifest in root.childNodes:
393 if manifest.nodeName == 'manifest':
394 break
395 else:
Brian Harring26448742011-04-28 05:04:41 -0700396 raise ManifestParseError("no <manifest> in %s" % (path,))
397
Colin Cross23acdd32012-04-21 00:33:54 -0700398 nodes = []
David Pursehouse4f7bdea2012-10-22 12:50:15 +0900399 for node in manifest.childNodes: # pylint:disable=W0631
David Pursehouse5c6eeac2012-10-11 16:44:48 +0900400 # We only get here if manifest is initialised
David Pursehousec1b86a22012-11-14 11:36:51 +0900401 if node.nodeName == 'include':
402 name = self._reqatt(node, 'name')
403 fp = os.path.join(include_root, name)
404 if not os.path.isfile(fp):
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530405 raise ManifestParseError("include %s doesn't exist or isn't a file"
406 % (name,))
David Pursehousec1b86a22012-11-14 11:36:51 +0900407 try:
408 nodes.extend(self._ParseManifestXml(fp, include_root))
409 # should isolate this to the exact exception, but that's
410 # tricky. actual parsing implementation may vary.
411 except (KeyboardInterrupt, RuntimeError, SystemExit):
412 raise
413 except Exception as e:
414 raise ManifestParseError(
415 "failed parsing included manifest %s: %s", (name, e))
416 else:
417 nodes.append(node)
Colin Cross23acdd32012-04-21 00:33:54 -0700418 return nodes
Brian Harring26448742011-04-28 05:04:41 -0700419
Colin Cross23acdd32012-04-21 00:33:54 -0700420 def _ParseManifest(self, node_list):
421 for node in itertools.chain(*node_list):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700422 if node.nodeName == 'remote':
423 remote = self._ParseRemote(node)
David Pursehouse717ece92012-11-13 08:49:16 +0900424 if remote:
425 if remote.name in self._remotes:
426 if remote != self._remotes[remote.name]:
427 raise ManifestParseError(
428 'remote %s already exists with different attributes' %
429 (remote.name))
430 else:
431 self._remotes[remote.name] = remote
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700432
Colin Cross23acdd32012-04-21 00:33:54 -0700433 for node in itertools.chain(*node_list):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700434 if node.nodeName == 'default':
435 if self._default is not None:
Doug Anderson37282b42011-03-04 11:54:18 -0800436 raise ManifestParseError(
437 'duplicate default in %s' %
438 (self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700439 self._default = self._ParseDefault(node)
440 if self._default is None:
441 self._default = _Default()
442
Colin Cross23acdd32012-04-21 00:33:54 -0700443 for node in itertools.chain(*node_list):
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700444 if node.nodeName == 'notice':
445 if self._notice is not None:
Doug Anderson37282b42011-03-04 11:54:18 -0800446 raise ManifestParseError(
447 'duplicate notice in %s' %
448 (self.manifestFile))
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700449 self._notice = self._ParseNotice(node)
450
Colin Cross23acdd32012-04-21 00:33:54 -0700451 for node in itertools.chain(*node_list):
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700452 if node.nodeName == 'manifest-server':
453 url = self._reqatt(node, 'url')
454 if self._manifest_server is not None:
David Pursehousec1b86a22012-11-14 11:36:51 +0900455 raise ManifestParseError(
456 'duplicate manifest-server in %s' %
457 (self.manifestFile))
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700458 self._manifest_server = url
459
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800460 def recursively_add_projects(project):
David James8d201162013-10-11 17:03:19 -0700461 projects = self._projects.setdefault(project.name, [])
462 if project.relpath is None:
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800463 raise ManifestParseError(
David James8d201162013-10-11 17:03:19 -0700464 'missing path for %s in %s' %
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800465 (project.name, self.manifestFile))
David James8d201162013-10-11 17:03:19 -0700466 if project.relpath in self._paths:
467 raise ManifestParseError(
468 'duplicate path %s in %s' %
469 (project.relpath, self.manifestFile))
470 self._paths[project.relpath] = project
471 projects.append(project)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800472 for subproject in project.subprojects:
473 recursively_add_projects(subproject)
474
Colin Cross23acdd32012-04-21 00:33:54 -0700475 for node in itertools.chain(*node_list):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700476 if node.nodeName == 'project':
477 project = self._ParseProject(node)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800478 recursively_add_projects(project)
Doug Anderson37282b42011-03-04 11:54:18 -0800479 if node.nodeName == 'repo-hooks':
480 # Get the name of the project and the (space-separated) list of enabled.
481 repo_hooks_project = self._reqatt(node, 'in-project')
482 enabled_repo_hooks = self._reqatt(node, 'enabled-list').split()
483
484 # Only one project can be the hooks project
485 if self._repo_hooks_project is not None:
486 raise ManifestParseError(
487 'duplicate repo-hooks in %s' %
488 (self.manifestFile))
489
490 # Store a reference to the Project.
491 try:
David James8d201162013-10-11 17:03:19 -0700492 repo_hooks_projects = self._projects[repo_hooks_project]
Doug Anderson37282b42011-03-04 11:54:18 -0800493 except KeyError:
494 raise ManifestParseError(
495 'project %s not found for repo-hooks' %
496 (repo_hooks_project))
497
David James8d201162013-10-11 17:03:19 -0700498 if len(repo_hooks_projects) != 1:
499 raise ManifestParseError(
500 'internal error parsing repo-hooks in %s' %
501 (self.manifestFile))
502 self._repo_hooks_project = repo_hooks_projects[0]
503
Doug Anderson37282b42011-03-04 11:54:18 -0800504 # Store the enabled hooks in the Project object.
505 self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks
Colin Cross23acdd32012-04-21 00:33:54 -0700506 if node.nodeName == 'remove-project':
507 name = self._reqatt(node, 'name')
508 try:
509 del self._projects[name]
510 except KeyError:
David Pursehousef9107482012-11-16 19:12:32 +0900511 raise ManifestParseError('remove-project element specifies non-existent '
512 'project: %s' % name)
Colin Cross23acdd32012-04-21 00:33:54 -0700513
514 # If the manifest removes the hooks project, treat it as if it deleted
515 # the repo-hooks element too.
516 if self._repo_hooks_project and (self._repo_hooks_project.name == name):
517 self._repo_hooks_project = None
518
Doug Anderson37282b42011-03-04 11:54:18 -0800519
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800520 def _AddMetaProjectMirror(self, m):
521 name = None
522 m_url = m.GetRemote(m.remote.name).url
523 if m_url.endswith('/.git'):
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530524 raise ManifestParseError('refusing to mirror %s' % m_url)
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800525
526 if self._default and self._default.remote:
Conley Owensceea3682011-10-20 10:45:47 -0700527 url = self._default.remote.resolvedFetchUrl
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800528 if not url.endswith('/'):
529 url += '/'
530 if m_url.startswith(url):
531 remote = self._default.remote
532 name = m_url[len(url):]
533
534 if name is None:
535 s = m_url.rindex('/') + 1
Conley Owensdb728cd2011-09-26 16:34:01 -0700536 manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
Shawn O. Pearcef35b2d92012-08-02 11:46:22 -0700537 remote = _XmlRemote('origin', fetch=m_url[:s], manifestUrl=manifestUrl)
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800538 name = m_url[s:]
539
540 if name.endswith('.git'):
541 name = name[:-4]
542
543 if name not in self._projects:
544 m.PreSync()
545 gitdir = os.path.join(self.topdir, '%s.git' % name)
546 project = Project(manifest = self,
547 name = name,
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700548 remote = remote.ToRemoteSpec(name),
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800549 gitdir = gitdir,
David James8d201162013-10-11 17:03:19 -0700550 objdir = gitdir,
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800551 worktree = None,
552 relpath = None,
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700553 revisionExpr = m.revisionExpr,
554 revisionId = None)
David James8d201162013-10-11 17:03:19 -0700555 self._projects[project.name] = [project]
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800556
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700557 def _ParseRemote(self, node):
558 """
559 reads a <remote> element from the manifest file
560 """
561 name = self._reqatt(node, 'name')
Yestin Sunb292b982012-07-02 07:32:50 -0700562 alias = node.getAttribute('alias')
563 if alias == '':
564 alias = None
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700565 fetch = self._reqatt(node, 'fetch')
566 review = node.getAttribute('review')
Shawn O. Pearceae6e0942008-11-06 10:25:35 -0800567 if review == '':
568 review = None
Conley Owensdb728cd2011-09-26 16:34:01 -0700569 manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
Yestin Sunb292b982012-07-02 07:32:50 -0700570 return _XmlRemote(name, alias, fetch, manifestUrl, review)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700571
572 def _ParseDefault(self, node):
573 """
574 reads a <default> element from the manifest file
575 """
576 d = _Default()
577 d.remote = self._get_remote(node)
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700578 d.revisionExpr = node.getAttribute('revision')
579 if d.revisionExpr == '':
580 d.revisionExpr = None
Anatol Pomazau79770d22012-04-20 14:41:59 -0700581
Bryan Jacobsf609f912013-05-06 13:36:24 -0400582 d.destBranchExpr = node.getAttribute('dest-branch') or None
583
Shawn O. Pearce6392c872011-09-22 17:44:31 -0700584 sync_j = node.getAttribute('sync-j')
585 if sync_j == '' or sync_j is None:
586 d.sync_j = 1
587 else:
588 d.sync_j = int(sync_j)
Anatol Pomazau79770d22012-04-20 14:41:59 -0700589
590 sync_c = node.getAttribute('sync-c')
591 if not sync_c:
592 d.sync_c = False
593 else:
594 d.sync_c = sync_c.lower() in ("yes", "true", "1")
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800595
596 sync_s = node.getAttribute('sync-s')
597 if not sync_s:
598 d.sync_s = False
599 else:
600 d.sync_s = sync_s.lower() in ("yes", "true", "1")
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700601 return d
602
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700603 def _ParseNotice(self, node):
604 """
605 reads a <notice> element from the manifest file
606
607 The <notice> element is distinct from other tags in the XML in that the
608 data is conveyed between the start and end tag (it's not an empty-element
609 tag).
610
611 The white space (carriage returns, indentation) for the notice element is
612 relevant and is parsed in a way that is based on how python docstrings work.
613 In fact, the code is remarkably similar to here:
614 http://www.python.org/dev/peps/pep-0257/
615 """
616 # Get the data out of the node...
617 notice = node.childNodes[0].data
618
619 # Figure out minimum indentation, skipping the first line (the same line
620 # as the <notice> tag)...
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530621 minIndent = sys.maxsize
Doug Anderson2b8db3c2010-11-01 15:08:06 -0700622 lines = notice.splitlines()
623 for line in lines[1:]:
624 lstrippedLine = line.lstrip()
625 if lstrippedLine:
626 indent = len(line) - len(lstrippedLine)
627 minIndent = min(indent, minIndent)
628
629 # Strip leading / trailing blank lines and also indentation.
630 cleanLines = [lines[0].strip()]
631 for line in lines[1:]:
632 cleanLines.append(line[minIndent:].rstrip())
633
634 # Clear completely blank lines from front and back...
635 while cleanLines and not cleanLines[0]:
636 del cleanLines[0]
637 while cleanLines and not cleanLines[-1]:
638 del cleanLines[-1]
639
640 return '\n'.join(cleanLines)
641
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800642 def _JoinName(self, parent_name, name):
643 return os.path.join(parent_name, name)
644
645 def _UnjoinName(self, parent_name, name):
646 return os.path.relpath(name, parent_name)
647
648 def _ParseProject(self, node, parent = None):
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700649 """
650 reads a <project> element from the manifest file
Nico Sallembiena1bfd2c2010-04-06 10:40:01 -0700651 """
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700652 name = self._reqatt(node, 'name')
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800653 if parent:
654 name = self._JoinName(parent.name, name)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700655
656 remote = self._get_remote(node)
657 if remote is None:
658 remote = self._default.remote
659 if remote is None:
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530660 raise ManifestParseError("no remote for project %s within %s" %
661 (name, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700662
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700663 revisionExpr = node.getAttribute('revision')
664 if not revisionExpr:
665 revisionExpr = self._default.revisionExpr
666 if not revisionExpr:
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530667 raise ManifestParseError("no revision for project %s within %s" %
668 (name, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700669
670 path = node.getAttribute('path')
671 if not path:
672 path = name
673 if path.startswith('/'):
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530674 raise ManifestParseError("project %s path cannot be absolute in %s" %
675 (name, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700676
Mike Pontillod3153822012-02-28 11:53:24 -0800677 rebase = node.getAttribute('rebase')
678 if not rebase:
679 rebase = True
680 else:
681 rebase = rebase.lower() in ("yes", "true", "1")
682
Anatol Pomazau79770d22012-04-20 14:41:59 -0700683 sync_c = node.getAttribute('sync-c')
684 if not sync_c:
685 sync_c = False
686 else:
687 sync_c = sync_c.lower() in ("yes", "true", "1")
688
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800689 sync_s = node.getAttribute('sync-s')
690 if not sync_s:
691 sync_s = self._default.sync_s
692 else:
693 sync_s = sync_s.lower() in ("yes", "true", "1")
694
David Pursehouseede7f122012-11-27 22:25:30 +0900695 clone_depth = node.getAttribute('clone-depth')
696 if clone_depth:
697 try:
698 clone_depth = int(clone_depth)
699 if clone_depth <= 0:
700 raise ValueError()
701 except ValueError:
702 raise ManifestParseError('invalid clone-depth %s in %s' %
703 (clone_depth, self.manifestFile))
704
Bryan Jacobsf609f912013-05-06 13:36:24 -0400705 dest_branch = node.getAttribute('dest-branch') or self._default.destBranchExpr
706
Brian Harring14a66742012-09-28 20:21:57 -0700707 upstream = node.getAttribute('upstream')
708
Conley Owens971de8e2012-04-16 10:36:08 -0700709 groups = ''
710 if node.hasAttribute('groups'):
711 groups = node.getAttribute('groups')
David Pursehouse1d947b32012-10-25 12:23:11 +0900712 groups = [x for x in re.split(r'[,\s]+', groups) if x]
Brian Harring7da13142012-06-15 02:24:20 -0700713
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800714 if parent is None:
David James8d201162013-10-11 17:03:19 -0700715 relpath, worktree, gitdir, objdir = self.GetProjectPaths(name, path)
Shawn O. Pearcecd81dd62012-10-26 12:18:00 -0700716 else:
David James8d201162013-10-11 17:03:19 -0700717 relpath, worktree, gitdir, objdir = \
718 self.GetSubprojectPaths(parent, name, path)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800719
720 default_groups = ['all', 'name:%s' % name, 'path:%s' % relpath]
721 groups.extend(set(default_groups).difference(groups))
Shawn O. Pearcecd81dd62012-10-26 12:18:00 -0700722
Scott Fandb83b1b2013-02-28 09:34:14 +0800723 if self.IsMirror and node.hasAttribute('force-path'):
724 if node.getAttribute('force-path').lower() in ("yes", "true", "1"):
725 gitdir = os.path.join(self.topdir, '%s.git' % path)
726
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700727 project = Project(manifest = self,
728 name = name,
Shawn O. Pearced1f70d92009-05-19 14:58:02 -0700729 remote = remote.ToRemoteSpec(name),
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700730 gitdir = gitdir,
David James8d201162013-10-11 17:03:19 -0700731 objdir = objdir,
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700732 worktree = worktree,
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800733 relpath = relpath,
Shawn O. Pearce3c8dea12009-05-29 18:38:17 -0700734 revisionExpr = revisionExpr,
Mike Pontillod3153822012-02-28 11:53:24 -0800735 revisionId = None,
Colin Cross5acde752012-03-28 20:15:45 -0700736 rebase = rebase,
Anatol Pomazau79770d22012-04-20 14:41:59 -0700737 groups = groups,
Brian Harring14a66742012-09-28 20:21:57 -0700738 sync_c = sync_c,
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800739 sync_s = sync_s,
David Pursehouseede7f122012-11-27 22:25:30 +0900740 clone_depth = clone_depth,
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800741 upstream = upstream,
Bryan Jacobsf609f912013-05-06 13:36:24 -0400742 parent = parent,
743 dest_branch = dest_branch)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700744
745 for n in node.childNodes:
Shawn O. Pearce242b5262009-05-19 13:00:29 -0700746 if n.nodeName == 'copyfile':
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700747 self._ParseCopyFile(project, n)
James W. Mills24c13082012-04-12 15:04:13 -0500748 if n.nodeName == 'annotation':
749 self._ParseAnnotation(project, n)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800750 if n.nodeName == 'project':
751 project.subprojects.append(self._ParseProject(n, parent = project))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700752
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700753 return project
754
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800755 def GetProjectPaths(self, name, path):
756 relpath = path
757 if self.IsMirror:
758 worktree = None
759 gitdir = os.path.join(self.topdir, '%s.git' % name)
David James8d201162013-10-11 17:03:19 -0700760 objdir = gitdir
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800761 else:
762 worktree = os.path.join(self.topdir, path).replace('\\', '/')
763 gitdir = os.path.join(self.repodir, 'projects', '%s.git' % path)
David James8d201162013-10-11 17:03:19 -0700764 objdir = os.path.join(self.repodir, 'project-objects', '%s.git' % name)
765 return relpath, worktree, gitdir, objdir
766
767 def GetProjectsWithName(self, name):
768 return self._projects.get(name, [])
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800769
770 def GetSubprojectName(self, parent, submodule_path):
771 return os.path.join(parent.name, submodule_path)
772
773 def _JoinRelpath(self, parent_relpath, relpath):
774 return os.path.join(parent_relpath, relpath)
775
776 def _UnjoinRelpath(self, parent_relpath, relpath):
777 return os.path.relpath(relpath, parent_relpath)
778
David James8d201162013-10-11 17:03:19 -0700779 def GetSubprojectPaths(self, parent, name, path):
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800780 relpath = self._JoinRelpath(parent.relpath, path)
781 gitdir = os.path.join(parent.gitdir, 'subprojects', '%s.git' % path)
David James8d201162013-10-11 17:03:19 -0700782 objdir = os.path.join(parent.gitdir, 'subproject-objects', '%s.git' % name)
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800783 if self.IsMirror:
784 worktree = None
785 else:
786 worktree = os.path.join(parent.worktree, path).replace('\\', '/')
David James8d201162013-10-11 17:03:19 -0700787 return relpath, worktree, gitdir, objdir
Che-Liang Chioub2bd91c2012-01-11 11:28:42 +0800788
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700789 def _ParseCopyFile(self, project, node):
790 src = self._reqatt(node, 'src')
791 dest = self._reqatt(node, 'dest')
Shawn O. Pearcee284ad12008-11-04 07:37:10 -0800792 if not self.IsMirror:
793 # src is project relative;
794 # dest is relative to the top of the tree
Shawn O. Pearcec7a4eef2009-03-05 10:32:38 -0800795 project.AddCopyFile(src, dest, os.path.join(self.topdir, dest))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700796
James W. Mills24c13082012-04-12 15:04:13 -0500797 def _ParseAnnotation(self, project, node):
798 name = self._reqatt(node, 'name')
799 value = self._reqatt(node, 'value')
800 try:
801 keep = self._reqatt(node, 'keep').lower()
802 except ManifestParseError:
803 keep = "true"
804 if keep != "true" and keep != "false":
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530805 raise ManifestParseError('optional "keep" attribute must be '
806 '"true" or "false"')
James W. Mills24c13082012-04-12 15:04:13 -0500807 project.AddAnnotation(name, value, keep)
808
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700809 def _get_remote(self, node):
810 name = node.getAttribute('remote')
811 if not name:
812 return None
813
814 v = self._remotes.get(name)
815 if not v:
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530816 raise ManifestParseError("remote %s not defined in %s" %
817 (name, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700818 return v
819
820 def _reqatt(self, node, attname):
821 """
822 reads a required attribute from the node.
823 """
824 v = node.getAttribute(attname)
825 if not v:
Chirayu Desai217ea7d2013-03-01 19:14:38 +0530826 raise ManifestParseError("no %s in <%s> within %s" %
827 (attname, node.nodeName, self.manifestFile))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700828 return v