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 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 16 | import itertools |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 17 | import os |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 18 | import re |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 19 | import sys |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 20 | import urlparse |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 21 | import xml.dom.minidom |
| 22 | |
David Pursehouse | e15c65a | 2012-08-22 10:46:11 +0900 | [diff] [blame] | 23 | from git_config import GitConfig |
David Pursehouse | e00aa6b | 2012-09-11 14:33:51 +0900 | [diff] [blame] | 24 | from git_refs import R_HEADS, HEAD |
| 25 | from project import RemoteSpec, Project, MetaProject |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 26 | from error import ManifestParseError |
| 27 | |
| 28 | MANIFEST_FILE_NAME = 'manifest.xml' |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 29 | LOCAL_MANIFEST_NAME = 'local_manifest.xml' |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 30 | LOCAL_MANIFESTS_DIR_NAME = 'local_manifests' |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 31 | |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 32 | urlparse.uses_relative.extend(['ssh', 'git']) |
| 33 | urlparse.uses_netloc.extend(['ssh', 'git']) |
| 34 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 35 | class _Default(object): |
| 36 | """Project defaults within the manifest.""" |
| 37 | |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 38 | revisionExpr = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 39 | remote = None |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 40 | sync_j = 1 |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 41 | sync_c = False |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 42 | |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 43 | class _XmlRemote(object): |
| 44 | def __init__(self, |
| 45 | name, |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 46 | alias=None, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 47 | fetch=None, |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 48 | manifestUrl=None, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 49 | review=None): |
| 50 | self.name = name |
| 51 | self.fetchUrl = fetch |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 52 | self.manifestUrl = manifestUrl |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 53 | self.remoteAlias = alias |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 54 | self.reviewUrl = review |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 55 | self.resolvedFetchUrl = self._resolveFetchUrl() |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 56 | |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 57 | def _resolveFetchUrl(self): |
| 58 | url = self.fetchUrl.rstrip('/') |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 59 | manifestUrl = self.manifestUrl.rstrip('/') |
| 60 | # urljoin will get confused if there is no scheme in the base url |
| 61 | # ie, if manifestUrl is of the form <hostname:port> |
| 62 | if manifestUrl.find(':') != manifestUrl.find('/') - 1: |
| 63 | manifestUrl = 'gopher://' + manifestUrl |
| 64 | url = urlparse.urljoin(manifestUrl, url) |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 65 | return re.sub(r'^gopher://', '', url) |
| 66 | |
| 67 | def ToRemoteSpec(self, projectName): |
Conley Owens | 9d8f914 | 2011-10-20 14:36:35 -0700 | [diff] [blame] | 68 | url = self.resolvedFetchUrl.rstrip('/') + '/' + projectName |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 69 | remoteName = self.name |
| 70 | if self.remoteAlias: |
| 71 | remoteName = self.remoteAlias |
| 72 | return RemoteSpec(remoteName, url, self.reviewUrl) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 73 | |
Shawn O. Pearce | c8a300f | 2009-05-18 13:19:57 -0700 | [diff] [blame] | 74 | class XmlManifest(object): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 75 | """manages the repo configuration file""" |
| 76 | |
| 77 | def __init__(self, repodir): |
| 78 | self.repodir = os.path.abspath(repodir) |
| 79 | self.topdir = os.path.dirname(self.repodir) |
| 80 | 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] | 81 | self.globalConfig = GitConfig.ForUser() |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 82 | |
| 83 | self.repoProject = MetaProject(self, 'repo', |
| 84 | gitdir = os.path.join(repodir, 'repo/.git'), |
| 85 | worktree = os.path.join(repodir, 'repo')) |
| 86 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 87 | self.manifestProject = MetaProject(self, 'manifests', |
Shawn O. Pearce | f5c25a6 | 2008-11-04 08:11:53 -0800 | [diff] [blame] | 88 | gitdir = os.path.join(repodir, 'manifests.git'), |
| 89 | worktree = os.path.join(repodir, 'manifests')) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 90 | |
| 91 | self._Unload() |
| 92 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 93 | def Override(self, name): |
| 94 | """Use a different manifest, just for the current instantiation. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 95 | """ |
| 96 | path = os.path.join(self.manifestProject.worktree, name) |
| 97 | if not os.path.isfile(path): |
| 98 | raise ManifestParseError('manifest %s not found' % name) |
| 99 | |
| 100 | old = self.manifestFile |
| 101 | try: |
| 102 | self.manifestFile = path |
| 103 | self._Unload() |
| 104 | self._Load() |
| 105 | finally: |
| 106 | self.manifestFile = old |
| 107 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 108 | def Link(self, name): |
| 109 | """Update the repo metadata to use a different manifest. |
| 110 | """ |
| 111 | self.Override(name) |
| 112 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 113 | try: |
| 114 | if os.path.exists(self.manifestFile): |
| 115 | os.remove(self.manifestFile) |
| 116 | os.symlink('manifests/%s' % name, self.manifestFile) |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 117 | except OSError: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 118 | raise ManifestParseError('cannot link manifest %s' % name) |
| 119 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 120 | def _RemoteToXml(self, r, doc, root): |
| 121 | e = doc.createElement('remote') |
| 122 | root.appendChild(e) |
| 123 | e.setAttribute('name', r.name) |
| 124 | e.setAttribute('fetch', r.fetchUrl) |
| 125 | if r.reviewUrl is not None: |
| 126 | e.setAttribute('review', r.reviewUrl) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 127 | |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 128 | def Save(self, fd, peg_rev=False, peg_rev_upstream=True): |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 129 | """Write the current manifest out to the given file descriptor. |
| 130 | """ |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 131 | mp = self.manifestProject |
| 132 | |
| 133 | groups = mp.config.GetString('manifest.groups') |
Colin Cross | c39864f | 2012-04-23 13:41:58 -0700 | [diff] [blame] | 134 | if not groups: |
Conley Owens | bb1b5f5 | 2012-08-13 13:11:18 -0700 | [diff] [blame] | 135 | groups = 'all' |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 136 | groups = [x for x in re.split(r'[,\s]+', groups) if x] |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 137 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 138 | doc = xml.dom.minidom.Document() |
| 139 | root = doc.createElement('manifest') |
| 140 | doc.appendChild(root) |
| 141 | |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 142 | # Save out the notice. There's a little bit of work here to give it the |
| 143 | # right whitespace, which assumes that the notice is automatically indented |
| 144 | # by 4 by minidom. |
| 145 | if self.notice: |
| 146 | notice_element = root.appendChild(doc.createElement('notice')) |
| 147 | notice_lines = self.notice.splitlines() |
| 148 | indented_notice = ('\n'.join(" "*4 + line for line in notice_lines))[4:] |
| 149 | notice_element.appendChild(doc.createTextNode(indented_notice)) |
| 150 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 151 | d = self.default |
| 152 | sort_remotes = list(self.remotes.keys()) |
| 153 | sort_remotes.sort() |
| 154 | |
| 155 | for r in sort_remotes: |
| 156 | self._RemoteToXml(self.remotes[r], doc, root) |
| 157 | if self.remotes: |
| 158 | root.appendChild(doc.createTextNode('')) |
| 159 | |
| 160 | have_default = False |
| 161 | e = doc.createElement('default') |
| 162 | if d.remote: |
| 163 | have_default = True |
| 164 | e.setAttribute('remote', d.remote.name) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 165 | if d.revisionExpr: |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 166 | have_default = True |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 167 | e.setAttribute('revision', d.revisionExpr) |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 168 | if d.sync_j > 1: |
| 169 | have_default = True |
| 170 | e.setAttribute('sync-j', '%d' % d.sync_j) |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 171 | if d.sync_c: |
| 172 | have_default = True |
| 173 | e.setAttribute('sync-c', 'true') |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 174 | if have_default: |
| 175 | root.appendChild(e) |
| 176 | root.appendChild(doc.createTextNode('')) |
| 177 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 178 | if self._manifest_server: |
| 179 | e = doc.createElement('manifest-server') |
| 180 | e.setAttribute('url', self._manifest_server) |
| 181 | root.appendChild(e) |
| 182 | root.appendChild(doc.createTextNode('')) |
| 183 | |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 184 | sort_projects = list(self.projects.keys()) |
| 185 | sort_projects.sort() |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 186 | |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 187 | for p in sort_projects: |
| 188 | p = self.projects[p] |
| 189 | |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 190 | if not p.MatchesGroups(groups): |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 191 | continue |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 192 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 193 | e = doc.createElement('project') |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 194 | root.appendChild(e) |
| 195 | e.setAttribute('name', p.name) |
| 196 | if p.relpath != p.name: |
| 197 | e.setAttribute('path', p.relpath) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 198 | if not d.remote or p.remote.name != d.remote.name: |
| 199 | e.setAttribute('remote', p.remote.name) |
| 200 | if peg_rev: |
| 201 | if self.IsMirror: |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 202 | value = p.bare_git.rev_parse(p.revisionExpr + '^0') |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 203 | else: |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 204 | value = p.work_git.rev_parse(HEAD + '^0') |
| 205 | e.setAttribute('revision', value) |
| 206 | if peg_rev_upstream and value != p.revisionExpr: |
| 207 | # Only save the origin if the origin is not a sha1, and the default |
| 208 | # isn't our value, and the if the default doesn't already have that |
| 209 | # covered. |
| 210 | e.setAttribute('upstream', p.revisionExpr) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 211 | elif not d.revisionExpr or p.revisionExpr != d.revisionExpr: |
| 212 | e.setAttribute('revision', p.revisionExpr) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 213 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 214 | for c in p.copyfiles: |
| 215 | ce = doc.createElement('copyfile') |
| 216 | ce.setAttribute('src', c.src) |
| 217 | ce.setAttribute('dest', c.dest) |
| 218 | e.appendChild(ce) |
| 219 | |
Conley Owens | bb1b5f5 | 2012-08-13 13:11:18 -0700 | [diff] [blame] | 220 | default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath] |
Dmitry Fink | 17f85ea | 2012-08-06 14:52:29 -0700 | [diff] [blame] | 221 | egroups = [g for g in p.groups if g not in default_groups] |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 222 | if egroups: |
| 223 | e.setAttribute('groups', ','.join(egroups)) |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 224 | |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 225 | for a in p.annotations: |
| 226 | if a.keep == "true": |
| 227 | ae = doc.createElement('annotation') |
| 228 | ae.setAttribute('name', a.name) |
| 229 | ae.setAttribute('value', a.value) |
| 230 | e.appendChild(ae) |
| 231 | |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 232 | if p.sync_c: |
| 233 | e.setAttribute('sync-c', 'true') |
| 234 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 235 | if self._repo_hooks_project: |
| 236 | root.appendChild(doc.createTextNode('')) |
| 237 | e = doc.createElement('repo-hooks') |
| 238 | e.setAttribute('in-project', self._repo_hooks_project.name) |
| 239 | e.setAttribute('enabled-list', |
| 240 | ' '.join(self._repo_hooks_project.enabled_repo_hooks)) |
| 241 | root.appendChild(e) |
| 242 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 243 | doc.writexml(fd, '', ' ', '\n', 'UTF-8') |
| 244 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 245 | @property |
| 246 | def projects(self): |
| 247 | self._Load() |
| 248 | return self._projects |
| 249 | |
| 250 | @property |
| 251 | def remotes(self): |
| 252 | self._Load() |
| 253 | return self._remotes |
| 254 | |
| 255 | @property |
| 256 | def default(self): |
| 257 | self._Load() |
| 258 | return self._default |
| 259 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 260 | @property |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 261 | def repo_hooks_project(self): |
| 262 | self._Load() |
| 263 | return self._repo_hooks_project |
| 264 | |
| 265 | @property |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 266 | def notice(self): |
| 267 | self._Load() |
| 268 | return self._notice |
| 269 | |
| 270 | @property |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 271 | def manifest_server(self): |
| 272 | self._Load() |
Shawn O. Pearce | 34fb20f | 2011-11-30 13:41:02 -0800 | [diff] [blame] | 273 | return self._manifest_server |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 274 | |
| 275 | @property |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 276 | def IsMirror(self): |
| 277 | return self.manifestProject.config.GetBoolean('repo.mirror') |
| 278 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 279 | def _Unload(self): |
| 280 | self._loaded = False |
| 281 | self._projects = {} |
| 282 | self._remotes = {} |
| 283 | self._default = None |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 284 | self._repo_hooks_project = None |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 285 | self._notice = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 286 | self.branch = None |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 287 | self._manifest_server = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 288 | |
| 289 | def _Load(self): |
| 290 | if not self._loaded: |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 291 | m = self.manifestProject |
| 292 | b = m.GetBranch(m.CurrentBranch).merge |
Shawn O. Pearce | 21c5c34 | 2009-06-25 16:47:30 -0700 | [diff] [blame] | 293 | if b is not None and b.startswith(R_HEADS): |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 294 | b = b[len(R_HEADS):] |
| 295 | self.branch = b |
| 296 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 297 | nodes = [] |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 298 | nodes.append(self._ParseManifestXml(self.manifestFile, |
| 299 | self.manifestProject.worktree)) |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 300 | |
| 301 | local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME) |
| 302 | if os.path.exists(local): |
David Pursehouse | 5566ae5 | 2012-11-13 03:04:18 +0900 | [diff] [blame^] | 303 | print >>sys.stderr, 'warning: %s is deprecated; put local manifests in %s instead' % \ |
| 304 | (LOCAL_MANIFEST_NAME, LOCAL_MANIFESTS_DIR_NAME) |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 305 | nodes.append(self._ParseManifestXml(local, self.repodir)) |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 306 | |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 307 | local_dir = os.path.abspath(os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME)) |
| 308 | try: |
| 309 | for local_file in os.listdir(local_dir): |
| 310 | if local_file.endswith('.xml'): |
| 311 | try: |
| 312 | nodes.append(self._ParseManifestXml(local_file, self.repodir)) |
| 313 | except ManifestParseError as e: |
| 314 | print >>sys.stderr, '%s' % str(e) |
| 315 | except OSError: |
| 316 | pass |
| 317 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 318 | self._ParseManifest(nodes) |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 319 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 320 | if self.IsMirror: |
| 321 | self._AddMetaProjectMirror(self.repoProject) |
| 322 | self._AddMetaProjectMirror(self.manifestProject) |
| 323 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 324 | self._loaded = True |
| 325 | |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 326 | def _ParseManifestXml(self, path, include_root): |
David Pursehouse | f7fc8a9 | 2012-11-13 04:00:28 +0900 | [diff] [blame] | 327 | try: |
| 328 | root = xml.dom.minidom.parse(path) |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 329 | except (OSError, xml.parsers.expat.ExpatError) as e: |
David Pursehouse | f7fc8a9 | 2012-11-13 04:00:28 +0900 | [diff] [blame] | 330 | raise ManifestParseError("error parsing manifest %s: %s" % (path, e)) |
| 331 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 332 | if not root or not root.childNodes: |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 333 | raise ManifestParseError("no root node in %s" % (path,)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 334 | |
Jooncheol Park | 34acdd2 | 2012-08-27 02:25:59 +0900 | [diff] [blame] | 335 | for manifest in root.childNodes: |
| 336 | if manifest.nodeName == 'manifest': |
| 337 | break |
| 338 | else: |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 339 | raise ManifestParseError("no <manifest> in %s" % (path,)) |
| 340 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 341 | nodes = [] |
David Pursehouse | 4f7bdea | 2012-10-22 12:50:15 +0900 | [diff] [blame] | 342 | for node in manifest.childNodes: # pylint:disable=W0631 |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 343 | # We only get here if manifest is initialised |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 344 | if node.nodeName == 'include': |
| 345 | name = self._reqatt(node, 'name') |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 346 | fp = os.path.join(include_root, name) |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 347 | if not os.path.isfile(fp): |
| 348 | raise ManifestParseError, \ |
| 349 | "include %s doesn't exist or isn't a file" % \ |
| 350 | (name,) |
| 351 | try: |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 352 | nodes.extend(self._ParseManifestXml(fp, include_root)) |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 353 | # should isolate this to the exact exception, but that's |
| 354 | # tricky. actual parsing implementation may vary. |
| 355 | except (KeyboardInterrupt, RuntimeError, SystemExit): |
| 356 | raise |
Sarah Owens | a5be53f | 2012-09-09 15:37:57 -0700 | [diff] [blame] | 357 | except Exception as e: |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 358 | raise ManifestParseError( |
| 359 | "failed parsing included manifest %s: %s", (name, e)) |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 360 | else: |
| 361 | nodes.append(node) |
| 362 | return nodes |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 363 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 364 | def _ParseManifest(self, node_list): |
| 365 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 366 | if node.nodeName == 'remote': |
| 367 | remote = self._ParseRemote(node) |
| 368 | if self._remotes.get(remote.name): |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 369 | raise ManifestParseError( |
| 370 | 'duplicate remote %s in %s' % |
| 371 | (remote.name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 372 | self._remotes[remote.name] = remote |
| 373 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 374 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 375 | if node.nodeName == 'default': |
| 376 | if self._default is not None: |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 377 | raise ManifestParseError( |
| 378 | 'duplicate default in %s' % |
| 379 | (self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 380 | self._default = self._ParseDefault(node) |
| 381 | if self._default is None: |
| 382 | self._default = _Default() |
| 383 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 384 | for node in itertools.chain(*node_list): |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 385 | if node.nodeName == 'notice': |
| 386 | if self._notice is not None: |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 387 | raise ManifestParseError( |
| 388 | 'duplicate notice in %s' % |
| 389 | (self.manifestFile)) |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 390 | self._notice = self._ParseNotice(node) |
| 391 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 392 | for node in itertools.chain(*node_list): |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 393 | if node.nodeName == 'manifest-server': |
| 394 | url = self._reqatt(node, 'url') |
| 395 | if self._manifest_server is not None: |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 396 | raise ManifestParseError( |
| 397 | 'duplicate manifest-server in %s' % |
| 398 | (self.manifestFile)) |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 399 | self._manifest_server = url |
| 400 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 401 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 402 | if node.nodeName == 'project': |
| 403 | project = self._ParseProject(node) |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 404 | if self._projects.get(project.name): |
| 405 | raise ManifestParseError( |
| 406 | 'duplicate project %s in %s' % |
| 407 | (project.name, self.manifestFile)) |
| 408 | self._projects[project.name] = project |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 409 | if node.nodeName == 'repo-hooks': |
| 410 | # Get the name of the project and the (space-separated) list of enabled. |
| 411 | repo_hooks_project = self._reqatt(node, 'in-project') |
| 412 | enabled_repo_hooks = self._reqatt(node, 'enabled-list').split() |
| 413 | |
| 414 | # Only one project can be the hooks project |
| 415 | if self._repo_hooks_project is not None: |
| 416 | raise ManifestParseError( |
| 417 | 'duplicate repo-hooks in %s' % |
| 418 | (self.manifestFile)) |
| 419 | |
| 420 | # Store a reference to the Project. |
| 421 | try: |
| 422 | self._repo_hooks_project = self._projects[repo_hooks_project] |
| 423 | except KeyError: |
| 424 | raise ManifestParseError( |
| 425 | 'project %s not found for repo-hooks' % |
| 426 | (repo_hooks_project)) |
| 427 | |
| 428 | # Store the enabled hooks in the Project object. |
| 429 | self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 430 | if node.nodeName == 'remove-project': |
| 431 | name = self._reqatt(node, 'name') |
| 432 | try: |
| 433 | del self._projects[name] |
| 434 | except KeyError: |
| 435 | raise ManifestParseError( |
| 436 | 'project %s not found' % |
| 437 | (name)) |
| 438 | |
| 439 | # If the manifest removes the hooks project, treat it as if it deleted |
| 440 | # the repo-hooks element too. |
| 441 | if self._repo_hooks_project and (self._repo_hooks_project.name == name): |
| 442 | self._repo_hooks_project = None |
| 443 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 444 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 445 | def _AddMetaProjectMirror(self, m): |
| 446 | name = None |
| 447 | m_url = m.GetRemote(m.remote.name).url |
| 448 | if m_url.endswith('/.git'): |
| 449 | raise ManifestParseError, 'refusing to mirror %s' % m_url |
| 450 | |
| 451 | if self._default and self._default.remote: |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 452 | url = self._default.remote.resolvedFetchUrl |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 453 | if not url.endswith('/'): |
| 454 | url += '/' |
| 455 | if m_url.startswith(url): |
| 456 | remote = self._default.remote |
| 457 | name = m_url[len(url):] |
| 458 | |
| 459 | if name is None: |
| 460 | s = m_url.rindex('/') + 1 |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 461 | manifestUrl = self.manifestProject.config.GetString('remote.origin.url') |
Shawn O. Pearce | f35b2d9 | 2012-08-02 11:46:22 -0700 | [diff] [blame] | 462 | remote = _XmlRemote('origin', fetch=m_url[:s], manifestUrl=manifestUrl) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 463 | name = m_url[s:] |
| 464 | |
| 465 | if name.endswith('.git'): |
| 466 | name = name[:-4] |
| 467 | |
| 468 | if name not in self._projects: |
| 469 | m.PreSync() |
| 470 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 471 | project = Project(manifest = self, |
| 472 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 473 | remote = remote.ToRemoteSpec(name), |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 474 | gitdir = gitdir, |
| 475 | worktree = None, |
| 476 | relpath = None, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 477 | revisionExpr = m.revisionExpr, |
| 478 | revisionId = None) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 479 | self._projects[project.name] = project |
| 480 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 481 | def _ParseRemote(self, node): |
| 482 | """ |
| 483 | reads a <remote> element from the manifest file |
| 484 | """ |
| 485 | name = self._reqatt(node, 'name') |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 486 | alias = node.getAttribute('alias') |
| 487 | if alias == '': |
| 488 | alias = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 489 | fetch = self._reqatt(node, 'fetch') |
| 490 | review = node.getAttribute('review') |
Shawn O. Pearce | ae6e094 | 2008-11-06 10:25:35 -0800 | [diff] [blame] | 491 | if review == '': |
| 492 | review = None |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 493 | manifestUrl = self.manifestProject.config.GetString('remote.origin.url') |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 494 | return _XmlRemote(name, alias, fetch, manifestUrl, review) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 495 | |
| 496 | def _ParseDefault(self, node): |
| 497 | """ |
| 498 | reads a <default> element from the manifest file |
| 499 | """ |
| 500 | d = _Default() |
| 501 | d.remote = self._get_remote(node) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 502 | d.revisionExpr = node.getAttribute('revision') |
| 503 | if d.revisionExpr == '': |
| 504 | d.revisionExpr = None |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 505 | |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 506 | sync_j = node.getAttribute('sync-j') |
| 507 | if sync_j == '' or sync_j is None: |
| 508 | d.sync_j = 1 |
| 509 | else: |
| 510 | d.sync_j = int(sync_j) |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 511 | |
| 512 | sync_c = node.getAttribute('sync-c') |
| 513 | if not sync_c: |
| 514 | d.sync_c = False |
| 515 | else: |
| 516 | d.sync_c = sync_c.lower() in ("yes", "true", "1") |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 517 | return d |
| 518 | |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 519 | def _ParseNotice(self, node): |
| 520 | """ |
| 521 | reads a <notice> element from the manifest file |
| 522 | |
| 523 | The <notice> element is distinct from other tags in the XML in that the |
| 524 | data is conveyed between the start and end tag (it's not an empty-element |
| 525 | tag). |
| 526 | |
| 527 | The white space (carriage returns, indentation) for the notice element is |
| 528 | relevant and is parsed in a way that is based on how python docstrings work. |
| 529 | In fact, the code is remarkably similar to here: |
| 530 | http://www.python.org/dev/peps/pep-0257/ |
| 531 | """ |
| 532 | # Get the data out of the node... |
| 533 | notice = node.childNodes[0].data |
| 534 | |
| 535 | # Figure out minimum indentation, skipping the first line (the same line |
| 536 | # as the <notice> tag)... |
| 537 | minIndent = sys.maxint |
| 538 | lines = notice.splitlines() |
| 539 | for line in lines[1:]: |
| 540 | lstrippedLine = line.lstrip() |
| 541 | if lstrippedLine: |
| 542 | indent = len(line) - len(lstrippedLine) |
| 543 | minIndent = min(indent, minIndent) |
| 544 | |
| 545 | # Strip leading / trailing blank lines and also indentation. |
| 546 | cleanLines = [lines[0].strip()] |
| 547 | for line in lines[1:]: |
| 548 | cleanLines.append(line[minIndent:].rstrip()) |
| 549 | |
| 550 | # Clear completely blank lines from front and back... |
| 551 | while cleanLines and not cleanLines[0]: |
| 552 | del cleanLines[0] |
| 553 | while cleanLines and not cleanLines[-1]: |
| 554 | del cleanLines[-1] |
| 555 | |
| 556 | return '\n'.join(cleanLines) |
| 557 | |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 558 | def _ParseProject(self, node): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 559 | """ |
| 560 | reads a <project> element from the manifest file |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 561 | """ |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 562 | name = self._reqatt(node, 'name') |
| 563 | |
| 564 | remote = self._get_remote(node) |
| 565 | if remote is None: |
| 566 | remote = self._default.remote |
| 567 | if remote is None: |
| 568 | raise ManifestParseError, \ |
| 569 | "no remote for project %s within %s" % \ |
| 570 | (name, self.manifestFile) |
| 571 | |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 572 | revisionExpr = node.getAttribute('revision') |
| 573 | if not revisionExpr: |
| 574 | revisionExpr = self._default.revisionExpr |
| 575 | if not revisionExpr: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 576 | raise ManifestParseError, \ |
| 577 | "no revision for project %s within %s" % \ |
| 578 | (name, self.manifestFile) |
| 579 | |
| 580 | path = node.getAttribute('path') |
| 581 | if not path: |
| 582 | path = name |
| 583 | if path.startswith('/'): |
| 584 | raise ManifestParseError, \ |
| 585 | "project %s path cannot be absolute in %s" % \ |
| 586 | (name, self.manifestFile) |
| 587 | |
Mike Pontillo | d315382 | 2012-02-28 11:53:24 -0800 | [diff] [blame] | 588 | rebase = node.getAttribute('rebase') |
| 589 | if not rebase: |
| 590 | rebase = True |
| 591 | else: |
| 592 | rebase = rebase.lower() in ("yes", "true", "1") |
| 593 | |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 594 | sync_c = node.getAttribute('sync-c') |
| 595 | if not sync_c: |
| 596 | sync_c = False |
| 597 | else: |
| 598 | sync_c = sync_c.lower() in ("yes", "true", "1") |
| 599 | |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 600 | upstream = node.getAttribute('upstream') |
| 601 | |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 602 | groups = '' |
| 603 | if node.hasAttribute('groups'): |
| 604 | groups = node.getAttribute('groups') |
David Pursehouse | 1d947b3 | 2012-10-25 12:23:11 +0900 | [diff] [blame] | 605 | groups = [x for x in re.split(r'[,\s]+', groups) if x] |
Brian Harring | 7da1314 | 2012-06-15 02:24:20 -0700 | [diff] [blame] | 606 | |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 607 | default_groups = ['all', 'name:%s' % name, 'path:%s' % path] |
Che-Liang Chiou | 69998b0 | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 608 | groups.extend(set(default_groups).difference(groups)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 609 | |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 610 | if self.IsMirror: |
| 611 | worktree = None |
| 612 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 613 | else: |
| 614 | worktree = os.path.join(self.topdir, path).replace('\\', '/') |
| 615 | gitdir = os.path.join(self.repodir, 'projects/%s.git' % path) |
| 616 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 617 | project = Project(manifest = self, |
| 618 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 619 | remote = remote.ToRemoteSpec(name), |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 620 | gitdir = gitdir, |
| 621 | worktree = worktree, |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 622 | relpath = path, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 623 | revisionExpr = revisionExpr, |
Mike Pontillo | d315382 | 2012-02-28 11:53:24 -0800 | [diff] [blame] | 624 | revisionId = None, |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 625 | rebase = rebase, |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 626 | groups = groups, |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 627 | sync_c = sync_c, |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 628 | upstream = upstream) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 629 | |
| 630 | for n in node.childNodes: |
Shawn O. Pearce | 242b526 | 2009-05-19 13:00:29 -0700 | [diff] [blame] | 631 | if n.nodeName == 'copyfile': |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 632 | self._ParseCopyFile(project, n) |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 633 | if n.nodeName == 'annotation': |
| 634 | self._ParseAnnotation(project, n) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 635 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 636 | return project |
| 637 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 638 | def _ParseCopyFile(self, project, node): |
| 639 | src = self._reqatt(node, 'src') |
| 640 | dest = self._reqatt(node, 'dest') |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 641 | if not self.IsMirror: |
| 642 | # src is project relative; |
| 643 | # dest is relative to the top of the tree |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 644 | 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] | 645 | |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 646 | def _ParseAnnotation(self, project, node): |
| 647 | name = self._reqatt(node, 'name') |
| 648 | value = self._reqatt(node, 'value') |
| 649 | try: |
| 650 | keep = self._reqatt(node, 'keep').lower() |
| 651 | except ManifestParseError: |
| 652 | keep = "true" |
| 653 | if keep != "true" and keep != "false": |
| 654 | raise ManifestParseError, "optional \"keep\" attribute must be \"true\" or \"false\"" |
| 655 | project.AddAnnotation(name, value, keep) |
| 656 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 657 | def _get_remote(self, node): |
| 658 | name = node.getAttribute('remote') |
| 659 | if not name: |
| 660 | return None |
| 661 | |
| 662 | v = self._remotes.get(name) |
| 663 | if not v: |
| 664 | raise ManifestParseError, \ |
| 665 | "remote %s not defined in %s" % \ |
| 666 | (name, self.manifestFile) |
| 667 | return v |
| 668 | |
| 669 | def _reqatt(self, node, attname): |
| 670 | """ |
| 671 | reads a required attribute from the node. |
| 672 | """ |
| 673 | v = node.getAttribute(attname) |
| 674 | if not v: |
| 675 | raise ManifestParseError, \ |
| 676 | "no %s in <%s> within %s" % \ |
| 677 | (attname, node.nodeName, self.manifestFile) |
| 678 | return v |