| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/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 """Utilities for formatting and writing DEPS files.""" | 6 """Utilities for formatting and writing DEPS files.""" |
| 7 | 7 |
| 8 import errno | 8 import errno |
| 9 import os | 9 import os |
| 10 import re | |
| 11 import shutil | 10 import shutil |
| 12 import subprocess | 11 import subprocess |
| 13 import sys | 12 import sys |
| 14 import time | 13 import time |
| 15 | 14 |
| 16 # Used by Varify() to automatically convert variable names tagged with this | |
| 17 # prefix into Var('<variable name>'). | |
| 18 VARIFY_MARKER_TAG_PREFIX = 'VARIFY_MARKER_TAG_' | |
| 19 | |
| 20 | 15 |
| 21 class VarImpl(object): | 16 class VarImpl(object): |
| 22 """Implement the Var function used within the DEPS file.""" | 17 """Implement the Var function used within the DEPS file.""" |
| 23 | 18 |
| 24 def __init__(self, local_scope): | 19 def __init__(self, local_scope): |
| 25 self._local_scope = local_scope | 20 self._local_scope = local_scope |
| 26 | 21 |
| 27 def Lookup(self, var_name): | 22 def Lookup(self, var_name): |
| 28 """Implements the Var syntax.""" | 23 """Implements the Var syntax.""" |
| 29 if var_name in self._local_scope.get('vars', {}): | 24 if var_name in self._local_scope.get('vars', {}): |
| (...skipping 14 matching lines...) Expand all Loading... |
| 44 'include_rules': [], | 39 'include_rules': [], |
| 45 'skip_child_includes': [], | 40 'skip_child_includes': [], |
| 46 'hooks': [], | 41 'hooks': [], |
| 47 } | 42 } |
| 48 exec(content, global_scope, local_scope) | 43 exec(content, global_scope, local_scope) |
| 49 local_scope.setdefault('deps', {}) | 44 local_scope.setdefault('deps', {}) |
| 50 local_scope.setdefault('deps_os', {}) | 45 local_scope.setdefault('deps_os', {}) |
| 51 local_scope.setdefault('include_rules', []) | 46 local_scope.setdefault('include_rules', []) |
| 52 local_scope.setdefault('skip_child_includes', []) | 47 local_scope.setdefault('skip_child_includes', []) |
| 53 local_scope.setdefault('hooks', []) | 48 local_scope.setdefault('hooks', []) |
| 54 local_scope.setdefault('vars', {}) | |
| 55 | 49 |
| 56 return (local_scope['deps'], local_scope['deps_os'], | 50 return (local_scope['deps'], local_scope['deps_os'], |
| 57 local_scope['include_rules'], local_scope['skip_child_includes'], | 51 local_scope['include_rules'], local_scope['skip_child_includes'], |
| 58 local_scope['hooks'], local_scope['vars']) | 52 local_scope['hooks']) |
| 59 | 53 |
| 60 | 54 |
| 61 def PrettyDeps(deps, indent=0): | 55 def PrettyDeps(deps, indent=0): |
| 62 """Stringify a deps dictionary in a pretty way.""" | 56 """Stringify a deps dictionary in a pretty way.""" |
| 63 pretty = ' ' * indent | 57 pretty = ' ' * indent |
| 64 pretty += '{\n' | 58 pretty += '{\n' |
| 65 | 59 |
| 66 indent += 4 | 60 indent += 4 |
| 67 | 61 |
| 68 for item in sorted(deps): | 62 for item in sorted(deps): |
| (...skipping 29 matching lines...) Expand all Loading... |
| 98 def Varify(deps): | 92 def Varify(deps): |
| 99 """Replace all instances of our git server with a git_url var.""" | 93 """Replace all instances of our git server with a git_url var.""" |
| 100 deps = deps.replace( | 94 deps = deps.replace( |
| 101 '\'https://chromium.googlesource.com/chromium/blink.git', | 95 '\'https://chromium.googlesource.com/chromium/blink.git', |
| 102 'Var(\'webkit_url\')') | 96 'Var(\'webkit_url\')') |
| 103 deps = deps.replace( | 97 deps = deps.replace( |
| 104 '\'https://chromium.googlesource.com', 'Var(\'git_url\') + \'') | 98 '\'https://chromium.googlesource.com', 'Var(\'git_url\') + \'') |
| 105 deps = deps.replace( | 99 deps = deps.replace( |
| 106 '\'https://git.chromium.org', 'Var(\'git_url\') + \'') | 100 '\'https://git.chromium.org', 'Var(\'git_url\') + \'') |
| 107 deps = deps.replace('VAR_WEBKIT_REV\'', ' + Var(\'webkit_rev\')') | 101 deps = deps.replace('VAR_WEBKIT_REV\'', ' + Var(\'webkit_rev\')') |
| 108 | |
| 109 # Try to replace all instances of form "marker_prefix_<name>'" with | |
| 110 # "' + Var('<name>')". If there are no matches, nothing is done. | |
| 111 deps = re.sub(VARIFY_MARKER_TAG_PREFIX + '_(\w+)\'', | |
| 112 lambda match: '\' + Var(\'%s\')' % match.group(1), deps) | |
| 113 return deps | 102 return deps |
| 114 | 103 |
| 115 | 104 |
| 116 def WriteDeps(deps_file_name, deps_vars, deps, deps_os, include_rules, | 105 def WriteDeps(deps_file_name, deps_vars, deps, deps_os, include_rules, |
| 117 skip_child_includes, hooks): | 106 skip_child_includes, hooks): |
| 118 """Given all the sections in a DEPS file, write it to disk.""" | 107 """Given all the sections in a DEPS file, write it to disk.""" |
| 119 new_deps = ('# DO NOT EDIT EXCEPT FOR LOCAL TESTING.\n' | 108 new_deps = ('# DO NOT EDIT EXCEPT FOR LOCAL TESTING.\n' |
| 120 '# THIS IS A GENERATED FILE.\n', | 109 '# THIS IS A GENERATED FILE.\n', |
| 121 '# ALL MANUAL CHANGES WILL BE OVERWRITTEN.\n', | 110 '# ALL MANUAL CHANGES WILL BE OVERWRITTEN.\n', |
| 122 '# SEE http://code.google.com/p/chromium/wiki/UsingGit\n', | 111 '# SEE http://code.google.com/p/chromium/wiki/UsingGit\n', |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 # For POSIX: making the directory writable guarantees removability. | 203 # For POSIX: making the directory writable guarantees removability. |
| 215 # Windows will ignore the non-read-only bits in the chmod value. | 204 # Windows will ignore the non-read-only bits in the chmod value. |
| 216 os.chmod(root, 0770) | 205 os.chmod(root, 0770) |
| 217 for name in files: | 206 for name in files: |
| 218 remove_with_retry(os.remove, os.path.join(root, name)) | 207 remove_with_retry(os.remove, os.path.join(root, name)) |
| 219 for name in dirs: | 208 for name in dirs: |
| 220 remove_with_retry(lambda p: shutil.rmtree(p, onerror=RmTreeOnError), | 209 remove_with_retry(lambda p: shutil.rmtree(p, onerror=RmTreeOnError), |
| 221 os.path.join(root, name)) | 210 os.path.join(root, name)) |
| 222 | 211 |
| 223 remove_with_retry(os.rmdir, file_path) | 212 remove_with_retry(os.rmdir, file_path) |
| OLD | NEW |