OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 # Files | 7 # Files |
8 # .gclient : Current client configuration, written by 'config' command. | 8 # .gclient : Current client configuration, written by 'config' command. |
9 # Format is a Python script defining 'solutions', a list whose | 9 # Format is a Python script defining 'solutions', a list whose |
10 # entries each are maps binding the strings "name" and "url" | 10 # entries each are maps binding the strings "name" and "url" |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 target_os_deps[os_dep_key] = sorted(possible_values)[0] | 507 target_os_deps[os_dep_key] = sorted(possible_values)[0] |
508 | 508 |
509 new_deps = deps.copy() | 509 new_deps = deps.copy() |
510 new_deps.update(target_os_deps) | 510 new_deps.update(target_os_deps) |
511 return new_deps | 511 return new_deps |
512 | 512 |
513 def ParseDepsFile(self): | 513 def ParseDepsFile(self): |
514 """Parses the DEPS file for this dependency.""" | 514 """Parses the DEPS file for this dependency.""" |
515 assert not self.deps_parsed | 515 assert not self.deps_parsed |
516 assert not self.dependencies | 516 assert not self.dependencies |
517 # One thing is unintuitive, vars = {} must happen before Var() use. | 517 |
518 local_scope = {} | 518 deps_content = None |
519 var = self.VarImpl(self.custom_vars, local_scope) | 519 use_strict = False |
520 global_scope = { | |
521 'File': self.FileImpl, | |
522 'From': self.FromImpl, | |
523 'Var': var.Lookup, | |
524 'deps_os': {}, | |
525 } | |
526 filepath = os.path.join(self.root.root_dir, self.name, self.deps_file) | 520 filepath = os.path.join(self.root.root_dir, self.name, self.deps_file) |
527 if not os.path.isfile(filepath): | 521 if not os.path.isfile(filepath): |
528 logging.info( | 522 logging.info( |
529 'ParseDepsFile(%s): No %s file found at %s' % ( | 523 'ParseDepsFile(%s): No %s file found at %s' % ( |
530 self.name, self.deps_file, filepath)) | 524 self.name, self.deps_file, filepath)) |
531 else: | 525 else: |
532 deps_content = gclient_utils.FileRead(filepath) | 526 deps_content = gclient_utils.FileRead(filepath) |
533 logging.debug('ParseDepsFile(%s) read:\n%s' % (self.name, deps_content)) | 527 logging.debug('ParseDepsFile(%s) read:\n%s' % (self.name, deps_content)) |
| 528 use_strict = 'use strict' in deps_content.splitlines()[0] |
| 529 |
| 530 local_scope = {} |
| 531 if deps_content: |
| 532 # One thing is unintuitive, vars = {} must happen before Var() use. |
| 533 var = self.VarImpl(self.custom_vars, local_scope) |
| 534 if use_strict: |
| 535 logging.info( |
| 536 'ParseDepsFile(%s): Strict Mode Enabled', self.name) |
| 537 global_scope = { |
| 538 '__builtins__': {'None': None}, |
| 539 'Var': var.Lookup, |
| 540 'deps_os': {}, |
| 541 } |
| 542 else: |
| 543 global_scope = { |
| 544 'File': self.FileImpl, |
| 545 'From': self.FromImpl, |
| 546 'Var': var.Lookup, |
| 547 'deps_os': {}, |
| 548 } |
534 # Eval the content. | 549 # Eval the content. |
535 try: | 550 try: |
536 exec(deps_content, global_scope, local_scope) | 551 exec(deps_content, global_scope, local_scope) |
537 except SyntaxError, e: | 552 except SyntaxError, e: |
538 gclient_utils.SyntaxErrorToError(filepath, e) | 553 gclient_utils.SyntaxErrorToError(filepath, e) |
| 554 if use_strict: |
| 555 for key, val in local_scope.iteritems(): |
| 556 if not isinstance(val, (dict, list, tuple, str)): |
| 557 raise gclient_utils.Error( |
| 558 'ParseDepsFile(%s): Strict mode disallows %r -> %r' % |
| 559 (self.name, key, val)) |
| 560 |
539 deps = local_scope.get('deps', {}) | 561 deps = local_scope.get('deps', {}) |
540 if 'recursion' in local_scope: | 562 if 'recursion' in local_scope: |
541 self.recursion_override = local_scope.get('recursion') | 563 self.recursion_override = local_scope.get('recursion') |
542 logging.warning( | 564 logging.warning( |
543 'Setting %s recursion to %d.', self.name, self.recursion_limit) | 565 'Setting %s recursion to %d.', self.name, self.recursion_limit) |
544 # If present, save 'target_os' in the local_target_os property. | 566 # If present, save 'target_os' in the local_target_os property. |
545 if 'target_os' in local_scope: | 567 if 'target_os' in local_scope: |
546 self.local_target_os = local_scope['target_os'] | 568 self.local_target_os = local_scope['target_os'] |
547 # load os specific dependencies if defined. these dependencies may | 569 # load os specific dependencies if defined. these dependencies may |
548 # override or extend the values defined by the 'deps' member. | 570 # override or extend the values defined by the 'deps' member. |
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1983 print >> sys.stderr, 'Error: %s' % str(e) | 2005 print >> sys.stderr, 'Error: %s' % str(e) |
1984 return 1 | 2006 return 1 |
1985 finally: | 2007 finally: |
1986 gclient_utils.PrintWarnings() | 2008 gclient_utils.PrintWarnings() |
1987 | 2009 |
1988 | 2010 |
1989 if '__main__' == __name__: | 2011 if '__main__' == __name__: |
1990 sys.exit(Main(sys.argv[1:])) | 2012 sys.exit(Main(sys.argv[1:])) |
1991 | 2013 |
1992 # vim: ts=2:sw=2:tw=80:et: | 2014 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |