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