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 |
Shawn O. Pearce | 5f947bb | 2009-07-03 17:24:17 -0700 | [diff] [blame] | 192 | b = m.GetBranch(m.CurrentBranch) |
| 193 | if b.remote and b.remote.name: |
| 194 | m.remote.name = b.remote.name |
| 195 | b = b.merge |
Shawn O. Pearce | 21c5c34 | 2009-06-25 16:47:30 -0700 | [diff] [blame] | 196 | if b is not None and b.startswith(R_HEADS): |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 197 | b = b[len(R_HEADS):] |
| 198 | self.branch = b |
| 199 | |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 200 | self._ParseManifest(True) |
| 201 | |
| 202 | local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME) |
| 203 | if os.path.exists(local): |
| 204 | try: |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 205 | real = self._manifestFile |
| 206 | self._manifestFile = local |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 207 | self._ParseManifest(False) |
| 208 | finally: |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 209 | self._manifestFile = real |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 210 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 211 | if self.IsMirror: |
| 212 | self._AddMetaProjectMirror(self.repoProject) |
| 213 | self._AddMetaProjectMirror(self.manifestProject) |
| 214 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 215 | self._loaded = True |
| 216 | |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 217 | def _ParseManifest(self, is_root_file): |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 218 | root = xml.dom.minidom.parse(self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 219 | if not root or not root.childNodes: |
| 220 | raise ManifestParseError, \ |
| 221 | "no root node in %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 222 | self._manifestFile |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 223 | |
| 224 | config = root.childNodes[0] |
| 225 | if config.nodeName != 'manifest': |
| 226 | raise ManifestParseError, \ |
| 227 | "no <manifest> in %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 228 | self._manifestFile |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 229 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 230 | for node in config.childNodes: |
Shawn O. Pearce | 03eaf07 | 2008-11-20 11:42:22 -0800 | [diff] [blame] | 231 | if node.nodeName == 'remove-project': |
| 232 | name = self._reqatt(node, 'name') |
| 233 | try: |
| 234 | del self._projects[name] |
| 235 | except KeyError: |
| 236 | raise ManifestParseError, \ |
| 237 | 'project %s not found' % \ |
| 238 | (name) |
| 239 | |
| 240 | for node in config.childNodes: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 241 | if node.nodeName == 'remote': |
| 242 | remote = self._ParseRemote(node) |
| 243 | if self._remotes.get(remote.name): |
| 244 | raise ManifestParseError, \ |
| 245 | 'duplicate remote %s in %s' % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 246 | (remote.name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 247 | self._remotes[remote.name] = remote |
| 248 | |
| 249 | for node in config.childNodes: |
| 250 | if node.nodeName == 'default': |
| 251 | if self._default is not None: |
| 252 | raise ManifestParseError, \ |
| 253 | 'duplicate default in %s' % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 254 | (self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 255 | self._default = self._ParseDefault(node) |
| 256 | if self._default is None: |
| 257 | self._default = _Default() |
| 258 | |
| 259 | for node in config.childNodes: |
| 260 | if node.nodeName == 'project': |
| 261 | project = self._ParseProject(node) |
| 262 | if self._projects.get(project.name): |
| 263 | raise ManifestParseError, \ |
| 264 | 'duplicate project %s in %s' % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 265 | (project.name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 266 | self._projects[project.name] = project |
| 267 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 268 | def _AddMetaProjectMirror(self, m): |
| 269 | name = None |
| 270 | m_url = m.GetRemote(m.remote.name).url |
| 271 | if m_url.endswith('/.git'): |
| 272 | raise ManifestParseError, 'refusing to mirror %s' % m_url |
| 273 | |
| 274 | if self._default and self._default.remote: |
| 275 | url = self._default.remote.fetchUrl |
| 276 | if not url.endswith('/'): |
| 277 | url += '/' |
| 278 | if m_url.startswith(url): |
| 279 | remote = self._default.remote |
| 280 | name = m_url[len(url):] |
| 281 | |
| 282 | if name is None: |
| 283 | s = m_url.rindex('/') + 1 |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 284 | remote = _XmlRemote('origin', m_url[:s]) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 285 | name = m_url[s:] |
| 286 | |
| 287 | if name.endswith('.git'): |
| 288 | name = name[:-4] |
| 289 | |
| 290 | if name not in self._projects: |
| 291 | m.PreSync() |
| 292 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 293 | project = Project(manifest = self, |
| 294 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 295 | remote = remote.ToRemoteSpec(name), |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 296 | gitdir = gitdir, |
| 297 | worktree = None, |
| 298 | relpath = None, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 299 | revisionExpr = m.revisionExpr, |
| 300 | revisionId = None) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 301 | self._projects[project.name] = project |
| 302 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 303 | def _ParseRemote(self, node): |
| 304 | """ |
| 305 | reads a <remote> element from the manifest file |
| 306 | """ |
| 307 | name = self._reqatt(node, 'name') |
| 308 | fetch = self._reqatt(node, 'fetch') |
| 309 | review = node.getAttribute('review') |
Shawn O. Pearce | ae6e094 | 2008-11-06 10:25:35 -0800 | [diff] [blame] | 310 | if review == '': |
| 311 | review = None |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 312 | return _XmlRemote(name, fetch, review) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 313 | |
| 314 | def _ParseDefault(self, node): |
| 315 | """ |
| 316 | reads a <default> element from the manifest file |
| 317 | """ |
| 318 | d = _Default() |
| 319 | d.remote = self._get_remote(node) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 320 | d.revisionExpr = node.getAttribute('revision') |
| 321 | if d.revisionExpr == '': |
| 322 | d.revisionExpr = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 323 | return d |
| 324 | |
| 325 | def _ParseProject(self, node): |
| 326 | """ |
| 327 | reads a <project> element from the manifest file |
| 328 | """ |
| 329 | name = self._reqatt(node, 'name') |
| 330 | |
| 331 | remote = self._get_remote(node) |
| 332 | if remote is None: |
| 333 | remote = self._default.remote |
| 334 | if remote is None: |
| 335 | raise ManifestParseError, \ |
| 336 | "no remote for project %s within %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 337 | (name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 338 | |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 339 | revisionExpr = node.getAttribute('revision') |
| 340 | if not revisionExpr: |
| 341 | revisionExpr = self._default.revisionExpr |
| 342 | if not revisionExpr: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 343 | raise ManifestParseError, \ |
| 344 | "no revision for project %s within %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 345 | (name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 346 | |
| 347 | path = node.getAttribute('path') |
| 348 | if not path: |
| 349 | path = name |
| 350 | if path.startswith('/'): |
| 351 | raise ManifestParseError, \ |
| 352 | "project %s path cannot be absolute in %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 353 | (name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 354 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 355 | if self.IsMirror: |
| 356 | relpath = None |
| 357 | worktree = None |
| 358 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 359 | else: |
| 360 | worktree = os.path.join(self.topdir, path) |
| 361 | 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] | 362 | |
| 363 | project = Project(manifest = self, |
| 364 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 365 | remote = remote.ToRemoteSpec(name), |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 366 | gitdir = gitdir, |
| 367 | worktree = worktree, |
| 368 | relpath = path, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 369 | revisionExpr = revisionExpr, |
| 370 | revisionId = None) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 371 | |
| 372 | for n in node.childNodes: |
Shawn O. Pearce | 242b526 | 2009-05-19 13:00:29 -0700 | [diff] [blame] | 373 | if n.nodeName == 'copyfile': |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 374 | self._ParseCopyFile(project, n) |
| 375 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 376 | return project |
| 377 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 378 | def _ParseCopyFile(self, project, node): |
| 379 | src = self._reqatt(node, 'src') |
| 380 | dest = self._reqatt(node, 'dest') |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 381 | if not self.IsMirror: |
| 382 | # src is project relative; |
| 383 | # dest is relative to the top of the tree |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 384 | 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] | 385 | |
| 386 | def _get_remote(self, node): |
| 387 | name = node.getAttribute('remote') |
| 388 | if not name: |
| 389 | return None |
| 390 | |
| 391 | v = self._remotes.get(name) |
| 392 | if not v: |
| 393 | raise ManifestParseError, \ |
| 394 | "remote %s not defined in %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 395 | (name, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 396 | return v |
| 397 | |
| 398 | def _reqatt(self, node, attname): |
| 399 | """ |
| 400 | reads a required attribute from the node. |
| 401 | """ |
| 402 | v = node.getAttribute(attname) |
| 403 | if not v: |
| 404 | raise ManifestParseError, \ |
| 405 | "no %s in <%s> within %s" % \ |
Shawn O. Pearce | f1a6b14 | 2009-06-03 16:01:11 -0700 | [diff] [blame] | 406 | (attname, node.nodeName, self._manifestFile) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 407 | return v |