| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Meta checkout manager supporting both Subversion and GIT. | 6 """Meta checkout manager supporting both Subversion and GIT. |
| 7 | 7 |
| 8 Files | 8 Files |
| 9 .gclient : Current client configuration, written by 'config' command. | 9 .gclient : Current client configuration, written by 'config' command. |
| 10 Format is a Python script defining 'solutions', a list whose | 10 Format is a Python script defining 'solutions', a list whose |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 # Eval the content. | 197 # Eval the content. |
| 198 # One thing is unintuitive, vars= {} must happen before Var() use. | 198 # One thing is unintuitive, vars= {} must happen before Var() use. |
| 199 local_scope = {} | 199 local_scope = {} |
| 200 var = self.VarImpl(self.custom_vars, local_scope) | 200 var = self.VarImpl(self.custom_vars, local_scope) |
| 201 global_scope = { | 201 global_scope = { |
| 202 'File': self.FileImpl, | 202 'File': self.FileImpl, |
| 203 'From': self.FromImpl, | 203 'From': self.FromImpl, |
| 204 'Var': var.Lookup, | 204 'Var': var.Lookup, |
| 205 'deps_os': {}, | 205 'deps_os': {}, |
| 206 } | 206 } |
| 207 exec(deps_content, global_scope, local_scope) | 207 try: |
| 208 exec(deps_content, global_scope, local_scope) |
| 209 except SyntaxError, e: |
| 210 gclient_utils.SyntaxErrorToError(filepath, e) |
| 208 deps = local_scope.get('deps', {}) | 211 deps = local_scope.get('deps', {}) |
| 209 # load os specific dependencies if defined. these dependencies may | 212 # load os specific dependencies if defined. these dependencies may |
| 210 # override or extend the values defined by the 'deps' member. | 213 # override or extend the values defined by the 'deps' member. |
| 211 if 'deps_os' in local_scope: | 214 if 'deps_os' in local_scope: |
| 212 for deps_os_key in self.enforced_os(): | 215 for deps_os_key in self.enforced_os(): |
| 213 os_deps = local_scope['deps_os'].get(deps_os_key, {}) | 216 os_deps = local_scope['deps_os'].get(deps_os_key, {}) |
| 214 if len(self.enforced_os()) > 1: | 217 if len(self.enforced_os()) > 1: |
| 215 # Ignore any conflict when including deps for more than one | 218 # Ignore any conflict when including deps for more than one |
| 216 # platform, so we collect the broadest set of dependencies available. | 219 # platform, so we collect the broadest set of dependencies available. |
| 217 # We may end up with the wrong revision of something for our | 220 # We may end up with the wrong revision of something for our |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 # are processed. | 460 # are processed. |
| 458 self._recursion_limit = 2 | 461 self._recursion_limit = 2 |
| 459 | 462 |
| 460 def SetConfig(self, content): | 463 def SetConfig(self, content): |
| 461 assert self.dependencies == [] | 464 assert self.dependencies == [] |
| 462 config_dict = {} | 465 config_dict = {} |
| 463 self.config_content = content | 466 self.config_content = content |
| 464 try: | 467 try: |
| 465 exec(content, config_dict) | 468 exec(content, config_dict) |
| 466 except SyntaxError, e: | 469 except SyntaxError, e: |
| 467 try: | 470 gclient_utils.SyntaxErrorToError('.gclient', e) |
| 468 # Try to construct a human readable error message | |
| 469 error_message = [ | |
| 470 'There is a syntax error in your configuration file.', | |
| 471 'Line #%s, character %s:' % (e.lineno, e.offset), | |
| 472 '"%s"' % re.sub(r'[\r\n]*$', '', e.text) ] | |
| 473 except: | |
| 474 # Something went wrong, re-raise the original exception | |
| 475 raise e | |
| 476 else: | |
| 477 # Raise a new exception with the human readable message: | |
| 478 raise gclient_utils.Error('\n'.join(error_message)) | |
| 479 for s in config_dict.get('solutions', []): | 471 for s in config_dict.get('solutions', []): |
| 480 try: | 472 try: |
| 481 self.dependencies.append(Dependency( | 473 self.dependencies.append(Dependency( |
| 482 self, s['name'], s['url'], | 474 self, s['name'], s['url'], |
| 483 s.get('safesync_url', None), | 475 s.get('safesync_url', None), |
| 484 s.get('custom_deps', {}), | 476 s.get('custom_deps', {}), |
| 485 s.get('custom_vars', {}))) | 477 s.get('custom_vars', {}))) |
| 486 except KeyError: | 478 except KeyError: |
| 487 raise gclient_utils.Error('Invalid .gclient file. Solution is ' | 479 raise gclient_utils.Error('Invalid .gclient file. Solution is ' |
| 488 'incomplete: %s' % s) | 480 'incomplete: %s' % s) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 """Read the .gclient_entries file for the given client. | 523 """Read the .gclient_entries file for the given client. |
| 532 | 524 |
| 533 Returns: | 525 Returns: |
| 534 A sequence of solution names, which will be empty if there is the | 526 A sequence of solution names, which will be empty if there is the |
| 535 entries file hasn't been created yet. | 527 entries file hasn't been created yet. |
| 536 """ | 528 """ |
| 537 scope = {} | 529 scope = {} |
| 538 filename = os.path.join(self.root_dir(), self._options.entries_filename) | 530 filename = os.path.join(self.root_dir(), self._options.entries_filename) |
| 539 if not os.path.exists(filename): | 531 if not os.path.exists(filename): |
| 540 return {} | 532 return {} |
| 541 exec(gclient_utils.FileRead(filename), scope) | 533 try: |
| 534 exec(gclient_utils.FileRead(filename), scope) |
| 535 except SyntaxError, e: |
| 536 gclient_utils.SyntaxErrorToError(filename, e) |
| 542 return scope['entries'] | 537 return scope['entries'] |
| 543 | 538 |
| 544 def _EnforceRevisions(self): | 539 def _EnforceRevisions(self): |
| 545 """Checks for revision overrides.""" | 540 """Checks for revision overrides.""" |
| 546 revision_overrides = {} | 541 revision_overrides = {} |
| 547 if self._options.head: | 542 if self._options.head: |
| 548 return revision_overrides | 543 return revision_overrides |
| 549 for s in self.dependencies: | 544 for s in self.dependencies: |
| 550 if not s.safesync_url: | 545 if not s.safesync_url: |
| 551 continue | 546 continue |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 return CMDhelp(parser, argv) | 1191 return CMDhelp(parser, argv) |
| 1197 except gclient_utils.Error, e: | 1192 except gclient_utils.Error, e: |
| 1198 print >> sys.stderr, 'Error: %s' % str(e) | 1193 print >> sys.stderr, 'Error: %s' % str(e) |
| 1199 return 1 | 1194 return 1 |
| 1200 | 1195 |
| 1201 | 1196 |
| 1202 if '__main__' == __name__: | 1197 if '__main__' == __name__: |
| 1203 sys.exit(Main(sys.argv[1:])) | 1198 sys.exit(Main(sys.argv[1:])) |
| 1204 | 1199 |
| 1205 # vim: ts=2:sw=2:tw=80:et: | 1200 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |