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 |
David Pursehouse | 59bbb58 | 2013-05-17 10:49:33 +0900 | [diff] [blame] | 21 | import xml.dom.minidom |
| 22 | |
| 23 | from pyversion import is_python3 |
| 24 | if is_python3(): |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 25 | import urllib.parse |
David Pursehouse | 59bbb58 | 2013-05-17 10:49:33 +0900 | [diff] [blame] | 26 | else: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 27 | import imp |
| 28 | import urlparse |
| 29 | urllib = imp.new_module('urllib') |
Chirayu Desai | db2ad9d | 2013-06-11 13:42:25 +0530 | [diff] [blame] | 30 | urllib.parse = urlparse |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 31 | |
David Pursehouse | e15c65a | 2012-08-22 10:46:11 +0900 | [diff] [blame] | 32 | from git_config import GitConfig |
David Pursehouse | e00aa6b | 2012-09-11 14:33:51 +0900 | [diff] [blame] | 33 | from git_refs import R_HEADS, HEAD |
| 34 | from project import RemoteSpec, Project, MetaProject |
Julien Campergue | dd65422 | 2014-01-09 16:21:37 +0100 | [diff] [blame] | 35 | from error import ManifestParseError, ManifestInvalidRevisionError |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 36 | |
| 37 | MANIFEST_FILE_NAME = 'manifest.xml' |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 38 | LOCAL_MANIFEST_NAME = 'local_manifest.xml' |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 39 | LOCAL_MANIFESTS_DIR_NAME = 'local_manifests' |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 40 | |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 41 | urllib.parse.uses_relative.extend(['ssh', 'git']) |
| 42 | urllib.parse.uses_netloc.extend(['ssh', 'git']) |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 43 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 44 | class _Default(object): |
| 45 | """Project defaults within the manifest.""" |
| 46 | |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 47 | revisionExpr = None |
Conley Owens | b6a16e6 | 2013-09-25 15:06:09 -0700 | [diff] [blame] | 48 | destBranchExpr = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 49 | remote = None |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 50 | sync_j = 1 |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 51 | sync_c = False |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 52 | sync_s = False |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 53 | |
Julien Campergue | 7487992 | 2013-10-09 14:38:46 +0200 | [diff] [blame] | 54 | def __eq__(self, other): |
| 55 | return self.__dict__ == other.__dict__ |
| 56 | |
| 57 | def __ne__(self, other): |
| 58 | return self.__dict__ != other.__dict__ |
| 59 | |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 60 | class _XmlRemote(object): |
| 61 | def __init__(self, |
| 62 | name, |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 63 | alias=None, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 64 | fetch=None, |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 65 | manifestUrl=None, |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 66 | review=None, |
| 67 | revision=None): |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 68 | self.name = name |
| 69 | self.fetchUrl = fetch |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 70 | self.manifestUrl = manifestUrl |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 71 | self.remoteAlias = alias |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 72 | self.reviewUrl = review |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 73 | self.revision = revision |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 74 | self.resolvedFetchUrl = self._resolveFetchUrl() |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 75 | |
David Pursehouse | 717ece9 | 2012-11-13 08:49:16 +0900 | [diff] [blame] | 76 | def __eq__(self, other): |
| 77 | return self.__dict__ == other.__dict__ |
| 78 | |
| 79 | def __ne__(self, other): |
| 80 | return self.__dict__ != other.__dict__ |
| 81 | |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 82 | def _resolveFetchUrl(self): |
| 83 | url = self.fetchUrl.rstrip('/') |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 84 | manifestUrl = self.manifestUrl.rstrip('/') |
Conley Owens | 2d0f508 | 2014-01-31 15:03:51 -0800 | [diff] [blame] | 85 | # urljoin will gets confused over quite a few things. The ones we care |
| 86 | # about here are: |
| 87 | # * no scheme in the base url, like <hostname:port> |
| 88 | # * persistent-https:// |
T.R. Fullhart | 4863307 | 2014-09-10 13:44:39 -0700 | [diff] [blame] | 89 | # * rpc:// |
Conley Owens | 2d0f508 | 2014-01-31 15:03:51 -0800 | [diff] [blame] | 90 | # We handle this by replacing these with obscure protocols |
| 91 | # and then replacing them with the original when we are done. |
| 92 | # gopher -> <none> |
| 93 | # wais -> persistent-https |
T.R. Fullhart | 4863307 | 2014-09-10 13:44:39 -0700 | [diff] [blame] | 94 | # nntp -> rpc |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 95 | if manifestUrl.find(':') != manifestUrl.find('/') - 1: |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 96 | manifestUrl = 'gopher://' + manifestUrl |
Conley Owens | 2d0f508 | 2014-01-31 15:03:51 -0800 | [diff] [blame] | 97 | manifestUrl = re.sub(r'^persistent-https://', 'wais://', manifestUrl) |
T.R. Fullhart | 4863307 | 2014-09-10 13:44:39 -0700 | [diff] [blame] | 98 | manifestUrl = re.sub(r'^rpc://', 'nntp://', manifestUrl) |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 99 | url = urllib.parse.urljoin(manifestUrl, url) |
Shawn Pearce | a9f11b3 | 2013-01-02 15:40:48 -0800 | [diff] [blame] | 100 | url = re.sub(r'^gopher://', '', url) |
Conley Owens | 2d0f508 | 2014-01-31 15:03:51 -0800 | [diff] [blame] | 101 | url = re.sub(r'^wais://', 'persistent-https://', url) |
T.R. Fullhart | 4863307 | 2014-09-10 13:44:39 -0700 | [diff] [blame] | 102 | url = re.sub(r'^nntp://', 'rpc://', url) |
Shawn Pearce | a9f11b3 | 2013-01-02 15:40:48 -0800 | [diff] [blame] | 103 | return url |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 104 | |
| 105 | def ToRemoteSpec(self, projectName): |
Conley Owens | 9d8f914 | 2011-10-20 14:36:35 -0700 | [diff] [blame] | 106 | url = self.resolvedFetchUrl.rstrip('/') + '/' + projectName |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 107 | remoteName = self.name |
Conley Owens | 1e7ab2a | 2013-10-08 17:26:57 -0700 | [diff] [blame] | 108 | if self.remoteAlias: |
David Pursehouse | 37128b6 | 2013-10-15 10:48:40 +0900 | [diff] [blame] | 109 | remoteName = self.remoteAlias |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 110 | return RemoteSpec(remoteName, url, self.reviewUrl) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 111 | |
Shawn O. Pearce | c8a300f | 2009-05-18 13:19:57 -0700 | [diff] [blame] | 112 | class XmlManifest(object): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 113 | """manages the repo configuration file""" |
| 114 | |
| 115 | def __init__(self, repodir): |
| 116 | self.repodir = os.path.abspath(repodir) |
| 117 | self.topdir = os.path.dirname(self.repodir) |
| 118 | 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] | 119 | self.globalConfig = GitConfig.ForUser() |
David Pursehouse | 4eb285c | 2013-02-14 16:28:44 +0900 | [diff] [blame] | 120 | self.localManifestWarning = False |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 121 | |
| 122 | self.repoProject = MetaProject(self, 'repo', |
| 123 | gitdir = os.path.join(repodir, 'repo/.git'), |
| 124 | worktree = os.path.join(repodir, 'repo')) |
| 125 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 126 | self.manifestProject = MetaProject(self, 'manifests', |
Shawn O. Pearce | f5c25a6 | 2008-11-04 08:11:53 -0800 | [diff] [blame] | 127 | gitdir = os.path.join(repodir, 'manifests.git'), |
| 128 | worktree = os.path.join(repodir, 'manifests')) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 129 | |
| 130 | self._Unload() |
| 131 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 132 | def Override(self, name): |
| 133 | """Use a different manifest, just for the current instantiation. |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 134 | """ |
| 135 | path = os.path.join(self.manifestProject.worktree, name) |
| 136 | if not os.path.isfile(path): |
| 137 | raise ManifestParseError('manifest %s not found' % name) |
| 138 | |
| 139 | old = self.manifestFile |
| 140 | try: |
| 141 | self.manifestFile = path |
| 142 | self._Unload() |
| 143 | self._Load() |
| 144 | finally: |
| 145 | self.manifestFile = old |
| 146 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 147 | def Link(self, name): |
| 148 | """Update the repo metadata to use a different manifest. |
| 149 | """ |
| 150 | self.Override(name) |
| 151 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 152 | try: |
Sebastian Frias | 223bf96 | 2012-11-21 19:09:25 +0100 | [diff] [blame] | 153 | if os.path.lexists(self.manifestFile): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 154 | os.remove(self.manifestFile) |
| 155 | os.symlink('manifests/%s' % name, self.manifestFile) |
Sebastian Frias | 223bf96 | 2012-11-21 19:09:25 +0100 | [diff] [blame] | 156 | except OSError as e: |
| 157 | raise ManifestParseError('cannot link manifest %s: %s' % (name, str(e))) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 158 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 159 | def _RemoteToXml(self, r, doc, root): |
| 160 | e = doc.createElement('remote') |
| 161 | root.appendChild(e) |
| 162 | e.setAttribute('name', r.name) |
| 163 | e.setAttribute('fetch', r.fetchUrl) |
Conley Owens | 1e7ab2a | 2013-10-08 17:26:57 -0700 | [diff] [blame] | 164 | if r.remoteAlias is not None: |
| 165 | e.setAttribute('alias', r.remoteAlias) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 166 | if r.reviewUrl is not None: |
| 167 | e.setAttribute('review', r.reviewUrl) |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 168 | if r.revision is not None: |
| 169 | e.setAttribute('revision', r.revision) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 170 | |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 171 | def _ParseGroups(self, groups): |
| 172 | return [x for x in re.split(r'[,\s]+', groups) if x] |
| 173 | |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 174 | def Save(self, fd, peg_rev=False, peg_rev_upstream=True): |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 175 | """Write the current manifest out to the given file descriptor. |
| 176 | """ |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 177 | mp = self.manifestProject |
| 178 | |
| 179 | groups = mp.config.GetString('manifest.groups') |
Matt Gumbel | 0c635bb | 2012-12-21 10:14:53 -0800 | [diff] [blame] | 180 | if groups: |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 181 | groups = self._ParseGroups(groups) |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 182 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 183 | doc = xml.dom.minidom.Document() |
| 184 | root = doc.createElement('manifest') |
| 185 | doc.appendChild(root) |
| 186 | |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 187 | # Save out the notice. There's a little bit of work here to give it the |
| 188 | # right whitespace, which assumes that the notice is automatically indented |
| 189 | # by 4 by minidom. |
| 190 | if self.notice: |
| 191 | notice_element = root.appendChild(doc.createElement('notice')) |
| 192 | notice_lines = self.notice.splitlines() |
| 193 | indented_notice = ('\n'.join(" "*4 + line for line in notice_lines))[4:] |
| 194 | notice_element.appendChild(doc.createTextNode(indented_notice)) |
| 195 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 196 | d = self.default |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 197 | |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 198 | for r in sorted(self.remotes): |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 199 | self._RemoteToXml(self.remotes[r], doc, root) |
| 200 | if self.remotes: |
| 201 | root.appendChild(doc.createTextNode('')) |
| 202 | |
| 203 | have_default = False |
| 204 | e = doc.createElement('default') |
| 205 | if d.remote: |
| 206 | have_default = True |
| 207 | e.setAttribute('remote', d.remote.name) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 208 | if d.revisionExpr: |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 209 | have_default = True |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 210 | e.setAttribute('revision', d.revisionExpr) |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 211 | if d.sync_j > 1: |
| 212 | have_default = True |
| 213 | e.setAttribute('sync-j', '%d' % d.sync_j) |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 214 | if d.sync_c: |
| 215 | have_default = True |
| 216 | e.setAttribute('sync-c', 'true') |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 217 | if d.sync_s: |
| 218 | have_default = True |
| 219 | e.setAttribute('sync-s', 'true') |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 220 | if have_default: |
| 221 | root.appendChild(e) |
| 222 | root.appendChild(doc.createTextNode('')) |
| 223 | |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 224 | if self._manifest_server: |
| 225 | e = doc.createElement('manifest-server') |
| 226 | e.setAttribute('url', self._manifest_server) |
| 227 | root.appendChild(e) |
| 228 | root.appendChild(doc.createTextNode('')) |
| 229 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 230 | def output_projects(parent, parent_node, projects): |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 231 | for project_name in projects: |
| 232 | for project in self._projects[project_name]: |
| 233 | output_project(parent, parent_node, project) |
Che-Liang Chiou | 69998b0 | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 234 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 235 | def output_project(parent, parent_node, p): |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 236 | if not p.MatchesGroups(groups): |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 237 | return |
| 238 | |
| 239 | name = p.name |
| 240 | relpath = p.relpath |
| 241 | if parent: |
| 242 | name = self._UnjoinName(parent.name, name) |
| 243 | relpath = self._UnjoinRelpath(parent.relpath, relpath) |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 244 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 245 | e = doc.createElement('project') |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 246 | parent_node.appendChild(e) |
| 247 | e.setAttribute('name', name) |
| 248 | if relpath != name: |
| 249 | e.setAttribute('path', relpath) |
Conley Owens | a17d7af | 2013-10-16 14:38:09 -0700 | [diff] [blame] | 250 | remoteName = None |
| 251 | if d.remote: |
Conley Owens | ce201a5 | 2013-10-16 14:42:42 -0700 | [diff] [blame] | 252 | remoteName = d.remote.remoteAlias or d.remote.name |
Conley Owens | 1e7ab2a | 2013-10-08 17:26:57 -0700 | [diff] [blame] | 253 | if not d.remote or p.remote.name != remoteName: |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 254 | remoteName = p.remote.name |
| 255 | e.setAttribute('remote', remoteName) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 256 | if peg_rev: |
| 257 | if self.IsMirror: |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 258 | value = p.bare_git.rev_parse(p.revisionExpr + '^0') |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 259 | else: |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 260 | value = p.work_git.rev_parse(HEAD + '^0') |
| 261 | e.setAttribute('revision', value) |
| 262 | if peg_rev_upstream and value != p.revisionExpr: |
| 263 | # Only save the origin if the origin is not a sha1, and the default |
| 264 | # isn't our value, and the if the default doesn't already have that |
| 265 | # covered. |
| 266 | e.setAttribute('upstream', p.revisionExpr) |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 267 | else: |
| 268 | revision = self.remotes[remoteName].revision or d.revisionExpr |
| 269 | if not revision or revision != p.revisionExpr: |
| 270 | e.setAttribute('revision', p.revisionExpr) |
Mani Chandel | 7a91d51 | 2014-07-24 16:27:08 +0530 | [diff] [blame] | 271 | if p.upstream and p.upstream != p.revisionExpr: |
| 272 | e.setAttribute('upstream', p.upstream) |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 273 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 274 | for c in p.copyfiles: |
| 275 | ce = doc.createElement('copyfile') |
| 276 | ce.setAttribute('src', c.src) |
| 277 | ce.setAttribute('dest', c.dest) |
| 278 | e.appendChild(ce) |
| 279 | |
Jeff Hamilton | e0df232 | 2014-04-21 17:10:59 -0500 | [diff] [blame] | 280 | for l in p.linkfiles: |
| 281 | le = doc.createElement('linkfile') |
| 282 | le.setAttribute('src', l.src) |
| 283 | le.setAttribute('dest', l.dest) |
| 284 | e.appendChild(le) |
| 285 | |
Conley Owens | bb1b5f5 | 2012-08-13 13:11:18 -0700 | [diff] [blame] | 286 | default_groups = ['all', 'name:%s' % p.name, 'path:%s' % p.relpath] |
Dmitry Fink | 17f85ea | 2012-08-06 14:52:29 -0700 | [diff] [blame] | 287 | 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] | 288 | if egroups: |
| 289 | e.setAttribute('groups', ','.join(egroups)) |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 290 | |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 291 | for a in p.annotations: |
| 292 | if a.keep == "true": |
| 293 | ae = doc.createElement('annotation') |
| 294 | ae.setAttribute('name', a.name) |
| 295 | ae.setAttribute('value', a.value) |
| 296 | e.appendChild(ae) |
| 297 | |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 298 | if p.sync_c: |
| 299 | e.setAttribute('sync-c', 'true') |
| 300 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 301 | if p.sync_s: |
| 302 | e.setAttribute('sync-s', 'true') |
| 303 | |
| 304 | if p.subprojects: |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 305 | subprojects = set(subp.name for subp in p.subprojects) |
| 306 | output_projects(p, e, list(sorted(subprojects))) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 307 | |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 308 | projects = set(p.name for p in self._paths.values() if not p.parent) |
| 309 | output_projects(None, root, list(sorted(projects))) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 310 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 311 | if self._repo_hooks_project: |
| 312 | root.appendChild(doc.createTextNode('')) |
| 313 | e = doc.createElement('repo-hooks') |
| 314 | e.setAttribute('in-project', self._repo_hooks_project.name) |
| 315 | e.setAttribute('enabled-list', |
| 316 | ' '.join(self._repo_hooks_project.enabled_repo_hooks)) |
| 317 | root.appendChild(e) |
| 318 | |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 319 | doc.writexml(fd, '', ' ', '\n', 'UTF-8') |
| 320 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 321 | @property |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 322 | def paths(self): |
| 323 | self._Load() |
| 324 | return self._paths |
| 325 | |
| 326 | @property |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 327 | def projects(self): |
| 328 | self._Load() |
Anthony King | d58bfe5 | 2014-05-05 23:30:49 +0100 | [diff] [blame] | 329 | return list(self._paths.values()) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 330 | |
| 331 | @property |
| 332 | def remotes(self): |
| 333 | self._Load() |
| 334 | return self._remotes |
| 335 | |
| 336 | @property |
| 337 | def default(self): |
| 338 | self._Load() |
| 339 | return self._default |
| 340 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 341 | @property |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 342 | def repo_hooks_project(self): |
| 343 | self._Load() |
| 344 | return self._repo_hooks_project |
| 345 | |
| 346 | @property |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 347 | def notice(self): |
| 348 | self._Load() |
| 349 | return self._notice |
| 350 | |
| 351 | @property |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 352 | def manifest_server(self): |
| 353 | self._Load() |
Shawn O. Pearce | 34fb20f | 2011-11-30 13:41:02 -0800 | [diff] [blame] | 354 | return self._manifest_server |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 355 | |
| 356 | @property |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 357 | def IsMirror(self): |
| 358 | return self.manifestProject.config.GetBoolean('repo.mirror') |
| 359 | |
Julien Campergue | 335f5ef | 2013-10-16 11:02:35 +0200 | [diff] [blame] | 360 | @property |
| 361 | def IsArchive(self): |
| 362 | return self.manifestProject.config.GetBoolean('repo.archive') |
| 363 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 364 | def _Unload(self): |
| 365 | self._loaded = False |
| 366 | self._projects = {} |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 367 | self._paths = {} |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 368 | self._remotes = {} |
| 369 | self._default = None |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 370 | self._repo_hooks_project = None |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 371 | self._notice = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 372 | self.branch = None |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 373 | self._manifest_server = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 374 | |
| 375 | def _Load(self): |
| 376 | if not self._loaded: |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 377 | m = self.manifestProject |
| 378 | b = m.GetBranch(m.CurrentBranch).merge |
Shawn O. Pearce | 21c5c34 | 2009-06-25 16:47:30 -0700 | [diff] [blame] | 379 | if b is not None and b.startswith(R_HEADS): |
Shawn O. Pearce | 2450a29 | 2008-11-04 08:22:07 -0800 | [diff] [blame] | 380 | b = b[len(R_HEADS):] |
| 381 | self.branch = b |
| 382 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 383 | nodes = [] |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 384 | nodes.append(self._ParseManifestXml(self.manifestFile, |
| 385 | self.manifestProject.worktree)) |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 386 | |
| 387 | local = os.path.join(self.repodir, LOCAL_MANIFEST_NAME) |
| 388 | if os.path.exists(local): |
David Pursehouse | 4eb285c | 2013-02-14 16:28:44 +0900 | [diff] [blame] | 389 | if not self.localManifestWarning: |
| 390 | self.localManifestWarning = True |
| 391 | print('warning: %s is deprecated; put local manifests in `%s` instead' |
| 392 | % (LOCAL_MANIFEST_NAME, os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME)), |
| 393 | file=sys.stderr) |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 394 | nodes.append(self._ParseManifestXml(local, self.repodir)) |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 395 | |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 396 | local_dir = os.path.abspath(os.path.join(self.repodir, LOCAL_MANIFESTS_DIR_NAME)) |
| 397 | try: |
David Pursehouse | 52f1e5d | 2012-11-14 04:53:24 +0900 | [diff] [blame] | 398 | for local_file in sorted(os.listdir(local_dir)): |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 399 | if local_file.endswith('.xml'): |
David Pursehouse | 5f434ed | 2012-11-22 13:48:10 +0900 | [diff] [blame] | 400 | local = os.path.join(local_dir, local_file) |
| 401 | nodes.append(self._ParseManifestXml(local, self.repodir)) |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 402 | except OSError: |
| 403 | pass |
| 404 | |
Joe Onorato | 26e2475 | 2013-01-11 12:35:53 -0800 | [diff] [blame] | 405 | try: |
| 406 | self._ParseManifest(nodes) |
| 407 | except ManifestParseError as e: |
| 408 | # There was a problem parsing, unload ourselves in case they catch |
| 409 | # this error and try again later, we will show the correct error |
| 410 | self._Unload() |
| 411 | raise e |
Shawn O. Pearce | 5cc6679 | 2008-10-23 16:19:27 -0700 | [diff] [blame] | 412 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 413 | if self.IsMirror: |
| 414 | self._AddMetaProjectMirror(self.repoProject) |
| 415 | self._AddMetaProjectMirror(self.manifestProject) |
| 416 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 417 | self._loaded = True |
| 418 | |
Brian Harring | 475a47d | 2012-06-07 20:05:35 -0700 | [diff] [blame] | 419 | def _ParseManifestXml(self, path, include_root): |
David Pursehouse | f7fc8a9 | 2012-11-13 04:00:28 +0900 | [diff] [blame] | 420 | try: |
| 421 | root = xml.dom.minidom.parse(path) |
David Pursehouse | 2d5a0df | 2012-11-13 02:50:36 +0900 | [diff] [blame] | 422 | except (OSError, xml.parsers.expat.ExpatError) as e: |
David Pursehouse | f7fc8a9 | 2012-11-13 04:00:28 +0900 | [diff] [blame] | 423 | raise ManifestParseError("error parsing manifest %s: %s" % (path, e)) |
| 424 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 425 | if not root or not root.childNodes: |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 426 | raise ManifestParseError("no root node in %s" % (path,)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 427 | |
Jooncheol Park | 34acdd2 | 2012-08-27 02:25:59 +0900 | [diff] [blame] | 428 | for manifest in root.childNodes: |
| 429 | if manifest.nodeName == 'manifest': |
| 430 | break |
| 431 | else: |
Brian Harring | 2644874 | 2011-04-28 05:04:41 -0700 | [diff] [blame] | 432 | raise ManifestParseError("no <manifest> in %s" % (path,)) |
| 433 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 434 | nodes = [] |
David Pursehouse | 4f7bdea | 2012-10-22 12:50:15 +0900 | [diff] [blame] | 435 | for node in manifest.childNodes: # pylint:disable=W0631 |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 436 | # We only get here if manifest is initialised |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 437 | if node.nodeName == 'include': |
| 438 | name = self._reqatt(node, 'name') |
| 439 | fp = os.path.join(include_root, name) |
| 440 | if not os.path.isfile(fp): |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 441 | raise ManifestParseError("include %s doesn't exist or isn't a file" |
| 442 | % (name,)) |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 443 | try: |
| 444 | nodes.extend(self._ParseManifestXml(fp, include_root)) |
| 445 | # should isolate this to the exact exception, but that's |
| 446 | # tricky. actual parsing implementation may vary. |
| 447 | except (KeyboardInterrupt, RuntimeError, SystemExit): |
| 448 | raise |
| 449 | except Exception as e: |
| 450 | raise ManifestParseError( |
| 451 | "failed parsing included manifest %s: %s", (name, e)) |
| 452 | else: |
| 453 | nodes.append(node) |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 454 | return nodes |
Shawn O. Pearce | 03eaf07 | 2008-11-20 11:42:22 -0800 | [diff] [blame] | 455 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 456 | def _ParseManifest(self, node_list): |
| 457 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 458 | if node.nodeName == 'remote': |
| 459 | remote = self._ParseRemote(node) |
David Pursehouse | 717ece9 | 2012-11-13 08:49:16 +0900 | [diff] [blame] | 460 | if remote: |
| 461 | if remote.name in self._remotes: |
| 462 | if remote != self._remotes[remote.name]: |
| 463 | raise ManifestParseError( |
| 464 | 'remote %s already exists with different attributes' % |
| 465 | (remote.name)) |
| 466 | else: |
| 467 | self._remotes[remote.name] = remote |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 468 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 469 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 470 | if node.nodeName == 'default': |
Julien Campergue | 7487992 | 2013-10-09 14:38:46 +0200 | [diff] [blame] | 471 | new_default = self._ParseDefault(node) |
| 472 | if self._default is None: |
| 473 | self._default = new_default |
| 474 | elif new_default != self._default: |
David Pursehouse | 37128b6 | 2013-10-15 10:48:40 +0900 | [diff] [blame] | 475 | raise ManifestParseError('duplicate default in %s' % |
| 476 | (self.manifestFile)) |
Julien Campergue | 7487992 | 2013-10-09 14:38:46 +0200 | [diff] [blame] | 477 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 478 | if self._default is None: |
| 479 | self._default = _Default() |
| 480 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 481 | for node in itertools.chain(*node_list): |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 482 | if node.nodeName == 'notice': |
| 483 | if self._notice is not None: |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 484 | raise ManifestParseError( |
| 485 | 'duplicate notice in %s' % |
| 486 | (self.manifestFile)) |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 487 | self._notice = self._ParseNotice(node) |
| 488 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 489 | for node in itertools.chain(*node_list): |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 490 | if node.nodeName == 'manifest-server': |
| 491 | url = self._reqatt(node, 'url') |
| 492 | if self._manifest_server is not None: |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 493 | raise ManifestParseError( |
| 494 | 'duplicate manifest-server in %s' % |
| 495 | (self.manifestFile)) |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 496 | self._manifest_server = url |
| 497 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 498 | def recursively_add_projects(project): |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 499 | projects = self._projects.setdefault(project.name, []) |
| 500 | if project.relpath is None: |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 501 | raise ManifestParseError( |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 502 | 'missing path for %s in %s' % |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 503 | (project.name, self.manifestFile)) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 504 | if project.relpath in self._paths: |
| 505 | raise ManifestParseError( |
| 506 | 'duplicate path %s in %s' % |
| 507 | (project.relpath, self.manifestFile)) |
| 508 | self._paths[project.relpath] = project |
| 509 | projects.append(project) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 510 | for subproject in project.subprojects: |
| 511 | recursively_add_projects(subproject) |
| 512 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 513 | for node in itertools.chain(*node_list): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 514 | if node.nodeName == 'project': |
| 515 | project = self._ParseProject(node) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 516 | recursively_add_projects(project) |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 517 | if node.nodeName == 'extend-project': |
| 518 | name = self._reqatt(node, 'name') |
| 519 | |
| 520 | if name not in self._projects: |
| 521 | raise ManifestParseError('extend-project element specifies non-existent ' |
| 522 | 'project: %s' % name) |
| 523 | |
| 524 | path = node.getAttribute('path') |
| 525 | groups = node.getAttribute('groups') |
| 526 | if groups: |
| 527 | groups = self._ParseGroups(groups) |
| 528 | |
| 529 | for p in self._projects[name]: |
| 530 | if path and p.relpath != path: |
| 531 | continue |
| 532 | if groups: |
| 533 | p.groups.extend(groups) |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 534 | if node.nodeName == 'repo-hooks': |
| 535 | # Get the name of the project and the (space-separated) list of enabled. |
| 536 | repo_hooks_project = self._reqatt(node, 'in-project') |
| 537 | enabled_repo_hooks = self._reqatt(node, 'enabled-list').split() |
| 538 | |
| 539 | # Only one project can be the hooks project |
| 540 | if self._repo_hooks_project is not None: |
| 541 | raise ManifestParseError( |
| 542 | 'duplicate repo-hooks in %s' % |
| 543 | (self.manifestFile)) |
| 544 | |
| 545 | # Store a reference to the Project. |
| 546 | try: |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 547 | repo_hooks_projects = self._projects[repo_hooks_project] |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 548 | except KeyError: |
| 549 | raise ManifestParseError( |
| 550 | 'project %s not found for repo-hooks' % |
| 551 | (repo_hooks_project)) |
| 552 | |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 553 | if len(repo_hooks_projects) != 1: |
| 554 | raise ManifestParseError( |
| 555 | 'internal error parsing repo-hooks in %s' % |
| 556 | (self.manifestFile)) |
| 557 | self._repo_hooks_project = repo_hooks_projects[0] |
| 558 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 559 | # Store the enabled hooks in the Project object. |
| 560 | self._repo_hooks_project.enabled_repo_hooks = enabled_repo_hooks |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 561 | if node.nodeName == 'remove-project': |
| 562 | name = self._reqatt(node, 'name') |
David James | b8433df | 2014-01-30 10:11:17 -0800 | [diff] [blame] | 563 | |
| 564 | if name not in self._projects: |
David Pursehouse | f910748 | 2012-11-16 19:12:32 +0900 | [diff] [blame] | 565 | raise ManifestParseError('remove-project element specifies non-existent ' |
| 566 | 'project: %s' % name) |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 567 | |
David James | b8433df | 2014-01-30 10:11:17 -0800 | [diff] [blame] | 568 | for p in self._projects[name]: |
| 569 | del self._paths[p.relpath] |
| 570 | del self._projects[name] |
| 571 | |
Colin Cross | 23acdd3 | 2012-04-21 00:33:54 -0700 | [diff] [blame] | 572 | # If the manifest removes the hooks project, treat it as if it deleted |
| 573 | # the repo-hooks element too. |
| 574 | if self._repo_hooks_project and (self._repo_hooks_project.name == name): |
| 575 | self._repo_hooks_project = None |
| 576 | |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 577 | |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 578 | def _AddMetaProjectMirror(self, m): |
| 579 | name = None |
| 580 | m_url = m.GetRemote(m.remote.name).url |
| 581 | if m_url.endswith('/.git'): |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 582 | raise ManifestParseError('refusing to mirror %s' % m_url) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 583 | |
| 584 | if self._default and self._default.remote: |
Conley Owens | ceea368 | 2011-10-20 10:45:47 -0700 | [diff] [blame] | 585 | url = self._default.remote.resolvedFetchUrl |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 586 | if not url.endswith('/'): |
| 587 | url += '/' |
| 588 | if m_url.startswith(url): |
| 589 | remote = self._default.remote |
| 590 | name = m_url[len(url):] |
| 591 | |
| 592 | if name is None: |
| 593 | s = m_url.rindex('/') + 1 |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 594 | manifestUrl = self.manifestProject.config.GetString('remote.origin.url') |
Shawn O. Pearce | f35b2d9 | 2012-08-02 11:46:22 -0700 | [diff] [blame] | 595 | remote = _XmlRemote('origin', fetch=m_url[:s], manifestUrl=manifestUrl) |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 596 | name = m_url[s:] |
| 597 | |
| 598 | if name.endswith('.git'): |
| 599 | name = name[:-4] |
| 600 | |
| 601 | if name not in self._projects: |
| 602 | m.PreSync() |
| 603 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
| 604 | project = Project(manifest = self, |
| 605 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 606 | remote = remote.ToRemoteSpec(name), |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 607 | gitdir = gitdir, |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 608 | objdir = gitdir, |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 609 | worktree = None, |
Kwanhong Lee | ccd218c | 2014-02-17 13:07:32 +0900 | [diff] [blame] | 610 | relpath = name or None, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 611 | revisionExpr = m.revisionExpr, |
| 612 | revisionId = None) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 613 | self._projects[project.name] = [project] |
Kwanhong Lee | ccd218c | 2014-02-17 13:07:32 +0900 | [diff] [blame] | 614 | self._paths[project.relpath] = project |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 615 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 616 | def _ParseRemote(self, node): |
| 617 | """ |
| 618 | reads a <remote> element from the manifest file |
| 619 | """ |
| 620 | name = self._reqatt(node, 'name') |
Yestin Sun | b292b98 | 2012-07-02 07:32:50 -0700 | [diff] [blame] | 621 | alias = node.getAttribute('alias') |
| 622 | if alias == '': |
| 623 | alias = None |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 624 | fetch = self._reqatt(node, 'fetch') |
| 625 | review = node.getAttribute('review') |
Shawn O. Pearce | ae6e094 | 2008-11-06 10:25:35 -0800 | [diff] [blame] | 626 | if review == '': |
| 627 | review = None |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 628 | revision = node.getAttribute('revision') |
| 629 | if revision == '': |
| 630 | revision = None |
Conley Owens | db728cd | 2011-09-26 16:34:01 -0700 | [diff] [blame] | 631 | manifestUrl = self.manifestProject.config.GetString('remote.origin.url') |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 632 | return _XmlRemote(name, alias, fetch, manifestUrl, review, revision) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 633 | |
| 634 | def _ParseDefault(self, node): |
| 635 | """ |
| 636 | reads a <default> element from the manifest file |
| 637 | """ |
| 638 | d = _Default() |
| 639 | d.remote = self._get_remote(node) |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 640 | d.revisionExpr = node.getAttribute('revision') |
| 641 | if d.revisionExpr == '': |
| 642 | d.revisionExpr = None |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 643 | |
Bryan Jacobs | f609f91 | 2013-05-06 13:36:24 -0400 | [diff] [blame] | 644 | d.destBranchExpr = node.getAttribute('dest-branch') or None |
| 645 | |
Shawn O. Pearce | 6392c87 | 2011-09-22 17:44:31 -0700 | [diff] [blame] | 646 | sync_j = node.getAttribute('sync-j') |
| 647 | if sync_j == '' or sync_j is None: |
| 648 | d.sync_j = 1 |
| 649 | else: |
| 650 | d.sync_j = int(sync_j) |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 651 | |
| 652 | sync_c = node.getAttribute('sync-c') |
| 653 | if not sync_c: |
| 654 | d.sync_c = False |
| 655 | else: |
| 656 | d.sync_c = sync_c.lower() in ("yes", "true", "1") |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 657 | |
| 658 | sync_s = node.getAttribute('sync-s') |
| 659 | if not sync_s: |
| 660 | d.sync_s = False |
| 661 | else: |
| 662 | 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] | 663 | return d |
| 664 | |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 665 | def _ParseNotice(self, node): |
| 666 | """ |
| 667 | reads a <notice> element from the manifest file |
| 668 | |
| 669 | The <notice> element is distinct from other tags in the XML in that the |
| 670 | data is conveyed between the start and end tag (it's not an empty-element |
| 671 | tag). |
| 672 | |
| 673 | The white space (carriage returns, indentation) for the notice element is |
| 674 | relevant and is parsed in a way that is based on how python docstrings work. |
| 675 | In fact, the code is remarkably similar to here: |
| 676 | http://www.python.org/dev/peps/pep-0257/ |
| 677 | """ |
| 678 | # Get the data out of the node... |
| 679 | notice = node.childNodes[0].data |
| 680 | |
| 681 | # Figure out minimum indentation, skipping the first line (the same line |
| 682 | # as the <notice> tag)... |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 683 | minIndent = sys.maxsize |
Doug Anderson | 2b8db3c | 2010-11-01 15:08:06 -0700 | [diff] [blame] | 684 | lines = notice.splitlines() |
| 685 | for line in lines[1:]: |
| 686 | lstrippedLine = line.lstrip() |
| 687 | if lstrippedLine: |
| 688 | indent = len(line) - len(lstrippedLine) |
| 689 | minIndent = min(indent, minIndent) |
| 690 | |
| 691 | # Strip leading / trailing blank lines and also indentation. |
| 692 | cleanLines = [lines[0].strip()] |
| 693 | for line in lines[1:]: |
| 694 | cleanLines.append(line[minIndent:].rstrip()) |
| 695 | |
| 696 | # Clear completely blank lines from front and back... |
| 697 | while cleanLines and not cleanLines[0]: |
| 698 | del cleanLines[0] |
| 699 | while cleanLines and not cleanLines[-1]: |
| 700 | del cleanLines[-1] |
| 701 | |
| 702 | return '\n'.join(cleanLines) |
| 703 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 704 | def _JoinName(self, parent_name, name): |
| 705 | return os.path.join(parent_name, name) |
| 706 | |
| 707 | def _UnjoinName(self, parent_name, name): |
| 708 | return os.path.relpath(name, parent_name) |
| 709 | |
| 710 | def _ParseProject(self, node, parent = None): |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 711 | """ |
| 712 | reads a <project> element from the manifest file |
Nico Sallembien | a1bfd2c | 2010-04-06 10:40:01 -0700 | [diff] [blame] | 713 | """ |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 714 | name = self._reqatt(node, 'name') |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 715 | if parent: |
| 716 | name = self._JoinName(parent.name, name) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 717 | |
| 718 | remote = self._get_remote(node) |
| 719 | if remote is None: |
| 720 | remote = self._default.remote |
| 721 | if remote is None: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 722 | raise ManifestParseError("no remote for project %s within %s" % |
| 723 | (name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 724 | |
Anthony King | 36ea2fb | 2014-05-06 11:54:01 +0100 | [diff] [blame] | 725 | revisionExpr = node.getAttribute('revision') or remote.revision |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 726 | if not revisionExpr: |
| 727 | revisionExpr = self._default.revisionExpr |
| 728 | if not revisionExpr: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 729 | raise ManifestParseError("no revision for project %s within %s" % |
| 730 | (name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 731 | |
| 732 | path = node.getAttribute('path') |
| 733 | if not path: |
| 734 | path = name |
| 735 | if path.startswith('/'): |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 736 | raise ManifestParseError("project %s path cannot be absolute in %s" % |
| 737 | (name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 738 | |
Mike Pontillo | d315382 | 2012-02-28 11:53:24 -0800 | [diff] [blame] | 739 | rebase = node.getAttribute('rebase') |
| 740 | if not rebase: |
| 741 | rebase = True |
| 742 | else: |
| 743 | rebase = rebase.lower() in ("yes", "true", "1") |
| 744 | |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 745 | sync_c = node.getAttribute('sync-c') |
| 746 | if not sync_c: |
| 747 | sync_c = False |
| 748 | else: |
| 749 | sync_c = sync_c.lower() in ("yes", "true", "1") |
| 750 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 751 | sync_s = node.getAttribute('sync-s') |
| 752 | if not sync_s: |
| 753 | sync_s = self._default.sync_s |
| 754 | else: |
| 755 | sync_s = sync_s.lower() in ("yes", "true", "1") |
| 756 | |
David Pursehouse | ede7f12 | 2012-11-27 22:25:30 +0900 | [diff] [blame] | 757 | clone_depth = node.getAttribute('clone-depth') |
| 758 | if clone_depth: |
| 759 | try: |
| 760 | clone_depth = int(clone_depth) |
| 761 | if clone_depth <= 0: |
| 762 | raise ValueError() |
| 763 | except ValueError: |
| 764 | raise ManifestParseError('invalid clone-depth %s in %s' % |
| 765 | (clone_depth, self.manifestFile)) |
| 766 | |
Bryan Jacobs | f609f91 | 2013-05-06 13:36:24 -0400 | [diff] [blame] | 767 | dest_branch = node.getAttribute('dest-branch') or self._default.destBranchExpr |
| 768 | |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 769 | upstream = node.getAttribute('upstream') |
| 770 | |
Conley Owens | 971de8e | 2012-04-16 10:36:08 -0700 | [diff] [blame] | 771 | groups = '' |
| 772 | if node.hasAttribute('groups'): |
| 773 | groups = node.getAttribute('groups') |
Josh Triplett | 884a387 | 2014-06-12 14:57:29 -0700 | [diff] [blame] | 774 | groups = self._ParseGroups(groups) |
Brian Harring | 7da1314 | 2012-06-15 02:24:20 -0700 | [diff] [blame] | 775 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 776 | if parent is None: |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 777 | relpath, worktree, gitdir, objdir = self.GetProjectPaths(name, path) |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 778 | else: |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 779 | relpath, worktree, gitdir, objdir = \ |
| 780 | self.GetSubprojectPaths(parent, name, path) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 781 | |
| 782 | default_groups = ['all', 'name:%s' % name, 'path:%s' % relpath] |
| 783 | groups.extend(set(default_groups).difference(groups)) |
Shawn O. Pearce | cd81dd6 | 2012-10-26 12:18:00 -0700 | [diff] [blame] | 784 | |
Scott Fan | db83b1b | 2013-02-28 09:34:14 +0800 | [diff] [blame] | 785 | if self.IsMirror and node.hasAttribute('force-path'): |
| 786 | if node.getAttribute('force-path').lower() in ("yes", "true", "1"): |
| 787 | gitdir = os.path.join(self.topdir, '%s.git' % path) |
| 788 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 789 | project = Project(manifest = self, |
| 790 | name = name, |
Shawn O. Pearce | d1f70d9 | 2009-05-19 14:58:02 -0700 | [diff] [blame] | 791 | remote = remote.ToRemoteSpec(name), |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 792 | gitdir = gitdir, |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 793 | objdir = objdir, |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 794 | worktree = worktree, |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 795 | relpath = relpath, |
Shawn O. Pearce | 3c8dea1 | 2009-05-29 18:38:17 -0700 | [diff] [blame] | 796 | revisionExpr = revisionExpr, |
Mike Pontillo | d315382 | 2012-02-28 11:53:24 -0800 | [diff] [blame] | 797 | revisionId = None, |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 798 | rebase = rebase, |
Anatol Pomazau | 79770d2 | 2012-04-20 14:41:59 -0700 | [diff] [blame] | 799 | groups = groups, |
Brian Harring | 14a6674 | 2012-09-28 20:21:57 -0700 | [diff] [blame] | 800 | sync_c = sync_c, |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 801 | sync_s = sync_s, |
David Pursehouse | ede7f12 | 2012-11-27 22:25:30 +0900 | [diff] [blame] | 802 | clone_depth = clone_depth, |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 803 | upstream = upstream, |
Bryan Jacobs | f609f91 | 2013-05-06 13:36:24 -0400 | [diff] [blame] | 804 | parent = parent, |
| 805 | dest_branch = dest_branch) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 806 | |
| 807 | for n in node.childNodes: |
Shawn O. Pearce | 242b526 | 2009-05-19 13:00:29 -0700 | [diff] [blame] | 808 | if n.nodeName == 'copyfile': |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 809 | self._ParseCopyFile(project, n) |
Jeff Hamilton | e0df232 | 2014-04-21 17:10:59 -0500 | [diff] [blame] | 810 | if n.nodeName == 'linkfile': |
| 811 | self._ParseLinkFile(project, n) |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 812 | if n.nodeName == 'annotation': |
| 813 | self._ParseAnnotation(project, n) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 814 | if n.nodeName == 'project': |
| 815 | project.subprojects.append(self._ParseProject(n, parent = project)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 816 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 817 | return project |
| 818 | |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 819 | def GetProjectPaths(self, name, path): |
| 820 | relpath = path |
| 821 | if self.IsMirror: |
| 822 | worktree = None |
| 823 | gitdir = os.path.join(self.topdir, '%s.git' % name) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 824 | objdir = gitdir |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 825 | else: |
| 826 | worktree = os.path.join(self.topdir, path).replace('\\', '/') |
| 827 | gitdir = os.path.join(self.repodir, 'projects', '%s.git' % path) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 828 | objdir = os.path.join(self.repodir, 'project-objects', '%s.git' % name) |
| 829 | return relpath, worktree, gitdir, objdir |
| 830 | |
| 831 | def GetProjectsWithName(self, name): |
| 832 | return self._projects.get(name, []) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 833 | |
| 834 | def GetSubprojectName(self, parent, submodule_path): |
| 835 | return os.path.join(parent.name, submodule_path) |
| 836 | |
| 837 | def _JoinRelpath(self, parent_relpath, relpath): |
| 838 | return os.path.join(parent_relpath, relpath) |
| 839 | |
| 840 | def _UnjoinRelpath(self, parent_relpath, relpath): |
| 841 | return os.path.relpath(relpath, parent_relpath) |
| 842 | |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 843 | def GetSubprojectPaths(self, parent, name, path): |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 844 | relpath = self._JoinRelpath(parent.relpath, path) |
| 845 | gitdir = os.path.join(parent.gitdir, 'subprojects', '%s.git' % path) |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 846 | objdir = os.path.join(parent.gitdir, 'subproject-objects', '%s.git' % name) |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 847 | if self.IsMirror: |
| 848 | worktree = None |
| 849 | else: |
| 850 | worktree = os.path.join(parent.worktree, path).replace('\\', '/') |
David James | 8d20116 | 2013-10-11 17:03:19 -0700 | [diff] [blame] | 851 | return relpath, worktree, gitdir, objdir |
Che-Liang Chiou | b2bd91c | 2012-01-11 11:28:42 +0800 | [diff] [blame] | 852 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 853 | def _ParseCopyFile(self, project, node): |
| 854 | src = self._reqatt(node, 'src') |
| 855 | dest = self._reqatt(node, 'dest') |
Shawn O. Pearce | e284ad1 | 2008-11-04 07:37:10 -0800 | [diff] [blame] | 856 | if not self.IsMirror: |
| 857 | # src is project relative; |
| 858 | # dest is relative to the top of the tree |
Shawn O. Pearce | c7a4eef | 2009-03-05 10:32:38 -0800 | [diff] [blame] | 859 | 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] | 860 | |
Jeff Hamilton | e0df232 | 2014-04-21 17:10:59 -0500 | [diff] [blame] | 861 | def _ParseLinkFile(self, project, node): |
| 862 | src = self._reqatt(node, 'src') |
| 863 | dest = self._reqatt(node, 'dest') |
| 864 | if not self.IsMirror: |
| 865 | # src is project relative; |
| 866 | # dest is relative to the top of the tree |
| 867 | project.AddLinkFile(src, dest, os.path.join(self.topdir, dest)) |
| 868 | |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 869 | def _ParseAnnotation(self, project, node): |
| 870 | name = self._reqatt(node, 'name') |
| 871 | value = self._reqatt(node, 'value') |
| 872 | try: |
| 873 | keep = self._reqatt(node, 'keep').lower() |
| 874 | except ManifestParseError: |
| 875 | keep = "true" |
| 876 | if keep != "true" and keep != "false": |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 877 | raise ManifestParseError('optional "keep" attribute must be ' |
| 878 | '"true" or "false"') |
James W. Mills | 24c1308 | 2012-04-12 15:04:13 -0500 | [diff] [blame] | 879 | project.AddAnnotation(name, value, keep) |
| 880 | |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 881 | def _get_remote(self, node): |
| 882 | name = node.getAttribute('remote') |
| 883 | if not name: |
| 884 | return None |
| 885 | |
| 886 | v = self._remotes.get(name) |
| 887 | if not v: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 888 | raise ManifestParseError("remote %s not defined in %s" % |
| 889 | (name, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 890 | return v |
| 891 | |
| 892 | def _reqatt(self, node, attname): |
| 893 | """ |
| 894 | reads a required attribute from the node. |
| 895 | """ |
| 896 | v = node.getAttribute(attname) |
| 897 | if not v: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 898 | raise ManifestParseError("no %s in <%s> within %s" % |
| 899 | (attname, node.nodeName, self.manifestFile)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 900 | return v |
Julien Campergue | dd65422 | 2014-01-09 16:21:37 +0100 | [diff] [blame] | 901 | |
| 902 | def projectsDiff(self, manifest): |
| 903 | """return the projects differences between two manifests. |
| 904 | |
| 905 | The diff will be from self to given manifest. |
| 906 | |
| 907 | """ |
| 908 | fromProjects = self.paths |
| 909 | toProjects = manifest.paths |
| 910 | |
Anthony King | 7446c59 | 2014-05-06 09:19:39 +0100 | [diff] [blame] | 911 | fromKeys = sorted(fromProjects.keys()) |
| 912 | toKeys = sorted(toProjects.keys()) |
Julien Campergue | dd65422 | 2014-01-09 16:21:37 +0100 | [diff] [blame] | 913 | |
| 914 | diff = {'added': [], 'removed': [], 'changed': [], 'unreachable': []} |
| 915 | |
| 916 | for proj in fromKeys: |
| 917 | if not proj in toKeys: |
| 918 | diff['removed'].append(fromProjects[proj]) |
| 919 | else: |
| 920 | fromProj = fromProjects[proj] |
| 921 | toProj = toProjects[proj] |
| 922 | try: |
| 923 | fromRevId = fromProj.GetCommitRevisionId() |
| 924 | toRevId = toProj.GetCommitRevisionId() |
| 925 | except ManifestInvalidRevisionError: |
| 926 | diff['unreachable'].append((fromProj, toProj)) |
| 927 | else: |
| 928 | if fromRevId != toRevId: |
| 929 | diff['changed'].append((fromProj, toProj)) |
| 930 | toKeys.remove(proj) |
| 931 | |
| 932 | for proj in toKeys: |
| 933 | diff['added'].append(toProjects[proj]) |
| 934 | |
| 935 | return diff |