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