The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # |
| 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 | |
| 16 | import os |
| 17 | import sys |
| 18 | import xml.dom.minidom |
| 19 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 20 | from git_config import GitConfig, IsId |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 21 | from project import RemoteSpec, Project, MetaProject, R_HEADS, HEAD |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 22 | from error import ManifestParseError |
| 23 | |
| 24 | MANIFEST_FILE_NAME = 'manifest.xml' |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 25 | LOCAL_MANIFEST_NAME = 'local_manifest.xml' |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 26 | |
| 27 | class _Default(object): |
| 28 | """Project defaults within the manifest.""" |
| 29 | |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 30 | revisionExpr = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 31 | remote = None |
| 32 | |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 33 | class _XmlRemote(object): |
| 34 | def __init__(self, |
| 35 | name, |
| 36 | fetch=None, |
| 37 | review=None): |
| 38 | self.name = name |
| 39 | self.fetchUrl = fetch |
| 40 | self.reviewUrl = review |
| 41 | |
| 42 | def ToRemoteSpec(self, projectName): |
| 43 | url = self.fetchUrl |
| 44 | while url.endswith('/'): |
| 45 | url = url[:-1] |
| 46 | url += '/%s.git' % projectName |
| 47 | return RemoteSpec(self.name, url, self.reviewUrl) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 48 | |
Shawn O. Pearce | c8a300f | 2009-05-18 13:19:57 -0700 | [diff] [blame] | 49 | class XmlManifest(object): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 50 | """manages the repo configuration file""" |
| 51 | |
| 52 | def __init__(self, repodir): |
| 53 | self.repodir = os.path.abspath(repodir) |
| 54 | self.topdir = os.path.dirname(self.repodir) |
| 55 | self.manifestFile = os.path.join(self.repodir, MANIFEST_FILE_NAME) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 56 | self.globalConfig = GitConfig.ForUser() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 57 | |
| 58 | self.repoProject = MetaProject(self, 'repo', |
| 59 | gitdir = os.path.join(repodir, 'repo/.git'), |
| 60 | worktree = os.path.join(repodir, 'repo')) |
| 61 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 62 | self.manifestProject = MetaProject(self, 'manifests', |
Shawn O. Pearce | f5c25a6 | 2008-11-04 08:11:53 -0800 | [diff] [blame] | 63 | gitdir = os.path.join(repodir, 'manifests.git'), |
| 64 | worktree = os.path.join(repodir, 'manifests')) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 65 | |
| 66 | self._Unload() |
| 67 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 68 | def Override(self, name): |
| 69 | """Use a different manifest, just for the current instantiation. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 70 | """ |
| 71 | path = os.path.join(self.manifestProject.worktree, name) |
| 72 | if not os.path.isfile(path): |
| 73 | raise ManifestParseError('manifest %s not found' % name) |
| 74 | |
| 75 | old = self.manifestFile |
| 76 | try: |
| 77 | self.manifestFile = path |
| 78 | self._Unload() |
| 79 | self._Load() |
| 80 | finally: |
| 81 | self.manifestFile = old |
| 82 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 83 | def Link(self, name): |
| 84 | """Update the repo metadata to use a different manifest. |
| 85 | """ |
| 86 | self.Override(name) |
| 87 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 88 | try: |
| 89 | if os.path.exists(self.manifestFile): |
| 90 | os.remove(self.manifestFile) |
| 91 | os.symlink('manifests/%s' % name, self.manifestFile) |
| 92 | except OSError, e: |
| 93 | raise ManifestParseError('cannot link manifest %s' % name) |
| 94 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 95 | def _RemoteToXml(self, r, doc, root): |
| 96 | e = doc.createElement('remote') |
| 97 | root.appendChild(e) |
| 98 | e.setAttribute('name', r.name) |
| 99 | e.setAttribute('fetch', r.fetchUrl) |
| 100 | if r.reviewUrl is not None: |
| 101 | e.setAttribute('review', r.reviewUrl) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 102 | |
| 103 | def Save(self, fd, peg_rev=False): |
| 104 | """Write the current manifest out to the given file descriptor. |
| 105 | """ |
| 106 | doc = xml.dom.minidom.Document() |
| 107 | root = doc.createElement('manifest') |
| 108 | doc.appendChild(root) |
| 109 | |
| 110 | d = self.default |
| 111 | sort_remotes = list(self.remotes.keys()) |
| 112 | sort_remotes.sort() |
| 113 | |
| 114 | for r in sort_remotes: |
| 115 | self._RemoteToXml(self.remotes[r], doc, root) |
| 116 | if self.remotes: |
| 117 | root.appendChild(doc.createTextNode('')) |
| 118 | |
| 119 | have_default = False |
| 120 | e = doc.createElement('default') |
| 121 | if d.remote: |
| 122 | have_default = True |
| 123 | e.setAttribute('remote', d.remote.name) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 124 | if d.revisionExpr: |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 125 | have_default = True |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 126 | e.setAttribute('revision', d.revisionExpr) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 127 | if have_default: |
| 128 | root.appendChild(e) |
| 129 | root.appendChild(doc.createTextNode('')) |
| 130 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 131 | if self._manifest_server: |
| 132 | e = doc.createElement('manifest-server') |
| 133 | e.setAttribute('url', self._manifest_server) |
| 134 | root.appendChild(e) |
| 135 | root.appendChild(doc.createTextNode('')) |
| 136 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 137 | sort_projects = list(self.projects.keys()) |
| 138 | sort_projects.sort() |
| 139 | |
| 140 | for p in sort_projects: |
| 141 | p = self.projects[p] |
| 142 | e = doc.createElement('project') |
| 143 | root.appendChild(e) |
| 144 | e.setAttribute('name', p.name) |
| 145 | if p.relpath != p.name: |
| 146 | e.setAttribute('path', p.relpath) |
| 147 | if not d.remote or p.remote.name != d.remote.name: |
| 148 | e.setAttribute('remote', p.remote.name) |
| 149 | if peg_rev: |
| 150 | if self.IsMirror: |
| 151 | e.setAttribute('revision', |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 152 | p.bare_git.rev_parse(p.revisionExpr + '^0')) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 153 | else: |
| 154 | e.setAttribute('revision', |
| 155 | p.work_git.rev_parse(HEAD + '^0')) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 156 | elif not d.revisionExpr or p.revisionExpr != d.revisionExpr: |
| 157 | e.setAttribute('revision', p.revisionExpr) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 158 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 159 | for c in p.copyfiles: |
| 160 | ce = doc.createElement('copyfile') |
| 161 | ce.setAttribute('src', c.src) |
| 162 | ce.setAttribute('dest', c.dest) |
| 163 | e.appendChild(ce) |
| 164 | |
| 165 | doc.writexml(fd, '', ' ', '\n', 'UTF-8') |
| 166 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 167 | @property |
| 168 | def projects(self): |
| 169 | self._Load() |
| 170 | return self._projects |
| 171 | |
| 172 | @property |
| 173 | def remotes(self): |
| 174 | self._Load() |
| 175 | return self._remotes |
| 176 | |
| 177 | @property |
| 178 | def default(self): |
| 179 | self._Load() |
| 180 | return self._default |
| 181 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 182 | @property |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 183 | def manifest_server(self): |
| 184 | self._Load() |
| 185 | return self._manifest_server |
| 186 | |
| 187 | @property |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 188 | def IsMirror(self): |
| 189 | return self.manifestProject.config.GetBoolean('repo.mirror') |
| 190 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 191 | def _Unload(self): |
| 192 | self._loaded = False |
| 193 | self._projects = {} |
| 194 | self._remotes = {} |
| 195 | self._default = None |
| 196 | self.branch = None |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 197 | self._manifest_server = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 198 | |
| 199 | def _Load(self): |
| 200 | if not self._loaded: |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 201 | m = self.manifestProject |
| 202 | b = m.GetBranch(m.CurrentBranch).merge |
Shawn O. Pearce | 21c5c34 | 2009-06-25 16:47:30 -0700 | [diff] [blame] | 203 | if b is not None and b.startswith(R_HEADS): |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 204 | b = b[len(R_HEADS):] |
| 205 | self.branch = b |
| 206 | |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 207 | self._ParseManifest(True) |
| 208 | |
| 209 | local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME) |
| 210 | if os.path.exists(local): |
| 211 | try: |
| 212 | real = self.manifestFile |
| 213 | self.manifestFile = local |
| 214 | self._ParseManifest(False) |
| 215 | finally: |
| 216 | self.manifestFile = real |
| 217 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 218 | if self.IsMirror: |
| 219 | self._AddMetaProjectMirror(self.repoProject) |
| 220 | self._AddMetaProjectMirror(self.manifestProject) |
| 221 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 222 | self._loaded = True |
| 223 | |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 224 | def _ParseManifest(self, is_root_file): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 225 | root = xml.dom.minidom.parse(self.manifestFile) |
| 226 | if not root or not root.childNodes: |
| 227 | raise ManifestParseError, \ |
| 228 | "no root node in %s" % \ |
| 229 | self.manifestFile |
| 230 | |
| 231 | config = root.childNodes[0] |
| 232 | if config.nodeName != 'manifest': |
| 233 | raise ManifestParseError, \ |
| 234 | "no <manifest> in %s" % \ |
| 235 | self.manifestFile |
| 236 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 237 | for node in config.childNodes: |
Shawn O. Pearce | 03eaf07 | 2008-11-20 11:42:22 -0800 | [diff] [blame] | 238 | if node.nodeName == 'remove-project': |
| 239 | name = self._reqatt(node, 'name') |
| 240 | try: |
| 241 | del self._projects[name] |
| 242 | except KeyError: |
| 243 | raise ManifestParseError, \ |
| 244 | 'project %s not found' % \ |
| 245 | (name) |
| 246 | |
| 247 | for node in config.childNodes: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 248 | if node.nodeName == 'remote': |
| 249 | remote = self._ParseRemote(node) |
| 250 | if self._remotes.get(remote.name): |
| 251 | raise ManifestParseError, \ |
| 252 | 'duplicate remote %s in %s' % \ |
| 253 | (remote.name, self.manifestFile) |
| 254 | self._remotes[remote.name] = remote |
| 255 | |
| 256 | for node in config.childNodes: |
| 257 | if node.nodeName == 'default': |
| 258 | if self._default is not None: |
| 259 | raise ManifestParseError, \ |
| 260 | 'duplicate default in %s' % \ |
| 261 | (self.manifestFile) |
| 262 | self._default = self._ParseDefault(node) |
| 263 | if self._default is None: |
| 264 | self._default = _Default() |
| 265 | |
| 266 | for node in config.childNodes: |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 267 | if node.nodeName == 'manifest-server': |
| 268 | url = self._reqatt(node, 'url') |
| 269 | if self._manifest_server is not None: |
| 270 | raise ManifestParseError, \ |
| 271 | 'duplicate manifest-server in %s' % \ |
| 272 | (self.manifestFile) |
| 273 | self._manifest_server = url |
| 274 | |
| 275 | for node in config.childNodes: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 276 | if node.nodeName == 'project': |
| 277 | project = self._ParseProject(node) |
| 278 | if self._projects.get(project.name): |
| 279 | raise ManifestParseError, \ |
| 280 | 'duplicate project %s in %s' % \ |
| 281 | (project.name, self.manifestFile) |
| 282 | self._projects[project.name] = project |
| 283 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 284 | def _AddMetaProjectMirror(self, m): |
| 285 | name = None |
| 286 | m_url = m.GetRemote(m.remote.name).url |
| 287 | if m_url.endswith('/.git'): |
| 288 | raise ManifestParseError, 'refusing to mirror %s' % m_url |
| 289 | |
| 290 | if self._default and self._default.remote: |
| 291 | url = self._default.remote.fetchUrl |
| 292 | if not url.endswith('/'): |
| 293 | url += '/' |
| 294 | if m_url.startswith(url): |
| 295 | remote = self._default.remote |
| 296 | name = m_url[len(url):] |
| 297 | |
| 298 | if name is None: |
| 299 | s = m_url.rindex('/') + 1 |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 300 | remote = _XmlRemote('origin', m_url[:s]) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 301 | name = m_url[s:] |
| 302 | |
| 303 | if name.endswith('.git'): |
| 304 | name = name[:-4] |
| 305 | |
| 306 | if name not in self._projects: |
| 307 | m.PreSync() |
| 308 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 309 | project = Project(manifest = self, |
| 310 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 311 | remote = remote.ToRemoteSpec(name), |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 312 | gitdir = gitdir, |
| 313 | worktree = None, |
| 314 | relpath = None, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 315 | revisionExpr = m.revisionExpr, |
| 316 | revisionId = None) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 317 | self._projects[project.name] = project |
| 318 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 319 | def _ParseRemote(self, node): |
| 320 | """ |
| 321 | reads a <remote> element from the manifest file |
| 322 | """ |
| 323 | name = self._reqatt(node, 'name') |
| 324 | fetch = self._reqatt(node, 'fetch') |
| 325 | review = node.getAttribute('review') |
Shawn O. Pearce | ae6e094 | 2008-11-06 10:25:35 -0800 | [diff] [blame] | 326 | if review == '': |
| 327 | review = None |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 328 | return _XmlRemote(name, fetch, review) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 329 | |
| 330 | def _ParseDefault(self, node): |
| 331 | """ |
| 332 | reads a <default> element from the manifest file |
| 333 | """ |
| 334 | d = _Default() |
| 335 | d.remote = self._get_remote(node) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 336 | d.revisionExpr = node.getAttribute('revision') |
| 337 | if d.revisionExpr == '': |
| 338 | d.revisionExpr = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 339 | return d |
| 340 | |
| 341 | def _ParseProject(self, node): |
| 342 | """ |
| 343 | reads a <project> element from the manifest file |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 344 | """ |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 345 | name = self._reqatt(node, 'name') |
| 346 | |
| 347 | remote = self._get_remote(node) |
| 348 | if remote is None: |
| 349 | remote = self._default.remote |
| 350 | if remote is None: |
| 351 | raise ManifestParseError, \ |
| 352 | "no remote for project %s within %s" % \ |
| 353 | (name, self.manifestFile) |
| 354 | |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 355 | revisionExpr = node.getAttribute('revision') |
| 356 | if not revisionExpr: |
| 357 | revisionExpr = self._default.revisionExpr |
| 358 | if not revisionExpr: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 359 | raise ManifestParseError, \ |
| 360 | "no revision for project %s within %s" % \ |
| 361 | (name, self.manifestFile) |
| 362 | |
| 363 | path = node.getAttribute('path') |
| 364 | if not path: |
| 365 | path = name |
| 366 | if path.startswith('/'): |
| 367 | raise ManifestParseError, \ |
| 368 | "project %s path cannot be absolute in %s" % \ |
| 369 | (name, self.manifestFile) |
| 370 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 371 | if self.IsMirror: |
| 372 | relpath = None |
| 373 | worktree = None |
| 374 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 375 | else: |
| 376 | worktree = os.path.join(self.topdir, path) |
| 377 | gitdir = os.path.join(self.repodir, 'projects/%s.git' % path) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 378 | |
| 379 | project = Project(manifest = self, |
| 380 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 381 | remote = remote.ToRemoteSpec(name), |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 382 | gitdir = gitdir, |
| 383 | worktree = worktree, |
| 384 | relpath = path, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 385 | revisionExpr = revisionExpr, |
| 386 | revisionId = None) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 387 | |
| 388 | for n in node.childNodes: |
Shawn O. Pearce | 242b526 | 2009-05-19 13:00:29 -0700 | [diff] [blame] | 389 | if n.nodeName == 'copyfile': |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 390 | self._ParseCopyFile(project, n) |
| 391 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 392 | return project |
| 393 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 394 | def _ParseCopyFile(self, project, node): |
| 395 | src = self._reqatt(node, 'src') |
| 396 | dest = self._reqatt(node, 'dest') |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 397 | if not self.IsMirror: |
| 398 | # src is project relative; |
| 399 | # dest is relative to the top of the tree |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 400 | project.AddCopyFile(src, dest, os.path.join(self.topdir, dest)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 401 | |
| 402 | def _get_remote(self, node): |
| 403 | name = node.getAttribute('remote') |
| 404 | if not name: |
| 405 | return None |
| 406 | |
| 407 | v = self._remotes.get(name) |
| 408 | if not v: |
| 409 | raise ManifestParseError, \ |
| 410 | "remote %s not defined in %s" % \ |
| 411 | (name, self.manifestFile) |
| 412 | return v |
| 413 | |
| 414 | def _reqatt(self, node, attname): |
| 415 | """ |
| 416 | reads a required attribute from the node. |
| 417 | """ |
| 418 | v = node.getAttribute(attname) |
| 419 | if not v: |
| 420 | raise ManifestParseError, \ |
| 421 | "no %s in <%s> within %s" % \ |
| 422 | (attname, node.nodeName, self.manifestFile) |
| 423 | return v |