Index: deps_utils.py |
=================================================================== |
--- deps_utils.py (revision 121912) |
+++ deps_utils.py (working copy) |
@@ -3,9 +3,18 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
+"""Utilities for formatting and writing DEPS files.""" |
+import re |
+ |
+# Used by Varify() to automatically convert variable names tagged with this |
+# prefix into Var('<variable name>'). |
+VARIFY_MARKER_TAG_PREFIX = 'VARIFY_MARKER_TAG_' |
+ |
+ |
class VarImpl(object): |
"""Implement the Var function used within the DEPS file.""" |
+ |
def __init__(self, local_scope): |
self._local_scope = local_scope |
@@ -23,12 +32,12 @@ |
local_scope = {} |
var = VarImpl(local_scope) |
global_scope = { |
- 'Var': var.Lookup, |
- 'deps': {}, |
- 'deps_os': {}, |
- 'include_rules': [], |
- 'skip_child_includes': [], |
- 'hooks': [], |
+ 'Var': var.Lookup, |
+ 'deps': {}, |
+ 'deps_os': {}, |
+ 'include_rules': [], |
+ 'skip_child_includes': [], |
+ 'hooks': [], |
} |
exec(content, global_scope, local_scope) |
local_scope.setdefault('deps', {}) |
@@ -36,10 +45,11 @@ |
local_scope.setdefault('include_rules', []) |
local_scope.setdefault('skip_child_includes', []) |
local_scope.setdefault('hooks', []) |
+ local_scope.setdefault('vars', {}) |
return (local_scope['deps'], local_scope['deps_os'], |
local_scope['include_rules'], local_scope['skip_child_includes'], |
- local_scope['hooks']) |
+ local_scope['hooks'], local_scope['vars']) |
def PrettyDeps(deps, indent=0): |
@@ -82,10 +92,15 @@ |
'Var(\'webkit_url\')') |
deps = deps.replace('\'http://git.chromium.org', 'Var(\'git_url\') + \'') |
deps = deps.replace('VAR_WEBKIT_REV\'', ' + Var(\'webkit_rev\')') |
+ |
+ # Try to replace all instances of form "marker_prefix_<name>'" with |
+ # "' + Var('<name>')". If there are no matches, nothing is done. |
+ deps = re.sub(VARIFY_MARKER_TAG_PREFIX + '_(\w+)\'', |
+ lambda match: '\' + Var(\'%s\')' % match.group(1), deps) |
return deps |
-def WriteDeps(deps_file_name, vars, deps, deps_os, include_rules, |
+def WriteDeps(deps_file_name, deps_vars, deps, deps_os, include_rules, |
skip_child_includes, hooks): |
"""Given all the sections in a DEPS file, write it to disk.""" |
new_deps = ('# DO NOT EDIT EXCEPT FOR LOCAL TESTING.\n' |
@@ -93,7 +108,7 @@ |
'# ALL MANUAL CHANGES WILL BE OVERWRITTEN.\n', |
'# SEE http://code.google.com/p/chromium/wiki/UsingNewGit\n', |
'# FOR HOW TO ROLL DEPS\n' |
- 'vars = %s\n\n' % PrettyObj(vars), |
+ 'vars = %s\n\n' % PrettyObj(deps_vars), |
'deps = %s\n\n' % Varify(PrettyDeps(deps)), |
'deps_os = %s\n\n' % Varify(PrettyDeps(deps_os)), |
'include_rules = %s\n\n' % PrettyObj(include_rules), |