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