[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1 | #!/usr/bin/python |
[email protected] | ba55177 | 2010-02-03 18:21:42 | [diff] [blame] | 2 | # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 5 | |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 6 | """Meta checkout manager supporting both Subversion and GIT. |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 7 | |
| 8 | Files |
| 9 | .gclient : Current client configuration, written by 'config' command. |
| 10 | Format is a Python script defining 'solutions', a list whose |
| 11 | entries each are maps binding the strings "name" and "url" |
| 12 | to strings specifying the name and location of the client |
| 13 | module, as well as "custom_deps" to a map similar to the DEPS |
| 14 | file below. |
| 15 | .gclient_entries : A cache constructed by 'update' command. Format is a |
| 16 | Python script defining 'entries', a list of the names |
| 17 | of all modules in the client |
| 18 | <module>/DEPS : Python script defining var 'deps' as a map from each requisite |
| 19 | submodule name to a URL where it can be found (via one SCM) |
| 20 | |
| 21 | Hooks |
| 22 | .gclient and DEPS files may optionally contain a list named "hooks" to |
| 23 | allow custom actions to be performed based on files that have changed in the |
[email protected] | 67820ef | 2009-07-27 17:23:00 | [diff] [blame] | 24 | working copy as a result of a "sync"/"update" or "revert" operation. This |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 25 | can be prevented by using --nohooks (hooks run by default). Hooks can also |
[email protected] | 5df6a46 | 2009-08-28 18:52:26 | [diff] [blame] | 26 | be forced to run with the "runhooks" operation. If "sync" is run with |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 27 | --force, all known hooks will run regardless of the state of the working |
| 28 | copy. |
| 29 | |
| 30 | Each item in a "hooks" list is a dict, containing these two keys: |
| 31 | "pattern" The associated value is a string containing a regular |
| 32 | expression. When a file whose pathname matches the expression |
| 33 | is checked out, updated, or reverted, the hook's "action" will |
| 34 | run. |
| 35 | "action" A list describing a command to run along with its arguments, if |
| 36 | any. An action command will run at most one time per gclient |
| 37 | invocation, regardless of how many files matched the pattern. |
| 38 | The action is executed in the same directory as the .gclient |
| 39 | file. If the first item in the list is the string "python", |
| 40 | the current Python interpreter (sys.executable) will be used |
[email protected] | 71b4068 | 2009-07-31 23:40:09 | [diff] [blame] | 41 | to run the command. If the list contains string "$matching_files" |
| 42 | it will be removed from the list and the list will be extended |
| 43 | by the list of matching files. |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 44 | |
| 45 | Example: |
| 46 | hooks = [ |
| 47 | { "pattern": "\\.(gif|jpe?g|pr0n|png)$", |
| 48 | "action": ["python", "image_indexer.py", "--all"]}, |
| 49 | ] |
| 50 | """ |
| 51 | |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 52 | __version__ = "0.5.1" |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 53 | |
[email protected] | 754960e | 2009-09-21 12:31:05 | [diff] [blame] | 54 | import logging |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 55 | import optparse |
| 56 | import os |
[email protected] | 621939b | 2010-08-10 20:12:00 | [diff] [blame] | 57 | import posixpath |
[email protected] | 2e38de7 | 2009-09-28 17:04:47 | [diff] [blame] | 58 | import pprint |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 59 | import re |
[email protected] | 4b90e3a | 2010-07-01 20:28:26 | [diff] [blame] | 60 | import subprocess |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 61 | import sys |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 62 | import threading |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 63 | import urlparse |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 64 | import urllib |
| 65 | |
[email protected] | ada4c65 | 2009-12-03 15:32:01 | [diff] [blame] | 66 | import breakpad |
| 67 | |
[email protected] | 5f3eee3 | 2009-09-17 00:34:30 | [diff] [blame] | 68 | import gclient_scm |
| 69 | import gclient_utils |
[email protected] | 1f7a3d1 | 2010-02-04 15:11:50 | [diff] [blame] | 70 | from third_party.repo.progress import Progress |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 71 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 72 | |
[email protected] | 1f7d118 | 2010-05-17 18:17:38 | [diff] [blame] | 73 | def attr(attr, data): |
| 74 | """Sets an attribute on a function.""" |
| 75 | def hook(fn): |
| 76 | setattr(fn, attr, data) |
| 77 | return fn |
| 78 | return hook |
[email protected] | e3da35f | 2010-03-09 21:40:45 | [diff] [blame] | 79 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 80 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 81 | ## GClient implementation. |
| 82 | |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 83 | class WorkItem(object): |
| 84 | """One work item.""" |
| 85 | requirements = [] |
| 86 | name = None |
| 87 | |
| 88 | def run(self): |
| 89 | pass |
| 90 | |
| 91 | |
| 92 | class ExecutionQueue(object): |
| 93 | """Dependencies sometime needs to be run out of order due to From() keyword. |
| 94 | |
| 95 | This class manages that all the required dependencies are run before running |
| 96 | each one. |
| 97 | |
| 98 | Methods of this class are multithread safe. |
| 99 | """ |
| 100 | def __init__(self, progress): |
| 101 | self.lock = threading.Lock() |
| 102 | # List of Dependency. |
| 103 | self.queued = [] |
| 104 | # List of strings representing each Dependency.name that was run. |
| 105 | self.ran = [] |
| 106 | # List of items currently running. |
| 107 | self.running = [] |
| 108 | self.progress = progress |
| 109 | if self.progress: |
| 110 | self.progress.update() |
| 111 | |
| 112 | def enqueue(self, d): |
| 113 | """Enqueue one Dependency to be executed later once its requirements are |
| 114 | satisfied. |
| 115 | """ |
| 116 | assert isinstance(d, WorkItem) |
| 117 | try: |
| 118 | self.lock.acquire() |
| 119 | self.queued.append(d) |
| 120 | total = len(self.queued) + len(self.ran) + len(self.running) |
| 121 | finally: |
| 122 | self.lock.release() |
| 123 | if self.progress: |
| 124 | self.progress._total = total + 1 |
| 125 | self.progress.update(0) |
| 126 | |
| 127 | def flush(self, *args, **kwargs): |
| 128 | """Runs all enqueued items until all are executed.""" |
| 129 | while self._run_one_item(*args, **kwargs): |
| 130 | pass |
| 131 | queued = [] |
| 132 | running = [] |
| 133 | try: |
| 134 | self.lock.acquire() |
| 135 | if self.queued: |
| 136 | queued = self.queued |
| 137 | self.queued = [] |
| 138 | if self.running: |
| 139 | running = self.running |
| 140 | self.running = [] |
| 141 | finally: |
| 142 | self.lock.release() |
| 143 | if self.progress: |
| 144 | self.progress.end() |
| 145 | if queued: |
| 146 | raise gclient_utils.Error('Entries still queued: %s' % str(queued)) |
| 147 | if running: |
| 148 | raise gclient_utils.Error('Entries still queued: %s' % str(running)) |
| 149 | |
| 150 | def _run_one_item(self, *args, **kwargs): |
| 151 | """Removes one item from the queue that has all its requirements completed |
| 152 | and execute it. |
| 153 | |
| 154 | Returns False if no item could be run. |
| 155 | """ |
| 156 | i = 0 |
| 157 | d = None |
| 158 | try: |
| 159 | self.lock.acquire() |
| 160 | while i != len(self.queued) and not d: |
| 161 | d = self.queued.pop(i) |
| 162 | for r in d.requirements: |
| 163 | if not r in self.ran: |
| 164 | self.queued.insert(i, d) |
| 165 | d = None |
| 166 | break |
| 167 | i += 1 |
| 168 | if not d: |
| 169 | return False |
| 170 | self.running.append(d) |
| 171 | finally: |
| 172 | self.lock.release() |
| 173 | d.run(*args, **kwargs) |
| 174 | try: |
| 175 | self.lock.acquire() |
| 176 | # TODO(maruel): http://crbug.com/51711 |
| 177 | #assert not d.name in self.ran |
| 178 | if not d.name in self.ran: |
| 179 | self.ran.append(d.name) |
| 180 | self.running.remove(d) |
| 181 | if self.progress: |
| 182 | self.progress.update(1) |
| 183 | finally: |
| 184 | self.lock.release() |
| 185 | return True |
| 186 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 187 | |
[email protected] | 116704f | 2010-06-11 17:34:38 | [diff] [blame] | 188 | class GClientKeywords(object): |
| 189 | class FromImpl(object): |
| 190 | """Used to implement the From() syntax.""" |
| 191 | |
| 192 | def __init__(self, module_name, sub_target_name=None): |
| 193 | """module_name is the dep module we want to include from. It can also be |
| 194 | the name of a subdirectory to include from. |
| 195 | |
| 196 | sub_target_name is an optional parameter if the module name in the other |
| 197 | DEPS file is different. E.g., you might want to map src/net to net.""" |
| 198 | self.module_name = module_name |
| 199 | self.sub_target_name = sub_target_name |
| 200 | |
| 201 | def __str__(self): |
| 202 | return 'From(%s, %s)' % (repr(self.module_name), |
| 203 | repr(self.sub_target_name)) |
| 204 | |
[email protected] | 116704f | 2010-06-11 17:34:38 | [diff] [blame] | 205 | class FileImpl(object): |
| 206 | """Used to implement the File('') syntax which lets you sync a single file |
[email protected] | e3216c6 | 2010-07-08 03:31:43 | [diff] [blame] | 207 | from a SVN repo.""" |
[email protected] | 116704f | 2010-06-11 17:34:38 | [diff] [blame] | 208 | |
| 209 | def __init__(self, file_location): |
| 210 | self.file_location = file_location |
| 211 | |
| 212 | def __str__(self): |
| 213 | return 'File("%s")' % self.file_location |
| 214 | |
| 215 | def GetPath(self): |
| 216 | return os.path.split(self.file_location)[0] |
| 217 | |
| 218 | def GetFilename(self): |
| 219 | rev_tokens = self.file_location.split('@') |
| 220 | return os.path.split(rev_tokens[0])[1] |
| 221 | |
| 222 | def GetRevision(self): |
| 223 | rev_tokens = self.file_location.split('@') |
| 224 | if len(rev_tokens) > 1: |
| 225 | return rev_tokens[1] |
| 226 | return None |
| 227 | |
| 228 | class VarImpl(object): |
| 229 | def __init__(self, custom_vars, local_scope): |
| 230 | self._custom_vars = custom_vars |
| 231 | self._local_scope = local_scope |
| 232 | |
| 233 | def Lookup(self, var_name): |
| 234 | """Implements the Var syntax.""" |
| 235 | if var_name in self._custom_vars: |
| 236 | return self._custom_vars[var_name] |
| 237 | elif var_name in self._local_scope.get("vars", {}): |
| 238 | return self._local_scope["vars"][var_name] |
| 239 | raise gclient_utils.Error("Var is not defined: %s" % var_name) |
| 240 | |
| 241 | |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 242 | class Dependency(GClientKeywords, WorkItem): |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 243 | """Object that represents a dependency checkout.""" |
[email protected] | 9eda411 | 2010-06-11 18:56:10 | [diff] [blame] | 244 | DEPS_FILE = 'DEPS' |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 245 | |
[email protected] | 0d81244 | 2010-08-10 12:41:08 | [diff] [blame] | 246 | def __init__(self, parent, name, url, safesync_url, custom_deps, |
| 247 | custom_vars, deps_file): |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 248 | GClientKeywords.__init__(self) |
| 249 | self.parent = parent |
| 250 | self.name = name |
| 251 | self.url = url |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 252 | self.parsed_url = None |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 253 | # These 2 are only set in .gclient and not in DEPS files. |
| 254 | self.safesync_url = safesync_url |
| 255 | self.custom_vars = custom_vars or {} |
| 256 | self.custom_deps = custom_deps or {} |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 257 | self.deps_hooks = [] |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 258 | self.dependencies = [] |
| 259 | self.deps_file = deps_file or self.DEPS_FILE |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 260 | # A cache of the files affected by the current operation, necessary for |
| 261 | # hooks. |
[email protected] | 861fd0f | 2010-07-23 03:05:05 | [diff] [blame] | 262 | self._file_list = [] |
[email protected] | 85c2a19 | 2010-07-22 21:14:43 | [diff] [blame] | 263 | # If it is not set to True, the dependency wasn't processed for its child |
| 264 | # dependency, i.e. its DEPS wasn't read. |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 265 | self.deps_parsed = False |
[email protected] | 85c2a19 | 2010-07-22 21:14:43 | [diff] [blame] | 266 | # A direct reference is dependency that is referenced by a deps, deps_os or |
| 267 | # solution. A indirect one is one that was loaded with From() or that |
| 268 | # exceeded recursion limit. |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 269 | self.direct_reference = False |
[email protected] | f3abb80 | 2010-08-10 17:19:56 | [diff] [blame] | 270 | # This dependency has been processed, i.e. checked out |
| 271 | self.processed = False |
| 272 | # This dependency had its hook run |
| 273 | self.hooks_ran = False |
[email protected] | 621939b | 2010-08-10 20:12:00 | [diff] [blame] | 274 | # Required dependencies to run before running this one: |
| 275 | self.requirements = [] |
| 276 | if self.parent and self.parent.name: |
| 277 | self.requirements.append(self.parent.name) |
| 278 | if isinstance(self.url, self.FromImpl): |
| 279 | self.requirements.append(self.url.module_name) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 280 | |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 281 | # Sanity checks |
| 282 | if not self.name and self.parent: |
| 283 | raise gclient_utils.Error('Dependency without name') |
| 284 | if not isinstance(self.url, |
| 285 | (basestring, self.FromImpl, self.FileImpl, None.__class__)): |
| 286 | raise gclient_utils.Error('dependency url must be either a string, None, ' |
| 287 | 'File() or From() instead of %s' % |
| 288 | self.url.__class__.__name__) |
| 289 | if '/' in self.deps_file or '\\' in self.deps_file: |
| 290 | raise gclient_utils.Error('deps_file name must not be a path, just a ' |
| 291 | 'filename. %s' % self.deps_file) |
| 292 | |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 293 | def LateOverride(self, url): |
[email protected] | da7a1f9 | 2010-08-10 17:19:02 | [diff] [blame] | 294 | """Resolves the parsed url from url. |
| 295 | |
| 296 | Manages From() keyword accordingly. Do not touch self.parsed_url nor |
| 297 | self.url because it may called with other urls due to From().""" |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 298 | overriden_url = self.get_custom_deps(self.name, url) |
| 299 | if overriden_url != url: |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 300 | logging.info('%s, %s was overriden to %s' % (self.name, url, |
[email protected] | da7a1f9 | 2010-08-10 17:19:02 | [diff] [blame] | 301 | overriden_url)) |
| 302 | return overriden_url |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 303 | elif isinstance(url, self.FromImpl): |
| 304 | ref = [dep for dep in self.tree(True) if url.module_name == dep.name] |
[email protected] | f3abb80 | 2010-08-10 17:19:56 | [diff] [blame] | 305 | if not ref: |
| 306 | raise gclient_utils.Error('Failed to find one reference to %s. %s' % ( |
| 307 | url.module_name, ref)) |
| 308 | # It may happen that len(ref) > 1 but it's no big deal. |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 309 | ref = ref[0] |
[email protected] | 98d05fa | 2010-07-22 21:58:01 | [diff] [blame] | 310 | sub_target = url.sub_target_name or self.name |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 311 | # Make sure the referenced dependency DEPS file is loaded and file the |
| 312 | # inner referenced dependency. |
| 313 | ref.ParseDepsFile(False) |
| 314 | found_dep = None |
| 315 | for d in ref.dependencies: |
| 316 | if d.name == sub_target: |
| 317 | found_dep = d |
| 318 | break |
| 319 | if not found_dep: |
[email protected] | f3abb80 | 2010-08-10 17:19:56 | [diff] [blame] | 320 | raise gclient_utils.Error( |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 321 | 'Couldn\'t find %s in %s, referenced by %s\n%s' % ( |
| 322 | sub_target, ref.name, self.name, str(self.root_parent()))) |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 323 | # Call LateOverride() again. |
[email protected] | da7a1f9 | 2010-08-10 17:19:02 | [diff] [blame] | 324 | parsed_url = found_dep.LateOverride(found_dep.url) |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 325 | logging.info('%s, %s to %s' % (self.name, url, parsed_url)) |
[email protected] | da7a1f9 | 2010-08-10 17:19:02 | [diff] [blame] | 326 | return parsed_url |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 327 | elif isinstance(url, basestring): |
| 328 | parsed_url = urlparse.urlparse(url) |
| 329 | if not parsed_url[0]: |
| 330 | # A relative url. Fetch the real base. |
| 331 | path = parsed_url[2] |
| 332 | if not path.startswith('/'): |
| 333 | raise gclient_utils.Error( |
| 334 | 'relative DEPS entry \'%s\' must begin with a slash' % url) |
| 335 | # Create a scm just to query the full url. |
| 336 | parent_url = self.parent.parsed_url |
| 337 | if isinstance(parent_url, self.FileImpl): |
| 338 | parent_url = parent_url.file_location |
| 339 | scm = gclient_scm.CreateSCM(parent_url, self.root_dir(), None) |
[email protected] | da7a1f9 | 2010-08-10 17:19:02 | [diff] [blame] | 340 | parsed_url = scm.FullUrlForRelativeUrl(url) |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 341 | else: |
[email protected] | da7a1f9 | 2010-08-10 17:19:02 | [diff] [blame] | 342 | parsed_url = url |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 343 | logging.info('%s, %s -> %s' % (self.name, url, parsed_url)) |
[email protected] | da7a1f9 | 2010-08-10 17:19:02 | [diff] [blame] | 344 | return parsed_url |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 345 | elif isinstance(url, self.FileImpl): |
[email protected] | da7a1f9 | 2010-08-10 17:19:02 | [diff] [blame] | 346 | parsed_url = url |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 347 | logging.info('%s, %s -> %s (File)' % (self.name, url, parsed_url)) |
[email protected] | da7a1f9 | 2010-08-10 17:19:02 | [diff] [blame] | 348 | return parsed_url |
| 349 | elif url is None: |
| 350 | return None |
| 351 | else: |
| 352 | raise gclient_utils.Error('Unkown url type') |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 353 | |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 354 | def ParseDepsFile(self, direct_reference): |
| 355 | """Parses the DEPS file for this dependency.""" |
| 356 | if direct_reference: |
| 357 | # Maybe it was referenced earlier by a From() keyword but it's now |
| 358 | # directly referenced. |
| 359 | self.direct_reference = direct_reference |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 360 | if self.deps_parsed: |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 361 | logging.debug('%s was already parsed' % self.name) |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 362 | return |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 363 | self.deps_parsed = True |
| 364 | filepath = os.path.join(self.root_dir(), self.name, self.deps_file) |
| 365 | if not os.path.isfile(filepath): |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 366 | logging.info('%s: No DEPS file found at %s' % (self.name, filepath)) |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 367 | return |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 368 | deps_content = gclient_utils.FileRead(filepath) |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 369 | logging.debug(deps_content) |
[email protected] | 0d42592 | 2010-06-21 19:22:24 | [diff] [blame] | 370 | |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 371 | # Eval the content. |
| 372 | # One thing is unintuitive, vars= {} must happen before Var() use. |
| 373 | local_scope = {} |
| 374 | var = self.VarImpl(self.custom_vars, local_scope) |
| 375 | global_scope = { |
| 376 | 'File': self.FileImpl, |
| 377 | 'From': self.FromImpl, |
| 378 | 'Var': var.Lookup, |
| 379 | 'deps_os': {}, |
| 380 | } |
[email protected] | 5990f9d | 2010-07-07 18:02:58 | [diff] [blame] | 381 | try: |
| 382 | exec(deps_content, global_scope, local_scope) |
| 383 | except SyntaxError, e: |
| 384 | gclient_utils.SyntaxErrorToError(filepath, e) |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 385 | deps = local_scope.get('deps', {}) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 386 | # load os specific dependencies if defined. these dependencies may |
| 387 | # override or extend the values defined by the 'deps' member. |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 388 | if 'deps_os' in local_scope: |
| 389 | for deps_os_key in self.enforced_os(): |
| 390 | os_deps = local_scope['deps_os'].get(deps_os_key, {}) |
| 391 | if len(self.enforced_os()) > 1: |
| 392 | # Ignore any conflict when including deps for more than one |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 393 | # platform, so we collect the broadest set of dependencies available. |
| 394 | # We may end up with the wrong revision of something for our |
| 395 | # platform, but this is the best we can do. |
| 396 | deps.update([x for x in os_deps.items() if not x[0] in deps]) |
| 397 | else: |
| 398 | deps.update(os_deps) |
| 399 | |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 400 | self.deps_hooks.extend(local_scope.get('hooks', [])) |
| 401 | |
| 402 | # If a line is in custom_deps, but not in the solution, we want to append |
| 403 | # this line to the solution. |
| 404 | for d in self.custom_deps: |
| 405 | if d not in deps: |
| 406 | deps[d] = self.custom_deps[d] |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 407 | |
| 408 | # If use_relative_paths is set in the DEPS file, regenerate |
| 409 | # the dictionary using paths relative to the directory containing |
| 410 | # the DEPS file. |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 411 | use_relative_paths = local_scope.get('use_relative_paths', False) |
| 412 | if use_relative_paths: |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 413 | rel_deps = {} |
| 414 | for d, url in deps.items(): |
| 415 | # normpath is required to allow DEPS to use .. in their |
| 416 | # dependency local path. |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 417 | rel_deps[os.path.normpath(os.path.join(self.name, d))] = url |
| 418 | deps = rel_deps |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 419 | |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 420 | # Convert the deps into real Dependency. |
| 421 | for name, url in deps.iteritems(): |
| 422 | if name in [s.name for s in self.dependencies]: |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 423 | raise gclient_utils.Error( |
| 424 | 'The same name "%s" appears multiple times in the deps section' % |
| 425 | name) |
[email protected] | 0d81244 | 2010-08-10 12:41:08 | [diff] [blame] | 426 | self.dependencies.append(Dependency(self, name, url, None, None, None, |
| 427 | None)) |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 428 | logging.debug('Loaded: %s' % str(self)) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 429 | |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 430 | def run(self, options, revision_overrides, command, args, work_queue): |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 431 | """Runs 'command' before parsing the DEPS in case it's a initial checkout |
| 432 | or a revert.""" |
[email protected] | 861fd0f | 2010-07-23 03:05:05 | [diff] [blame] | 433 | assert self._file_list == [] |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 434 | # When running runhooks, there's no need to consult the SCM. |
| 435 | # All known hooks are expected to run unconditionally regardless of working |
| 436 | # copy state, so skip the SCM status check. |
| 437 | run_scm = command not in ('runhooks', None) |
[email protected] | da7a1f9 | 2010-08-10 17:19:02 | [diff] [blame] | 438 | self.parsed_url = self.LateOverride(self.url) |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 439 | if run_scm and self.parsed_url: |
| 440 | if isinstance(self.parsed_url, self.FileImpl): |
| 441 | # Special support for single-file checkout. |
| 442 | if not command in (None, 'cleanup', 'diff', 'pack', 'status'): |
| 443 | options.revision = self.parsed_url.GetRevision() |
| 444 | scm = gclient_scm.SVNWrapper(self.parsed_url.GetPath(), |
| 445 | self.root_dir(), |
| 446 | self.name) |
| 447 | scm.RunCommand('updatesingle', options, |
| 448 | args + [self.parsed_url.GetFilename()], |
[email protected] | 861fd0f | 2010-07-23 03:05:05 | [diff] [blame] | 449 | self._file_list) |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 450 | else: |
| 451 | options.revision = revision_overrides.get(self.name) |
| 452 | scm = gclient_scm.CreateSCM(self.parsed_url, self.root_dir(), self.name) |
[email protected] | 861fd0f | 2010-07-23 03:05:05 | [diff] [blame] | 453 | scm.RunCommand(command, options, args, self._file_list) |
| 454 | self._file_list = [os.path.join(self.name, f.strip()) |
| 455 | for f in self._file_list] |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 456 | options.revision = None |
[email protected] | f3abb80 | 2010-08-10 17:19:56 | [diff] [blame] | 457 | self.processed = True |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 458 | if self.recursion_limit(): |
| 459 | # Then we can parse the DEPS file. |
| 460 | self.ParseDepsFile(True) |
[email protected] | 621939b | 2010-08-10 20:12:00 | [diff] [blame] | 461 | # Adjust the implicit dependency requirement; e.g. if a DEPS file contains |
| 462 | # both src/foo and src/foo/bar, src/foo/bar is implicitly dependent of |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 463 | # src/foo. Yes, it's O(n^2)... It's important to do that before |
| 464 | # enqueueing them. |
[email protected] | 621939b | 2010-08-10 20:12:00 | [diff] [blame] | 465 | for s in self.dependencies: |
| 466 | for s2 in self.dependencies: |
| 467 | if s is s2: |
| 468 | continue |
| 469 | if s.name.startswith(posixpath.join(s2.name, '')): |
| 470 | s.requirements.append(s2.name) |
| 471 | |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 472 | # Parse the dependencies of this dependency. |
| 473 | for s in self.dependencies: |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 474 | work_queue.enqueue(s) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 475 | |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 476 | def RunHooksRecursively(self, options): |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 477 | """Evaluates all hooks, running actions as needed. run() |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 478 | must have been called before to load the DEPS.""" |
[email protected] | dc7445d | 2010-07-09 21:05:29 | [diff] [blame] | 479 | # If "--force" was specified, run all hooks regardless of what files have |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 480 | # changed. |
| 481 | if self.deps_hooks and self.direct_reference: |
| 482 | # TODO(maruel): If the user is using git or git-svn, then we don't know |
| 483 | # what files have changed so we always run all hooks. It'd be nice to fix |
| 484 | # that. |
| 485 | if (options.force or |
| 486 | isinstance(self.parsed_url, self.FileImpl) or |
| 487 | gclient_scm.GetScmName(self.parsed_url) in ('git', None) or |
| 488 | os.path.isdir(os.path.join(self.root_dir(), self.name, '.git'))): |
| 489 | for hook_dict in self.deps_hooks: |
| 490 | self._RunHookAction(hook_dict, []) |
| 491 | else: |
| 492 | # TODO(phajdan.jr): We should know exactly when the paths are absolute. |
| 493 | # Convert all absolute paths to relative. |
[email protected] | 861fd0f | 2010-07-23 03:05:05 | [diff] [blame] | 494 | file_list = self.file_list() |
| 495 | for i in range(len(file_list)): |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 496 | # It depends on the command being executed (like runhooks vs sync). |
[email protected] | 861fd0f | 2010-07-23 03:05:05 | [diff] [blame] | 497 | if not os.path.isabs(file_list[i]): |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 498 | continue |
[email protected] | dc7445d | 2010-07-09 21:05:29 | [diff] [blame] | 499 | |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 500 | prefix = os.path.commonprefix([self.root_dir().lower(), |
[email protected] | 861fd0f | 2010-07-23 03:05:05 | [diff] [blame] | 501 | file_list[i].lower()]) |
| 502 | file_list[i] = file_list[i][len(prefix):] |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 503 | |
| 504 | # Strip any leading path separators. |
[email protected] | 861fd0f | 2010-07-23 03:05:05 | [diff] [blame] | 505 | while (file_list[i].startswith('\\') or |
| 506 | file_list[i].startswith('/')): |
| 507 | file_list[i] = file_list[i][1:] |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 508 | |
| 509 | # Run hooks on the basis of whether the files from the gclient operation |
| 510 | # match each hook's pattern. |
| 511 | for hook_dict in self.deps_hooks: |
| 512 | pattern = re.compile(hook_dict['pattern']) |
[email protected] | 861fd0f | 2010-07-23 03:05:05 | [diff] [blame] | 513 | matching_file_list = [f for f in file_list if pattern.search(f)] |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 514 | if matching_file_list: |
| 515 | self._RunHookAction(hook_dict, matching_file_list) |
| 516 | if self.recursion_limit(): |
| 517 | for s in self.dependencies: |
| 518 | s.RunHooksRecursively(options) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 519 | |
[email protected] | eaf6106 | 2010-07-07 18:42:39 | [diff] [blame] | 520 | def _RunHookAction(self, hook_dict, matching_file_list): |
| 521 | """Runs the action from a single hook.""" |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 522 | # A single DEPS file can specify multiple hooks so this function can be |
| 523 | # called multiple times on a single Dependency. |
| 524 | #assert self.hooks_ran == False |
[email protected] | f3abb80 | 2010-08-10 17:19:56 | [diff] [blame] | 525 | self.hooks_ran = True |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 526 | logging.debug(hook_dict) |
| 527 | logging.debug(matching_file_list) |
[email protected] | eaf6106 | 2010-07-07 18:42:39 | [diff] [blame] | 528 | command = hook_dict['action'][:] |
| 529 | if command[0] == 'python': |
| 530 | # If the hook specified "python" as the first item, the action is a |
| 531 | # Python script. Run it by starting a new copy of the same |
| 532 | # interpreter. |
| 533 | command[0] = sys.executable |
| 534 | |
| 535 | if '$matching_files' in command: |
| 536 | splice_index = command.index('$matching_files') |
| 537 | command[splice_index:splice_index + 1] = matching_file_list |
| 538 | |
| 539 | # Use a discrete exit status code of 2 to indicate that a hook action |
| 540 | # failed. Users of this script may wish to treat hook action failures |
| 541 | # differently from VC failures. |
| 542 | return gclient_utils.SubprocessCall(command, self.root_dir(), fail_status=2) |
| 543 | |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 544 | def root_dir(self): |
| 545 | return self.parent.root_dir() |
| 546 | |
| 547 | def enforced_os(self): |
| 548 | return self.parent.enforced_os() |
| 549 | |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 550 | def recursion_limit(self): |
| 551 | return self.parent.recursion_limit() - 1 |
| 552 | |
[email protected] | 0d81244 | 2010-08-10 12:41:08 | [diff] [blame] | 553 | def tree(self, include_all): |
| 554 | return self.parent.tree(include_all) |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 555 | |
[email protected] | 0d81244 | 2010-08-10 12:41:08 | [diff] [blame] | 556 | def subtree(self, include_all): |
[email protected] | c57e4f2 | 2010-07-22 21:37:46 | [diff] [blame] | 557 | result = [] |
| 558 | # Add breadth-first. |
[email protected] | 0d81244 | 2010-08-10 12:41:08 | [diff] [blame] | 559 | if self.direct_reference or include_all: |
[email protected] | c57e4f2 | 2010-07-22 21:37:46 | [diff] [blame] | 560 | for d in self.dependencies: |
[email protected] | 044f4e3 | 2010-07-22 21:59:57 | [diff] [blame] | 561 | result.append(d) |
[email protected] | c57e4f2 | 2010-07-22 21:37:46 | [diff] [blame] | 562 | for d in self.dependencies: |
[email protected] | 0d81244 | 2010-08-10 12:41:08 | [diff] [blame] | 563 | result.extend(d.subtree(include_all)) |
[email protected] | c57e4f2 | 2010-07-22 21:37:46 | [diff] [blame] | 564 | return result |
| 565 | |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 566 | def get_custom_deps(self, name, url): |
| 567 | """Returns a custom deps if applicable.""" |
| 568 | if self.parent: |
| 569 | url = self.parent.get_custom_deps(name, url) |
| 570 | # None is a valid return value to disable a dependency. |
| 571 | return self.custom_deps.get(name, url) |
| 572 | |
[email protected] | 861fd0f | 2010-07-23 03:05:05 | [diff] [blame] | 573 | def file_list(self): |
| 574 | result = self._file_list[:] |
| 575 | for d in self.dependencies: |
| 576 | result.extend(d.file_list()) |
| 577 | return result |
| 578 | |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 579 | def __str__(self): |
| 580 | out = [] |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 581 | for i in ('name', 'url', 'parsed_url', 'safesync_url', 'custom_deps', |
| 582 | 'custom_vars', 'deps_hooks', '_file_list', 'processed', |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 583 | 'hooks_ran', 'deps_parsed', 'requirements', 'direct_reference'): |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 584 | # 'deps_file' |
| 585 | if self.__dict__[i]: |
| 586 | out.append('%s: %s' % (i, self.__dict__[i])) |
| 587 | |
| 588 | for d in self.dependencies: |
| 589 | out.extend([' ' + x for x in str(d).splitlines()]) |
| 590 | out.append('') |
| 591 | return '\n'.join(out) |
| 592 | |
| 593 | def __repr__(self): |
| 594 | return '%s: %s' % (self.name, self.url) |
| 595 | |
[email protected] | bffb904 | 2010-07-22 20:59:36 | [diff] [blame] | 596 | def hierarchy(self): |
[email protected] | bc2d2f9 | 2010-07-22 21:26:48 | [diff] [blame] | 597 | """Returns a human-readable hierarchical reference to a Dependency.""" |
[email protected] | bffb904 | 2010-07-22 20:59:36 | [diff] [blame] | 598 | out = '%s(%s)' % (self.name, self.url) |
| 599 | i = self.parent |
| 600 | while i and i.name: |
| 601 | out = '%s(%s) -> %s' % (i.name, i.url, out) |
| 602 | i = i.parent |
| 603 | return out |
| 604 | |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 605 | def root_parent(self): |
| 606 | """Returns the root object, normally a GClient object.""" |
| 607 | d = self |
| 608 | while d.parent: |
| 609 | d = d.parent |
| 610 | return d |
| 611 | |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 612 | |
| 613 | class GClient(Dependency): |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 614 | """Object that represent a gclient checkout. A tree of Dependency(), one per |
| 615 | solution or DEPS entry.""" |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 616 | |
| 617 | DEPS_OS_CHOICES = { |
| 618 | "win32": "win", |
| 619 | "win": "win", |
| 620 | "cygwin": "win", |
| 621 | "darwin": "mac", |
| 622 | "mac": "mac", |
| 623 | "unix": "unix", |
| 624 | "linux": "unix", |
| 625 | "linux2": "unix", |
| 626 | } |
| 627 | |
| 628 | DEFAULT_CLIENT_FILE_TEXT = ("""\ |
| 629 | solutions = [ |
| 630 | { "name" : "%(solution_name)s", |
| 631 | "url" : "%(solution_url)s", |
| 632 | "custom_deps" : { |
| 633 | }, |
[email protected] | 73e2114 | 2010-07-05 13:32:01 | [diff] [blame] | 634 | "safesync_url": "%(safesync_url)s", |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 635 | }, |
| 636 | ] |
| 637 | """) |
| 638 | |
| 639 | DEFAULT_SNAPSHOT_SOLUTION_TEXT = ("""\ |
| 640 | { "name" : "%(solution_name)s", |
| 641 | "url" : "%(solution_url)s", |
| 642 | "custom_deps" : { |
[email protected] | 73e2114 | 2010-07-05 13:32:01 | [diff] [blame] | 643 | %(solution_deps)s }, |
| 644 | "safesync_url": "%(safesync_url)s", |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 645 | }, |
| 646 | """) |
| 647 | |
| 648 | DEFAULT_SNAPSHOT_FILE_TEXT = ("""\ |
| 649 | # Snapshot generated with gclient revinfo --snapshot |
| 650 | solutions = [ |
[email protected] | 73e2114 | 2010-07-05 13:32:01 | [diff] [blame] | 651 | %(solution_list)s] |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 652 | """) |
| 653 | |
| 654 | def __init__(self, root_dir, options): |
[email protected] | 0d81244 | 2010-08-10 12:41:08 | [diff] [blame] | 655 | # Do not change previous behavior. Only solution level and immediate DEPS |
| 656 | # are processed. |
| 657 | self._recursion_limit = 2 |
| 658 | Dependency.__init__(self, None, None, None, None, None, None, None) |
[email protected] | 0d42592 | 2010-06-21 19:22:24 | [diff] [blame] | 659 | self._options = options |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 660 | if options.deps_os: |
| 661 | enforced_os = options.deps_os.split(',') |
| 662 | else: |
| 663 | enforced_os = [self.DEPS_OS_CHOICES.get(sys.platform, 'unix')] |
| 664 | if 'all' in enforced_os: |
| 665 | enforced_os = self.DEPS_OS_CHOICES.itervalues() |
| 666 | self._enforced_os = list(set(enforced_os)) |
| 667 | self._root_dir = root_dir |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 668 | self.config_content = None |
| 669 | |
| 670 | def SetConfig(self, content): |
| 671 | assert self.dependencies == [] |
| 672 | config_dict = {} |
| 673 | self.config_content = content |
| 674 | try: |
| 675 | exec(content, config_dict) |
| 676 | except SyntaxError, e: |
[email protected] | 5990f9d | 2010-07-07 18:02:58 | [diff] [blame] | 677 | gclient_utils.SyntaxErrorToError('.gclient', e) |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 678 | for s in config_dict.get('solutions', []): |
[email protected] | 81843b8 | 2010-06-28 16:49:26 | [diff] [blame] | 679 | try: |
| 680 | self.dependencies.append(Dependency( |
| 681 | self, s['name'], s['url'], |
| 682 | s.get('safesync_url', None), |
| 683 | s.get('custom_deps', {}), |
[email protected] | 0d81244 | 2010-08-10 12:41:08 | [diff] [blame] | 684 | s.get('custom_vars', {}), |
| 685 | None)) |
[email protected] | 81843b8 | 2010-06-28 16:49:26 | [diff] [blame] | 686 | except KeyError: |
| 687 | raise gclient_utils.Error('Invalid .gclient file. Solution is ' |
| 688 | 'incomplete: %s' % s) |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 689 | # .gclient can have hooks. |
| 690 | self.deps_hooks = config_dict.get('hooks', []) |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 691 | self.direct_reference = True |
| 692 | self.deps_parsed = True |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 693 | |
| 694 | def SaveConfig(self): |
| 695 | gclient_utils.FileWrite(os.path.join(self.root_dir(), |
| 696 | self._options.config_filename), |
| 697 | self.config_content) |
| 698 | |
| 699 | @staticmethod |
| 700 | def LoadCurrentConfig(options): |
| 701 | """Searches for and loads a .gclient file relative to the current working |
| 702 | dir. Returns a GClient object.""" |
| 703 | path = gclient_utils.FindGclientRoot(os.getcwd(), options.config_filename) |
| 704 | if not path: |
| 705 | return None |
| 706 | client = GClient(path, options) |
| 707 | client.SetConfig(gclient_utils.FileRead( |
| 708 | os.path.join(path, options.config_filename))) |
| 709 | return client |
| 710 | |
| 711 | def SetDefaultConfig(self, solution_name, solution_url, safesync_url): |
| 712 | self.SetConfig(self.DEFAULT_CLIENT_FILE_TEXT % { |
| 713 | 'solution_name': solution_name, |
| 714 | 'solution_url': solution_url, |
| 715 | 'safesync_url' : safesync_url, |
| 716 | }) |
| 717 | |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 718 | def _SaveEntries(self): |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 719 | """Creates a .gclient_entries file to record the list of unique checkouts. |
| 720 | |
| 721 | The .gclient_entries file lives in the same directory as .gclient. |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 722 | """ |
| 723 | # Sometimes pprint.pformat will use {', sometimes it'll use { ' ... It |
| 724 | # makes testing a bit too fun. |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 725 | result = 'entries = {\n' |
| 726 | for entry in self.tree(False): |
| 727 | # Skip over File() dependencies as we can't version them. |
| 728 | if not isinstance(entry.parsed_url, self.FileImpl): |
| 729 | result += ' %s: %s,\n' % (pprint.pformat(entry.name), |
| 730 | pprint.pformat(entry.parsed_url)) |
| 731 | result += '}\n' |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 732 | file_path = os.path.join(self.root_dir(), self._options.entries_filename) |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 733 | logging.info(result) |
| 734 | gclient_utils.FileWrite(file_path, result) |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 735 | |
| 736 | def _ReadEntries(self): |
| 737 | """Read the .gclient_entries file for the given client. |
| 738 | |
| 739 | Returns: |
| 740 | A sequence of solution names, which will be empty if there is the |
| 741 | entries file hasn't been created yet. |
| 742 | """ |
| 743 | scope = {} |
| 744 | filename = os.path.join(self.root_dir(), self._options.entries_filename) |
| 745 | if not os.path.exists(filename): |
[email protected] | 73e2114 | 2010-07-05 13:32:01 | [diff] [blame] | 746 | return {} |
[email protected] | 5990f9d | 2010-07-07 18:02:58 | [diff] [blame] | 747 | try: |
| 748 | exec(gclient_utils.FileRead(filename), scope) |
| 749 | except SyntaxError, e: |
| 750 | gclient_utils.SyntaxErrorToError(filename, e) |
[email protected] | 9a66ddf | 2010-06-16 16:54:16 | [diff] [blame] | 751 | return scope['entries'] |
| 752 | |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 753 | def _EnforceRevisions(self): |
[email protected] | 918a9ae | 2010-05-28 15:50:30 | [diff] [blame] | 754 | """Checks for revision overrides.""" |
| 755 | revision_overrides = {} |
[email protected] | 307d179 | 2010-05-31 20:03:13 | [diff] [blame] | 756 | if self._options.head: |
| 757 | return revision_overrides |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 758 | for s in self.dependencies: |
| 759 | if not s.safesync_url: |
[email protected] | 307d179 | 2010-05-31 20:03:13 | [diff] [blame] | 760 | continue |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 761 | handle = urllib.urlopen(s.safesync_url) |
[email protected] | 307d179 | 2010-05-31 20:03:13 | [diff] [blame] | 762 | rev = handle.read().strip() |
| 763 | handle.close() |
| 764 | if len(rev): |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 765 | self._options.revisions.append('%s@%s' % (s.name, rev)) |
[email protected] | 307d179 | 2010-05-31 20:03:13 | [diff] [blame] | 766 | if not self._options.revisions: |
| 767 | return revision_overrides |
| 768 | # --revision will take over safesync_url. |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 769 | solutions_names = [s.name for s in self.dependencies] |
[email protected] | 307d179 | 2010-05-31 20:03:13 | [diff] [blame] | 770 | index = 0 |
| 771 | for revision in self._options.revisions: |
| 772 | if not '@' in revision: |
| 773 | # Support for --revision 123 |
| 774 | revision = '%s@%s' % (solutions_names[index], revision) |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 775 | sol, rev = revision.split('@', 1) |
[email protected] | 307d179 | 2010-05-31 20:03:13 | [diff] [blame] | 776 | if not sol in solutions_names: |
| 777 | #raise gclient_utils.Error('%s is not a valid solution.' % sol) |
| 778 | print >> sys.stderr, ('Please fix your script, having invalid ' |
| 779 | '--revision flags will soon considered an error.') |
| 780 | else: |
[email protected] | 918a9ae | 2010-05-28 15:50:30 | [diff] [blame] | 781 | revision_overrides[sol] = rev |
[email protected] | 307d179 | 2010-05-31 20:03:13 | [diff] [blame] | 782 | index += 1 |
[email protected] | 918a9ae | 2010-05-28 15:50:30 | [diff] [blame] | 783 | return revision_overrides |
| 784 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 785 | def RunOnDeps(self, command, args): |
| 786 | """Runs a command on each dependency in a client and its dependencies. |
| 787 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 788 | Args: |
| 789 | command: The command to use (e.g., 'status' or 'diff') |
| 790 | args: list of str - extra arguments to add to the command line. |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 791 | """ |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 792 | if not self.dependencies: |
[email protected] | 73e2114 | 2010-07-05 13:32:01 | [diff] [blame] | 793 | raise gclient_utils.Error('No solution specified') |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 794 | revision_overrides = self._EnforceRevisions() |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 795 | pm = None |
[email protected] | d2e9256 | 2010-04-27 01:55:18 | [diff] [blame] | 796 | if command == 'update' and not self._options.verbose: |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 797 | pm = Progress('Syncing projects', 1) |
| 798 | work_queue = ExecutionQueue(pm) |
| 799 | for s in self.dependencies: |
| 800 | work_queue.enqueue(s) |
| 801 | work_queue.flush(self._options, revision_overrides, command, args, |
| 802 | work_queue) |
[email protected] | 6f36372 | 2010-04-27 00:41:09 | [diff] [blame] | 803 | |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 804 | # Once all the dependencies have been processed, it's now safe to run the |
| 805 | # hooks. |
| 806 | if not self._options.nohooks: |
| 807 | self.RunHooksRecursively(self._options) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 808 | |
| 809 | if command == 'update': |
[email protected] | cdcee80 | 2009-06-23 15:30:42 | [diff] [blame] | 810 | # Notify the user if there is an orphaned entry in their working copy. |
| 811 | # Only delete the directory if there are no changes in it, and |
| 812 | # delete_unversioned_trees is set to true. |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 813 | entries = [i.name for i in self.tree(False)] |
| 814 | for entry, prev_url in self._ReadEntries().iteritems(): |
[email protected] | c5e9aec | 2009-08-03 18:25:56 | [diff] [blame] | 815 | # Fix path separator on Windows. |
| 816 | entry_fixed = entry.replace('/', os.path.sep) |
[email protected] | 75a5927 | 2010-06-11 22:34:03 | [diff] [blame] | 817 | e_dir = os.path.join(self.root_dir(), entry_fixed) |
[email protected] | c5e9aec | 2009-08-03 18:25:56 | [diff] [blame] | 818 | # Use entry and not entry_fixed there. |
[email protected] | 0329e67 | 2009-05-13 18:41:04 | [diff] [blame] | 819 | if entry not in entries and os.path.exists(e_dir): |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 820 | file_list = [] |
| 821 | scm = gclient_scm.CreateSCM(prev_url, self.root_dir(), entry_fixed) |
| 822 | scm.status(self._options, [], file_list) |
| 823 | modified_files = file_list != [] |
[email protected] | 8301701 | 2009-09-28 18:52:12 | [diff] [blame] | 824 | if not self._options.delete_unversioned_trees or modified_files: |
[email protected] | c5e9aec | 2009-08-03 18:25:56 | [diff] [blame] | 825 | # There are modified files in this entry. Keep warning until |
| 826 | # removed. |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 827 | print(('\nWARNING: \'%s\' is no longer part of this client. ' |
| 828 | 'It is recommended that you manually remove it.\n') % |
[email protected] | c5e9aec | 2009-08-03 18:25:56 | [diff] [blame] | 829 | entry_fixed) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 830 | else: |
| 831 | # Delete the entry |
[email protected] | 73e2114 | 2010-07-05 13:32:01 | [diff] [blame] | 832 | print('\n________ deleting \'%s\' in \'%s\'' % ( |
| 833 | entry_fixed, self.root_dir())) |
[email protected] | 5f3eee3 | 2009-09-17 00:34:30 | [diff] [blame] | 834 | gclient_utils.RemoveDirectory(e_dir) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 835 | # record the current list of entries for next time |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 836 | self._SaveEntries() |
[email protected] | 17cdf76 | 2010-05-28 17:30:52 | [diff] [blame] | 837 | return 0 |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 838 | |
| 839 | def PrintRevInfo(self): |
[email protected] | 54a07a2 | 2010-06-14 19:07:39 | [diff] [blame] | 840 | if not self.dependencies: |
[email protected] | 73e2114 | 2010-07-05 13:32:01 | [diff] [blame] | 841 | raise gclient_utils.Error('No solution specified') |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 842 | # Load all the settings. |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 843 | work_queue = ExecutionQueue(None) |
| 844 | for s in self.dependencies: |
| 845 | work_queue.enqueue(s) |
| 846 | work_queue.flush(self._options, {}, None, [], work_queue) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 847 | |
[email protected] | 6da25d0 | 2010-08-11 17:32:55 | [diff] [blame] | 848 | def GetURLAndRev(dep): |
| 849 | """Returns the revision-qualified SCM url for a Dependency.""" |
| 850 | if dep.parsed_url is None: |
[email protected] | baa578e | 2010-07-12 17:36:59 | [diff] [blame] | 851 | return None |
[email protected] | 6da25d0 | 2010-08-11 17:32:55 | [diff] [blame] | 852 | if isinstance(dep.parsed_url, self.FileImpl): |
| 853 | original_url = dep.parsed_url.file_location |
| 854 | else: |
| 855 | original_url = dep.parsed_url |
[email protected] | 5d63eb8 | 2010-03-24 23:22:09 | [diff] [blame] | 856 | url, _ = gclient_utils.SplitUrlRevision(original_url) |
[email protected] | 6da25d0 | 2010-08-11 17:32:55 | [diff] [blame] | 857 | scm = gclient_scm.CreateSCM(original_url, self.root_dir(), dep.name) |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 858 | if not os.path.isdir(scm.checkout_path): |
| 859 | return None |
[email protected] | baa578e | 2010-07-12 17:36:59 | [diff] [blame] | 860 | return '%s@%s' % (url, scm.revinfo(self._options, [], None)) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 861 | |
[email protected] | baa578e | 2010-07-12 17:36:59 | [diff] [blame] | 862 | if self._options.snapshot: |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 863 | new_gclient = '' |
| 864 | # First level at .gclient |
| 865 | for d in self.dependencies: |
| 866 | entries = {} |
[email protected] | 6da25d0 | 2010-08-11 17:32:55 | [diff] [blame] | 867 | def GrabDeps(dep): |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 868 | """Recursively grab dependencies.""" |
[email protected] | 6da25d0 | 2010-08-11 17:32:55 | [diff] [blame] | 869 | for d in dep.dependencies: |
| 870 | entries[d.name] = GetURLAndRev(d) |
| 871 | GrabDeps(d) |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 872 | GrabDeps(d) |
| 873 | custom_deps = [] |
| 874 | for k in sorted(entries.keys()): |
| 875 | if entries[k]: |
| 876 | # Quotes aren't escaped... |
| 877 | custom_deps.append(' \"%s\": \'%s\',\n' % (k, entries[k])) |
| 878 | else: |
| 879 | custom_deps.append(' \"%s\": None,\n' % k) |
| 880 | new_gclient += self.DEFAULT_SNAPSHOT_SOLUTION_TEXT % { |
| 881 | 'solution_name': d.name, |
| 882 | 'solution_url': d.url, |
| 883 | 'safesync_url' : d.safesync_url or '', |
| 884 | 'solution_deps': ''.join(custom_deps), |
| 885 | } |
| 886 | # Print the snapshot configuration file |
| 887 | print(self.DEFAULT_SNAPSHOT_FILE_TEXT % {'solution_list': new_gclient}) |
[email protected] | de8f352 | 2010-03-11 23:47:44 | [diff] [blame] | 888 | else: |
[email protected] | b1e315f | 2010-08-11 18:44:50 | [diff] [blame] | 889 | entries = {} |
| 890 | for d in self.tree(False): |
| 891 | if self._options.actual: |
| 892 | entries[d.name] = GetURLAndRev(d) |
| 893 | else: |
| 894 | entries[d.name] = d.parsed_url |
| 895 | keys = sorted(entries.keys()) |
| 896 | for x in keys: |
| 897 | line = '%s: %s' % (x, entries[x]) |
| 898 | if x is not keys[-1]: |
[email protected] | df2b315 | 2010-07-21 17:35:24 | [diff] [blame] | 899 | line += ';' |
| 900 | print line |
[email protected] | dde32ee | 2010-08-10 17:44:05 | [diff] [blame] | 901 | logging.info(str(self)) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 902 | |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 903 | def ParseDepsFile(self, direct_reference): |
| 904 | """No DEPS to parse for a .gclient file.""" |
[email protected] | 049bced | 2010-08-12 13:37:20 | [diff] [blame^] | 905 | raise gclient_utils.Error('Internal error') |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 906 | |
[email protected] | 75a5927 | 2010-06-11 22:34:03 | [diff] [blame] | 907 | def root_dir(self): |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 908 | """Root directory of gclient checkout.""" |
[email protected] | 75a5927 | 2010-06-11 22:34:03 | [diff] [blame] | 909 | return self._root_dir |
| 910 | |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 911 | def enforced_os(self): |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 912 | """What deps_os entries that are to be parsed.""" |
[email protected] | 271375b | 2010-06-23 19:17:38 | [diff] [blame] | 913 | return self._enforced_os |
| 914 | |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 915 | def recursion_limit(self): |
| 916 | """How recursive can each dependencies in DEPS file can load DEPS file.""" |
| 917 | return self._recursion_limit |
| 918 | |
[email protected] | 0d81244 | 2010-08-10 12:41:08 | [diff] [blame] | 919 | def tree(self, include_all): |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 920 | """Returns a flat list of all the dependencies.""" |
[email protected] | 0d81244 | 2010-08-10 12:41:08 | [diff] [blame] | 921 | return self.subtree(include_all) |
[email protected] | d36fba8 | 2010-06-28 16:50:40 | [diff] [blame] | 922 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 923 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 924 | #### gclient commands. |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 925 | |
| 926 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 927 | def CMDcleanup(parser, args): |
| 928 | """Cleans up all working copies. |
[email protected] | ddff62d | 2010-05-17 21:02:36 | [diff] [blame] | 929 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 930 | Mostly svn-specific. Simply runs 'svn cleanup' for each module. |
[email protected] | 79692d6 | 2010-05-14 18:57:13 | [diff] [blame] | 931 | """ |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 932 | parser.add_option('--deps', dest='deps_os', metavar='OS_LIST', |
| 933 | help='override deps for the specified (comma-separated) ' |
| 934 | 'platform(s); \'all\' will process all deps_os ' |
| 935 | 'references') |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 936 | (options, args) = parser.parse_args(args) |
[email protected] | 2806acc | 2009-05-15 12:33:34 | [diff] [blame] | 937 | client = GClient.LoadCurrentConfig(options) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 938 | if not client: |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 939 | raise gclient_utils.Error('client not configured; see \'gclient config\'') |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 940 | if options.verbose: |
| 941 | # Print out the .gclient file. This is longer than if we just printed the |
| 942 | # client dict, but more legible, and it might contain helpful comments. |
[email protected] | 116704f | 2010-06-11 17:34:38 | [diff] [blame] | 943 | print(client.config_content) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 944 | return client.RunOnDeps('cleanup', args) |
| 945 | |
| 946 | |
[email protected] | 4b90e3a | 2010-07-01 20:28:26 | [diff] [blame] | 947 | @attr('usage', '[command] [args ...]') |
| 948 | def CMDrecurse(parser, args): |
| 949 | """Operates on all the entries. |
| 950 | |
| 951 | Runs a shell command on all entries. |
| 952 | """ |
| 953 | # Stop parsing at the first non-arg so that these go through to the command |
| 954 | parser.disable_interspersed_args() |
| 955 | parser.add_option('-s', '--scm', action='append', default=[], |
| 956 | help='choose scm types to operate upon') |
| 957 | options, args = parser.parse_args(args) |
| 958 | root, entries = gclient_utils.GetGClientRootAndEntries() |
| 959 | scm_set = set() |
| 960 | for scm in options.scm: |
| 961 | scm_set.update(scm.split(',')) |
| 962 | |
| 963 | # Pass in the SCM type as an env variable |
| 964 | env = os.environ.copy() |
| 965 | |
| 966 | for path, url in entries.iteritems(): |
| 967 | scm = gclient_scm.GetScmName(url) |
| 968 | if scm_set and scm not in scm_set: |
| 969 | continue |
| 970 | dir = os.path.normpath(os.path.join(root, path)) |
| 971 | env['GCLIENT_SCM'] = scm |
| 972 | env['GCLIENT_URL'] = url |
| 973 | subprocess.Popen(args, cwd=dir, env=env).communicate() |
| 974 | |
| 975 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 976 | @attr('usage', '[url] [safesync url]') |
| 977 | def CMDconfig(parser, args): |
[email protected] | ddff62d | 2010-05-17 21:02:36 | [diff] [blame] | 978 | """Create a .gclient file in the current directory. |
| 979 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 980 | This specifies the configuration for further commands. After update/sync, |
[email protected] | 79692d6 | 2010-05-14 18:57:13 | [diff] [blame] | 981 | top-level DEPS files in each module are read to determine dependent |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 982 | modules to operate on as well. If optional [url] parameter is |
[email protected] | 79692d6 | 2010-05-14 18:57:13 | [diff] [blame] | 983 | provided, then configuration is read from a specified Subversion server |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 984 | URL. |
[email protected] | 79692d6 | 2010-05-14 18:57:13 | [diff] [blame] | 985 | """ |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 986 | parser.add_option('--spec', |
| 987 | help='create a gclient file containing the provided ' |
| 988 | 'string. Due to Cygwin/Python brokenness, it ' |
| 989 | 'probably can\'t contain any newlines.') |
| 990 | parser.add_option('--name', |
| 991 | help='overrides the default name for the solution') |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 992 | (options, args) = parser.parse_args(args) |
[email protected] | 5fc2a33 | 2010-05-26 19:37:15 | [diff] [blame] | 993 | if ((options.spec and args) or len(args) > 2 or |
| 994 | (not options.spec and not args)): |
| 995 | parser.error('Inconsistent arguments. Use either --spec or one or 2 args') |
| 996 | |
[email protected] | 0329e67 | 2009-05-13 18:41:04 | [diff] [blame] | 997 | if os.path.exists(options.config_filename): |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 998 | raise gclient_utils.Error('%s file already exists in the current directory' |
[email protected] | e3608df | 2009-11-10 20:22:57 | [diff] [blame] | 999 | % options.config_filename) |
[email protected] | 2806acc | 2009-05-15 12:33:34 | [diff] [blame] | 1000 | client = GClient('.', options) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1001 | if options.spec: |
| 1002 | client.SetConfig(options.spec) |
| 1003 | else: |
[email protected] | 1ab7ffc | 2009-06-03 17:21:37 | [diff] [blame] | 1004 | base_url = args[0].rstrip('/') |
[email protected] | 8cf7a39 | 2010-04-07 17:20:26 | [diff] [blame] | 1005 | if not options.name: |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1006 | name = base_url.split('/')[-1] |
[email protected] | 8cf7a39 | 2010-04-07 17:20:26 | [diff] [blame] | 1007 | else: |
| 1008 | # specify an alternate relpath for the given URL. |
| 1009 | name = options.name |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1010 | safesync_url = '' |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1011 | if len(args) > 1: |
| 1012 | safesync_url = args[1] |
| 1013 | client.SetDefaultConfig(name, base_url, safesync_url) |
| 1014 | client.SaveConfig() |
[email protected] | 79692d6 | 2010-05-14 18:57:13 | [diff] [blame] | 1015 | return 0 |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1016 | |
| 1017 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1018 | def CMDexport(parser, args): |
[email protected] | ddff62d | 2010-05-17 21:02:36 | [diff] [blame] | 1019 | """Wrapper for svn export for all managed directories.""" |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1020 | parser.add_option('--deps', dest='deps_os', metavar='OS_LIST', |
| 1021 | help='override deps for the specified (comma-separated) ' |
| 1022 | 'platform(s); \'all\' will process all deps_os ' |
| 1023 | 'references') |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1024 | (options, args) = parser.parse_args(args) |
[email protected] | 644aa0c | 2009-07-17 20:20:41 | [diff] [blame] | 1025 | if len(args) != 1: |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1026 | raise gclient_utils.Error('Need directory name') |
[email protected] | 644aa0c | 2009-07-17 20:20:41 | [diff] [blame] | 1027 | client = GClient.LoadCurrentConfig(options) |
| 1028 | |
| 1029 | if not client: |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1030 | raise gclient_utils.Error('client not configured; see \'gclient config\'') |
[email protected] | 644aa0c | 2009-07-17 20:20:41 | [diff] [blame] | 1031 | |
| 1032 | if options.verbose: |
| 1033 | # Print out the .gclient file. This is longer than if we just printed the |
| 1034 | # client dict, but more legible, and it might contain helpful comments. |
[email protected] | 116704f | 2010-06-11 17:34:38 | [diff] [blame] | 1035 | print(client.config_content) |
[email protected] | 644aa0c | 2009-07-17 20:20:41 | [diff] [blame] | 1036 | return client.RunOnDeps('export', args) |
| 1037 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1038 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1039 | @attr('epilog', """Example: |
| 1040 | gclient pack > patch.txt |
| 1041 | generate simple patch for configured client and dependences |
| 1042 | """) |
| 1043 | def CMDpack(parser, args): |
[email protected] | 79692d6 | 2010-05-14 18:57:13 | [diff] [blame] | 1044 | """Generate a patch which can be applied at the root of the tree. |
[email protected] | ddff62d | 2010-05-17 21:02:36 | [diff] [blame] | 1045 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1046 | Internally, runs 'svn diff'/'git diff' on each checked out module and |
[email protected] | 79692d6 | 2010-05-14 18:57:13 | [diff] [blame] | 1047 | dependencies, and performs minimal postprocessing of the output. The |
| 1048 | resulting patch is printed to stdout and can be applied to a freshly |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1049 | checked out tree via 'patch -p0 < patchfile'. |
[email protected] | 79692d6 | 2010-05-14 18:57:13 | [diff] [blame] | 1050 | """ |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1051 | parser.add_option('--deps', dest='deps_os', metavar='OS_LIST', |
| 1052 | help='override deps for the specified (comma-separated) ' |
| 1053 | 'platform(s); \'all\' will process all deps_os ' |
| 1054 | 'references') |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1055 | (options, args) = parser.parse_args(args) |
[email protected] | ab31859 | 2009-09-04 00:54:55 | [diff] [blame] | 1056 | client = GClient.LoadCurrentConfig(options) |
| 1057 | if not client: |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1058 | raise gclient_utils.Error('client not configured; see \'gclient config\'') |
[email protected] | ab31859 | 2009-09-04 00:54:55 | [diff] [blame] | 1059 | if options.verbose: |
| 1060 | # Print out the .gclient file. This is longer than if we just printed the |
| 1061 | # client dict, but more legible, and it might contain helpful comments. |
[email protected] | 116704f | 2010-06-11 17:34:38 | [diff] [blame] | 1062 | print(client.config_content) |
[email protected] | ab31859 | 2009-09-04 00:54:55 | [diff] [blame] | 1063 | return client.RunOnDeps('pack', args) |
| 1064 | |
| 1065 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1066 | def CMDstatus(parser, args): |
| 1067 | """Show modification status for every dependencies.""" |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1068 | parser.add_option('--deps', dest='deps_os', metavar='OS_LIST', |
| 1069 | help='override deps for the specified (comma-separated) ' |
| 1070 | 'platform(s); \'all\' will process all deps_os ' |
| 1071 | 'references') |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1072 | (options, args) = parser.parse_args(args) |
[email protected] | 2806acc | 2009-05-15 12:33:34 | [diff] [blame] | 1073 | client = GClient.LoadCurrentConfig(options) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1074 | if not client: |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1075 | raise gclient_utils.Error('client not configured; see \'gclient config\'') |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1076 | if options.verbose: |
| 1077 | # Print out the .gclient file. This is longer than if we just printed the |
| 1078 | # client dict, but more legible, and it might contain helpful comments. |
[email protected] | 116704f | 2010-06-11 17:34:38 | [diff] [blame] | 1079 | print(client.config_content) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1080 | return client.RunOnDeps('status', args) |
| 1081 | |
| 1082 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1083 | @attr('epilog', """Examples: |
[email protected] | 79692d6 | 2010-05-14 18:57:13 | [diff] [blame] | 1084 | gclient sync |
| 1085 | update files from SCM according to current configuration, |
| 1086 | *for modules which have changed since last update or sync* |
| 1087 | gclient sync --force |
| 1088 | update files from SCM according to current configuration, for |
| 1089 | all modules (useful for recovering files deleted from local copy) |
| 1090 | gclient sync --revision src@31000 |
| 1091 | update src directory to r31000 |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1092 | """) |
| 1093 | def CMDsync(parser, args): |
| 1094 | """Checkout/update all modules.""" |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1095 | parser.add_option('-f', '--force', action='store_true', |
| 1096 | help='force update even for unchanged modules') |
| 1097 | parser.add_option('-n', '--nohooks', action='store_true', |
| 1098 | help='don\'t run hooks after the update is complete') |
| 1099 | parser.add_option('-r', '--revision', action='append', |
| 1100 | dest='revisions', metavar='REV', default=[], |
| 1101 | help='Enforces revision/hash for the solutions with the ' |
| 1102 | 'format src@rev. The src@ part is optional and can be ' |
| 1103 | 'skipped. -r can be used multiple times when .gclient ' |
| 1104 | 'has multiple solutions configured and will work even ' |
| 1105 | 'if the src@ part is skipped.') |
| 1106 | parser.add_option('-H', '--head', action='store_true', |
| 1107 | help='skips any safesync_urls specified in ' |
| 1108 | 'configured solutions and sync to head instead') |
| 1109 | parser.add_option('-D', '--delete_unversioned_trees', action='store_true', |
| 1110 | help='delete any unexpected unversioned trees ' |
| 1111 | 'that are in the checkout') |
| 1112 | parser.add_option('-R', '--reset', action='store_true', |
| 1113 | help='resets any local changes before updating (git only)') |
| 1114 | parser.add_option('--deps', dest='deps_os', metavar='OS_LIST', |
| 1115 | help='override deps for the specified (comma-separated) ' |
| 1116 | 'platform(s); \'all\' will process all deps_os ' |
| 1117 | 'references') |
| 1118 | parser.add_option('-m', '--manually_grab_svn_rev', action='store_true', |
| 1119 | help='Skip svn up whenever possible by requesting ' |
| 1120 | 'actual HEAD revision from the repository') |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1121 | (options, args) = parser.parse_args(args) |
[email protected] | 2806acc | 2009-05-15 12:33:34 | [diff] [blame] | 1122 | client = GClient.LoadCurrentConfig(options) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1123 | |
| 1124 | if not client: |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1125 | raise gclient_utils.Error('client not configured; see \'gclient config\'') |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1126 | |
[email protected] | 307d179 | 2010-05-31 20:03:13 | [diff] [blame] | 1127 | if options.revisions and options.head: |
| 1128 | # TODO(maruel): Make it a parser.error if it doesn't break any builder. |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1129 | print('Warning: you cannot use both --head and --revision') |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1130 | |
| 1131 | if options.verbose: |
| 1132 | # Print out the .gclient file. This is longer than if we just printed the |
| 1133 | # client dict, but more legible, and it might contain helpful comments. |
[email protected] | 116704f | 2010-06-11 17:34:38 | [diff] [blame] | 1134 | print(client.config_content) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1135 | return client.RunOnDeps('update', args) |
| 1136 | |
| 1137 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1138 | def CMDupdate(parser, args): |
[email protected] | ddff62d | 2010-05-17 21:02:36 | [diff] [blame] | 1139 | """Alias for the sync command. Deprecated.""" |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1140 | return CMDsync(parser, args) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1141 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1142 | def CMDdiff(parser, args): |
| 1143 | """Displays local diff for every dependencies.""" |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1144 | parser.add_option('--deps', dest='deps_os', metavar='OS_LIST', |
| 1145 | help='override deps for the specified (comma-separated) ' |
| 1146 | 'platform(s); \'all\' will process all deps_os ' |
| 1147 | 'references') |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1148 | (options, args) = parser.parse_args(args) |
[email protected] | 2806acc | 2009-05-15 12:33:34 | [diff] [blame] | 1149 | client = GClient.LoadCurrentConfig(options) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1150 | if not client: |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1151 | raise gclient_utils.Error('client not configured; see \'gclient config\'') |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1152 | if options.verbose: |
| 1153 | # Print out the .gclient file. This is longer than if we just printed the |
| 1154 | # client dict, but more legible, and it might contain helpful comments. |
[email protected] | 116704f | 2010-06-11 17:34:38 | [diff] [blame] | 1155 | print(client.config_content) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1156 | return client.RunOnDeps('diff', args) |
| 1157 | |
| 1158 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1159 | def CMDrevert(parser, args): |
| 1160 | """Revert all modifications in every dependencies.""" |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1161 | parser.add_option('--deps', dest='deps_os', metavar='OS_LIST', |
| 1162 | help='override deps for the specified (comma-separated) ' |
| 1163 | 'platform(s); \'all\' will process all deps_os ' |
| 1164 | 'references') |
| 1165 | parser.add_option('-n', '--nohooks', action='store_true', |
| 1166 | help='don\'t run hooks after the revert is complete') |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1167 | (options, args) = parser.parse_args(args) |
| 1168 | # --force is implied. |
| 1169 | options.force = True |
[email protected] | 2806acc | 2009-05-15 12:33:34 | [diff] [blame] | 1170 | client = GClient.LoadCurrentConfig(options) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1171 | if not client: |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1172 | raise gclient_utils.Error('client not configured; see \'gclient config\'') |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1173 | return client.RunOnDeps('revert', args) |
| 1174 | |
| 1175 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1176 | def CMDrunhooks(parser, args): |
| 1177 | """Runs hooks for files that have been modified in the local working copy.""" |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1178 | parser.add_option('--deps', dest='deps_os', metavar='OS_LIST', |
| 1179 | help='override deps for the specified (comma-separated) ' |
| 1180 | 'platform(s); \'all\' will process all deps_os ' |
| 1181 | 'references') |
| 1182 | parser.add_option('-f', '--force', action='store_true', default=True, |
| 1183 | help='Deprecated. No effect.') |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1184 | (options, args) = parser.parse_args(args) |
[email protected] | 2806acc | 2009-05-15 12:33:34 | [diff] [blame] | 1185 | client = GClient.LoadCurrentConfig(options) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1186 | if not client: |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1187 | raise gclient_utils.Error('client not configured; see \'gclient config\'') |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1188 | if options.verbose: |
| 1189 | # Print out the .gclient file. This is longer than if we just printed the |
| 1190 | # client dict, but more legible, and it might contain helpful comments. |
[email protected] | 116704f | 2010-06-11 17:34:38 | [diff] [blame] | 1191 | print(client.config_content) |
[email protected] | 5df6a46 | 2009-08-28 18:52:26 | [diff] [blame] | 1192 | options.force = True |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1193 | options.nohooks = False |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1194 | return client.RunOnDeps('runhooks', args) |
| 1195 | |
| 1196 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1197 | def CMDrevinfo(parser, args): |
[email protected] | 9eda411 | 2010-06-11 18:56:10 | [diff] [blame] | 1198 | """Output revision info mapping for the client and its dependencies. |
| 1199 | |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1200 | This allows the capture of an overall 'revision' for the source tree that |
[email protected] | 9eda411 | 2010-06-11 18:56:10 | [diff] [blame] | 1201 | can be used to reproduce the same tree in the future. It is only useful for |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1202 | 'unpinned dependencies', i.e. DEPS/deps references without a svn revision |
| 1203 | number or a git hash. A git branch name isn't 'pinned' since the actual |
[email protected] | 9eda411 | 2010-06-11 18:56:10 | [diff] [blame] | 1204 | commit can change. |
| 1205 | """ |
| 1206 | parser.add_option('--deps', dest='deps_os', metavar='OS_LIST', |
| 1207 | help='override deps for the specified (comma-separated) ' |
| 1208 | 'platform(s); \'all\' will process all deps_os ' |
| 1209 | 'references') |
[email protected] | b1e315f | 2010-08-11 18:44:50 | [diff] [blame] | 1210 | parser.add_option('-a', '--actual', action='store_true', |
| 1211 | help='gets the actual checked out revisions instead of the ' |
| 1212 | 'ones specified in the DEPS and .gclient files') |
[email protected] | 9eda411 | 2010-06-11 18:56:10 | [diff] [blame] | 1213 | parser.add_option('-s', '--snapshot', action='store_true', |
| 1214 | help='creates a snapshot .gclient file of the current ' |
[email protected] | b1e315f | 2010-08-11 18:44:50 | [diff] [blame] | 1215 | 'version of all repositories to reproduce the tree, ' |
| 1216 | 'implies -a') |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1217 | (options, args) = parser.parse_args(args) |
[email protected] | 2806acc | 2009-05-15 12:33:34 | [diff] [blame] | 1218 | client = GClient.LoadCurrentConfig(options) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1219 | if not client: |
[email protected] | 0b6a084 | 2010-06-15 14:34:19 | [diff] [blame] | 1220 | raise gclient_utils.Error('client not configured; see \'gclient config\'') |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1221 | client.PrintRevInfo() |
[email protected] | 79692d6 | 2010-05-14 18:57:13 | [diff] [blame] | 1222 | return 0 |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1223 | |
| 1224 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1225 | def Command(name): |
| 1226 | return getattr(sys.modules[__name__], 'CMD' + name, None) |
| 1227 | |
| 1228 | |
| 1229 | def CMDhelp(parser, args): |
| 1230 | """Prints list of commands or help for a specific command.""" |
[email protected] | 6e29d57 | 2010-06-04 17:32:20 | [diff] [blame] | 1231 | (_, args) = parser.parse_args(args) |
[email protected] | ddff62d | 2010-05-17 21:02:36 | [diff] [blame] | 1232 | if len(args) == 1: |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1233 | return Main(args + ['--help']) |
[email protected] | ddff62d | 2010-05-17 21:02:36 | [diff] [blame] | 1234 | parser.print_help() |
| 1235 | return 0 |
| 1236 | |
| 1237 | |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1238 | def GenUsage(parser, command): |
| 1239 | """Modify an OptParse object with the function's documentation.""" |
| 1240 | obj = Command(command) |
| 1241 | if command == 'help': |
| 1242 | command = '<command>' |
| 1243 | # OptParser.description prefer nicely non-formatted strings. |
| 1244 | parser.description = re.sub('[\r\n ]{2,}', ' ', obj.__doc__) |
| 1245 | usage = getattr(obj, 'usage', '') |
| 1246 | parser.set_usage('%%prog %s [options] %s' % (command, usage)) |
| 1247 | parser.epilog = getattr(obj, 'epilog', None) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1248 | |
| 1249 | |
| 1250 | def Main(argv): |
[email protected] | 5ca2769 | 2010-05-26 19:32:41 | [diff] [blame] | 1251 | """Doesn't parse the arguments here, just find the right subcommand to |
| 1252 | execute.""" |
[email protected] | 6e29d57 | 2010-06-04 17:32:20 | [diff] [blame] | 1253 | try: |
| 1254 | # Do it late so all commands are listed. |
| 1255 | CMDhelp.usage = ('\n\nCommands are:\n' + '\n'.join([ |
| 1256 | ' %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip()) |
| 1257 | for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')])) |
| 1258 | parser = optparse.OptionParser(version='%prog ' + __version__) |
[email protected] | f0fc991 | 2010-06-11 17:57:33 | [diff] [blame] | 1259 | parser.add_option('-v', '--verbose', action='count', default=0, |
| 1260 | help='Produces additional output for diagnostics. Can be ' |
| 1261 | 'used up to three times for more logging info.') |
| 1262 | parser.add_option('--gclientfile', dest='config_filename', |
| 1263 | default=os.environ.get('GCLIENT_FILE', '.gclient'), |
| 1264 | help='Specify an alternate %default file') |
[email protected] | 6e29d57 | 2010-06-04 17:32:20 | [diff] [blame] | 1265 | # Integrate standard options processing. |
| 1266 | old_parser = parser.parse_args |
| 1267 | def Parse(args): |
| 1268 | (options, args) = old_parser(args) |
[email protected] | f0fc991 | 2010-06-11 17:57:33 | [diff] [blame] | 1269 | level = None |
[email protected] | 6e29d57 | 2010-06-04 17:32:20 | [diff] [blame] | 1270 | if options.verbose == 2: |
[email protected] | f0fc991 | 2010-06-11 17:57:33 | [diff] [blame] | 1271 | level = logging.INFO |
[email protected] | 6e29d57 | 2010-06-04 17:32:20 | [diff] [blame] | 1272 | elif options.verbose > 2: |
[email protected] | f0fc991 | 2010-06-11 17:57:33 | [diff] [blame] | 1273 | level = logging.DEBUG |
| 1274 | logging.basicConfig(level=level, |
| 1275 | format='%(module)s(%(lineno)d) %(funcName)s:%(message)s') |
| 1276 | options.entries_filename = options.config_filename + '_entries' |
[email protected] | e3216c6 | 2010-07-08 03:31:43 | [diff] [blame] | 1277 | |
| 1278 | # These hacks need to die. |
[email protected] | 6e29d57 | 2010-06-04 17:32:20 | [diff] [blame] | 1279 | if not hasattr(options, 'revisions'): |
| 1280 | # GClient.RunOnDeps expects it even if not applicable. |
| 1281 | options.revisions = [] |
| 1282 | if not hasattr(options, 'head'): |
| 1283 | options.head = None |
[email protected] | f0fc991 | 2010-06-11 17:57:33 | [diff] [blame] | 1284 | if not hasattr(options, 'nohooks'): |
| 1285 | options.nohooks = True |
| 1286 | if not hasattr(options, 'deps_os'): |
| 1287 | options.deps_os = None |
[email protected] | e3216c6 | 2010-07-08 03:31:43 | [diff] [blame] | 1288 | if not hasattr(options, 'manually_grab_svn_rev'): |
| 1289 | options.manually_grab_svn_rev = None |
| 1290 | if not hasattr(options, 'force'): |
| 1291 | options.force = None |
[email protected] | 6e29d57 | 2010-06-04 17:32:20 | [diff] [blame] | 1292 | return (options, args) |
| 1293 | parser.parse_args = Parse |
| 1294 | # We don't want wordwrapping in epilog (usually examples) |
| 1295 | parser.format_epilog = lambda _: parser.epilog or '' |
| 1296 | if argv: |
| 1297 | command = Command(argv[0]) |
| 1298 | if command: |
[email protected] | f0fc991 | 2010-06-11 17:57:33 | [diff] [blame] | 1299 | # 'fix' the usage and the description now that we know the subcommand. |
[email protected] | 6e29d57 | 2010-06-04 17:32:20 | [diff] [blame] | 1300 | GenUsage(parser, argv[0]) |
| 1301 | return command(parser, argv[1:]) |
| 1302 | # Not a known command. Default to help. |
| 1303 | GenUsage(parser, 'help') |
| 1304 | return CMDhelp(parser, argv) |
| 1305 | except gclient_utils.Error, e: |
[email protected] | f0fc991 | 2010-06-11 17:57:33 | [diff] [blame] | 1306 | print >> sys.stderr, 'Error: %s' % str(e) |
[email protected] | 6e29d57 | 2010-06-04 17:32:20 | [diff] [blame] | 1307 | return 1 |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1308 | |
| 1309 | |
[email protected] | f0fc991 | 2010-06-11 17:57:33 | [diff] [blame] | 1310 | if '__main__' == __name__: |
[email protected] | 6e29d57 | 2010-06-04 17:32:20 | [diff] [blame] | 1311 | sys.exit(Main(sys.argv[1:])) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1312 | |
| 1313 | # vim: ts=2:sw=2:tw=80:et: |