Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(602)

Side by Side Diff: deps_utils.py

Issue 9359045: Add support for non-git-svn repos. Fix syntax errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/deps2git/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « deps2git.py ('k') | svn_to_git_public.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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."""
7
8 import re
9
10 # Used by Varify() to automatically convert variable names tagged with this
11 # prefix into Var('<variable name>').
12 VARIFY_MARKER_TAG_PREFIX = 'VARIFY_MARKER_TAG_'
13
6 14
7 class VarImpl(object): 15 class VarImpl(object):
8 """Implement the Var function used within the DEPS file.""" 16 """Implement the Var function used within the DEPS file."""
17
9 def __init__(self, local_scope): 18 def __init__(self, local_scope):
10 self._local_scope = local_scope 19 self._local_scope = local_scope
11 20
12 def Lookup(self, var_name): 21 def Lookup(self, var_name):
13 """Implements the Var syntax.""" 22 """Implements the Var syntax."""
14 if var_name in self._local_scope.get('vars', {}): 23 if var_name in self._local_scope.get('vars', {}):
15 return self._local_scope['vars'][var_name] 24 return self._local_scope['vars'][var_name]
16 raise Exception('Var is not defined: %s' % var_name) 25 raise Exception('Var is not defined: %s' % var_name)
17 26
18 27
19 def GetDepsContent(deps_path): 28 def GetDepsContent(deps_path):
20 """Read a DEPS file and return all the sections.""" 29 """Read a DEPS file and return all the sections."""
21 deps_file = open(deps_path, 'rU') 30 deps_file = open(deps_path, 'rU')
22 content = deps_file.read() 31 content = deps_file.read()
23 local_scope = {} 32 local_scope = {}
24 var = VarImpl(local_scope) 33 var = VarImpl(local_scope)
25 global_scope = { 34 global_scope = {
26 'Var': var.Lookup, 35 'Var': var.Lookup,
27 'deps': {}, 36 'deps': {},
28 'deps_os': {}, 37 'deps_os': {},
29 'include_rules': [], 38 'include_rules': [],
30 'skip_child_includes': [], 39 'skip_child_includes': [],
31 'hooks': [], 40 'hooks': [],
32 } 41 }
33 exec(content, global_scope, local_scope) 42 exec(content, global_scope, local_scope)
34 local_scope.setdefault('deps', {}) 43 local_scope.setdefault('deps', {})
35 local_scope.setdefault('deps_os', {}) 44 local_scope.setdefault('deps_os', {})
36 local_scope.setdefault('include_rules', []) 45 local_scope.setdefault('include_rules', [])
37 local_scope.setdefault('skip_child_includes', []) 46 local_scope.setdefault('skip_child_includes', [])
38 local_scope.setdefault('hooks', []) 47 local_scope.setdefault('hooks', [])
48 local_scope.setdefault('vars', {})
39 49
40 return (local_scope['deps'], local_scope['deps_os'], 50 return (local_scope['deps'], local_scope['deps_os'],
41 local_scope['include_rules'], local_scope['skip_child_includes'], 51 local_scope['include_rules'], local_scope['skip_child_includes'],
42 local_scope['hooks']) 52 local_scope['hooks'], local_scope['vars'])
43 53
44 54
45 def PrettyDeps(deps, indent=0): 55 def PrettyDeps(deps, indent=0):
46 """Stringify a deps dictionary in a pretty way.""" 56 """Stringify a deps dictionary in a pretty way."""
47 pretty = ' ' * indent 57 pretty = ' ' * indent
48 pretty += '{\n' 58 pretty += '{\n'
49 59
50 indent += 4 60 indent += 4
51 61
52 for item in sorted(deps): 62 for item in sorted(deps):
(...skipping 22 matching lines...) Expand all
75 pretty = pretty.replace(', ', ',\n ') 85 pretty = pretty.replace(', ', ',\n ')
76 return pretty 86 return pretty
77 87
78 88
79 def Varify(deps): 89 def Varify(deps):
80 """Replace all instances of our git server with a git_url var.""" 90 """Replace all instances of our git server with a git_url var."""
81 deps = deps.replace('\'http://git.chromium.org/external/WebKit_trimmed.git', 91 deps = deps.replace('\'http://git.chromium.org/external/WebKit_trimmed.git',
82 'Var(\'webkit_url\')') 92 'Var(\'webkit_url\')')
83 deps = deps.replace('\'http://git.chromium.org', 'Var(\'git_url\') + \'') 93 deps = deps.replace('\'http://git.chromium.org', 'Var(\'git_url\') + \'')
84 deps = deps.replace('VAR_WEBKIT_REV\'', ' + Var(\'webkit_rev\')') 94 deps = deps.replace('VAR_WEBKIT_REV\'', ' + Var(\'webkit_rev\')')
95
96 # Try to replace all instances of form "marker_prefix_<name>'" with
97 # "' + Var('<name>')". If there are no matches, nothing is done.
98 deps = re.sub(VARIFY_MARKER_TAG_PREFIX + '_(\w+)\'',
99 lambda match: '\' + Var(\'%s\')' % match.group(1), deps)
85 return deps 100 return deps
86 101
87 102
88 def WriteDeps(deps_file_name, vars, deps, deps_os, include_rules, 103 def WriteDeps(deps_file_name, deps_vars, deps, deps_os, include_rules,
89 skip_child_includes, hooks): 104 skip_child_includes, hooks):
90 """Given all the sections in a DEPS file, write it to disk.""" 105 """Given all the sections in a DEPS file, write it to disk."""
91 new_deps = ('# DO NOT EDIT EXCEPT FOR LOCAL TESTING.\n' 106 new_deps = ('# DO NOT EDIT EXCEPT FOR LOCAL TESTING.\n'
92 '# THIS IS A GENERATED FILE.\n', 107 '# THIS IS A GENERATED FILE.\n',
93 '# ALL MANUAL CHANGES WILL BE OVERWRITTEN.\n', 108 '# ALL MANUAL CHANGES WILL BE OVERWRITTEN.\n',
94 '# SEE http://code.google.com/p/chromium/wiki/UsingNewGit\n', 109 '# SEE http://code.google.com/p/chromium/wiki/UsingNewGit\n',
95 '# FOR HOW TO ROLL DEPS\n' 110 '# FOR HOW TO ROLL DEPS\n'
96 'vars = %s\n\n' % PrettyObj(vars), 111 'vars = %s\n\n' % PrettyObj(deps_vars),
97 'deps = %s\n\n' % Varify(PrettyDeps(deps)), 112 'deps = %s\n\n' % Varify(PrettyDeps(deps)),
98 'deps_os = %s\n\n' % Varify(PrettyDeps(deps_os)), 113 'deps_os = %s\n\n' % Varify(PrettyDeps(deps_os)),
99 'include_rules = %s\n\n' % PrettyObj(include_rules), 114 'include_rules = %s\n\n' % PrettyObj(include_rules),
100 'skip_child_includes = %s\n\n' % PrettyObj(skip_child_includes), 115 'skip_child_includes = %s\n\n' % PrettyObj(skip_child_includes),
101 'hooks = %s\n' % PrettyObj(hooks)) 116 'hooks = %s\n' % PrettyObj(hooks))
102 new_deps = ''.join(new_deps) 117 new_deps = ''.join(new_deps)
103 deps_file = open(deps_file_name, 'w') 118 deps_file = open(deps_file_name, 'w')
104 deps_file.write(new_deps) 119 deps_file.write(new_deps)
OLDNEW
« no previous file with comments | « deps2git.py ('k') | svn_to_git_public.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698