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